|
|
@@ -1,12 +1,13 @@
|
|
|
using FreeRedis;
|
|
|
-using PlcSiemens.Core.Extension;
|
|
|
using System.ComponentModel;
|
|
|
using System.Diagnostics;
|
|
|
using WCS.Core;
|
|
|
+using WCS.Entity.Protocol.DataStructure;
|
|
|
+using WCS.WorkEngineering.Worlds;
|
|
|
|
|
|
namespace WCS.WorkEngineering.Systems
|
|
|
{
|
|
|
- // [BelongTo(typeof(MainWorld))]
|
|
|
+ [BelongTo(typeof(DataCollectionWorld))]
|
|
|
[Description("数据采集系统")]
|
|
|
public class 数据采集 : SystemBase
|
|
|
{
|
|
|
@@ -33,47 +34,89 @@ namespace WCS.WorkEngineering.Systems
|
|
|
|
|
|
public override void Update(List<WorkTimes> list)
|
|
|
{
|
|
|
- //var sw = new Stopwatch();
|
|
|
- //sw.Start();
|
|
|
- //var pack = new DataPack();
|
|
|
- //pack.Frame = DateTime.Now;
|
|
|
- //var ps = pack.GetType().GetProperties();
|
|
|
- //foreach (var p in ps)
|
|
|
- //{
|
|
|
- // if (!p.PropertyType.IsArray)
|
|
|
- // continue;
|
|
|
- // var t = p.PropertyType.GetElementType();
|
|
|
- // if (t.IsGenericType)
|
|
|
- // {
|
|
|
- // var entType = t.GetGenericArguments()[0];
|
|
|
- // var protType = GetProtocolType(entType);
|
|
|
- // var arr = Device.All.Where(v => v.HasProtocol(protType))
|
|
|
- // .Select(v =>
|
|
|
- // {
|
|
|
- // try
|
|
|
- // {
|
|
|
- // var obj = Activator.CreateInstance(t);
|
|
|
- // t.GetProperty("Code").SetValue(obj, v.Code);
|
|
|
- // var value = v.Protocol(protType, World).Copy(entType);
|
|
|
- // t.GetProperty("Data").SetValue(obj, value);
|
|
|
- // return obj;
|
|
|
- // }
|
|
|
- // catch (Exception ex)
|
|
|
- // {
|
|
|
- // return null;
|
|
|
- // }
|
|
|
- // }).Where(v => v != null).ToArray();
|
|
|
+ var sw = new Stopwatch();
|
|
|
+ sw.Start();
|
|
|
+ var pack = new DeviceDataPack();
|
|
|
+ pack.Frame = DateTime.Now;
|
|
|
+ var ps = pack.GetType().GetProperties();
|
|
|
+ foreach (var p in ps)
|
|
|
+ {
|
|
|
+ if (!p.PropertyType.IsClass) continue;
|
|
|
+ var prs = p.PropertyType.GetProperties();
|
|
|
+ foreach (var pr in prs)
|
|
|
+ {
|
|
|
+ if (!pr.PropertyType.IsArray) continue;
|
|
|
+ var yt = pr.PropertyType.GetElementType();
|
|
|
+ if (yt.IsClass)
|
|
|
+ {
|
|
|
+ var pros = yt.GetProperties();
|
|
|
+ foreach (var pro in pros)
|
|
|
+ {
|
|
|
+ if (pro.PropertyType == typeof(DateTime)) continue;
|
|
|
+ }
|
|
|
|
|
|
- // var m = typeof(Enumerable).GetMethod("OfType", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);
|
|
|
- // m = m.MakeGenericMethod(t);
|
|
|
- // var arr2 = m.Invoke(null, new object[] { arr });
|
|
|
+ var entType = yt.GetGenericArguments()[0];
|
|
|
+ var protType = GetProtocolType(entType);
|
|
|
+ var arr = Device.All.Where(v => v.HasProtocol(protType))
|
|
|
+ .Select(v =>
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ var obj = Activator.CreateInstance(yt);
|
|
|
+ yt.GetProperty("Code").SetValue(obj, v.Code);
|
|
|
+ //var value = v.Protocol(protType, World).Copy(entType);
|
|
|
+ //t.GetProperty("Data").SetValue(obj, value);
|
|
|
+ return obj;
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }).Where(v => v != null).ToArray();
|
|
|
|
|
|
- // m = typeof(Enumerable).GetMethod("ToArray", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);
|
|
|
- // m = m.MakeGenericMethod(t);
|
|
|
- // var arr3 = m.Invoke(null, new object[] { arr2 });
|
|
|
- // p.SetValue(pack, arr3);
|
|
|
- // }
|
|
|
- //}
|
|
|
+ var m = typeof(Enumerable).GetMethod("OfType", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);
|
|
|
+ m = m.MakeGenericMethod(yt);
|
|
|
+ var arr2 = m.Invoke(null, new object[] { arr });
|
|
|
+
|
|
|
+ m = typeof(Enumerable).GetMethod("ToArray", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);
|
|
|
+ m = m.MakeGenericMethod(yt);
|
|
|
+ var arr3 = m.Invoke(null, new object[] { arr2 });
|
|
|
+ p.SetValue(pack, arr3);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ var t = p.PropertyType.GetElementType();
|
|
|
+ if (t.IsGenericType)
|
|
|
+ {
|
|
|
+ var entType = t.GetGenericArguments()[0];
|
|
|
+ var protType = GetProtocolType(entType);
|
|
|
+ var arr = Device.All.Where(v => v.HasProtocol(protType))
|
|
|
+ .Select(v =>
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ var obj = Activator.CreateInstance(t);
|
|
|
+ t.GetProperty("Code").SetValue(obj, v.Code);
|
|
|
+ //var value = v.Protocol(protType, World).Copy(entType);
|
|
|
+ //t.GetProperty("Data").SetValue(obj, value);
|
|
|
+ return obj;
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }).Where(v => v != null).ToArray();
|
|
|
+
|
|
|
+ var m = typeof(Enumerable).GetMethod("OfType", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);
|
|
|
+ m = m.MakeGenericMethod(t);
|
|
|
+ var arr2 = m.Invoke(null, new object[] { arr });
|
|
|
+
|
|
|
+ m = typeof(Enumerable).GetMethod("ToArray", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);
|
|
|
+ m = m.MakeGenericMethod(t);
|
|
|
+ var arr3 = m.Invoke(null, new object[] { arr2 });
|
|
|
+ p.SetValue(pack, arr3);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
//Redis.RPush("Packs", pack);
|
|
|
//if (Redis.LLen("Packs") > 50000)
|