Просмотр исходного кода

Revert "fix"

This reverts commit 390172677e1db937d6aafdeb5c74eb2b547da042.
Administrator 2 лет назад
Родитель
Сommit
11ccb33165

+ 57 - 3
Projects/永冠OPP/WCS.Service/ProtocolProxy.cs

@@ -63,7 +63,7 @@ namespace WCS.Service
                     db.Default.Attach(obj);
                     obj.ISLAST = false;
                 }
-                db.Default.SaveChangesAsync();
+                db.Default.SaveChanges();
             }
             var res = Enumerable.LastOrDefault(list);
             return res;
@@ -89,23 +89,50 @@ namespace WCS.Service
             newobj.UPDATEUSER = user;
             newobj.FRAME = LogicHandler.Frame;
             db.Default.Add(newobj);
-            db.Default.SaveChangesAsync();
+            db.Default.SaveChanges();
             return newobj;
         }
 
+        //static ConcurrentQueue<PackInfo> Packs = new ConcurrentQueue<PackInfo>();
         private static Dictionary<string, Playerback> Clients = new Dictionary<string, Playerback>();
 
+        //private static RedisClient Redis;
         public static RedisClient YG150Redis;
         public static RedisClient YGWMS150Redis;
+        //public static RedisClient YGWCS150Redis;
 
         static ProtocolProxy()
         {
             MessagePackSerializer.DefaultOptions = StandardResolver.Options.WithCompression(MessagePackCompression.Lz4Block);
+            //Redis = new RedisClient("192.168.249.120,password=123456,database=11");
+            //Redis = new RedisClient("212.64.66.35,database=10");
+            //Redis.Serialize = obj =>
+            //{
+            //    var bytes = MessagePackSerializer.Serialize(obj);
+            //    return bytes;
+            //};
+            //Redis.DeserializeRaw = (bytes, type) =>
+            //{
+            //    var obj = MessagePackSerializer.Deserialize(type, bytes);
+            //    return obj;
+            //};
 
             YG150Redis = new RedisClient("192.168.249.150,password=123456,database=1");
             YGWMS150Redis = new RedisClient("192.168.249.150,password=123456,database=0");
+            //YGWCS150Redis = new RedisClient("192.168.249.150,password=123456,database=10");
+            //YGWCS150Redis.Serialize = obj =>
+            //{
+            //    var bytes = MessagePackSerializer.Serialize(obj);
+            //    return bytes;
+            //};
+            //YGWCS150Redis.DeserializeRaw = (bytes, type) =>
+            //{
+            //    var obj = MessagePackSerializer.Deserialize(type, bytes);
+            //    return obj;
+            //};
         }
 
+        //static ConcurrentDictionary<string, DeviceData> Datas = new ConcurrentDictionary<string, DeviceData>();
         public override void Publish(string code, WCS_PROTOCOLDATA obj)
         {
             try
@@ -166,6 +193,15 @@ namespace WCS.Service
             {
                 var gs = AllDatas.GroupBy(v => v.Value.GetType());
 
+                //Parallel.ForEach(gs, g =>
+                //{
+                //    var value = g.Select(v => v.Value).ToArray();
+                //    var etype = g.Key;
+                //    var type = typeof(DeviceDataCollection<>).MakeGenericType(etype);
+                //    var coll = Activator.CreateInstance(type, LogicHandler.Frame, value);
+                //    Redis.Set(etype.Name, coll);
+                //    YGWCS150Redis.Set(etype.Name, coll);
+                //});
                 DeviceDataPack pack = new DeviceDataPack();
                 pack.Frame = LogicHandler.Frame;
                 foreach (var g in gs)
@@ -180,12 +216,29 @@ namespace WCS.Service
 
                 var sw = new Stopwatch();
                 sw.Start();
-         
+                //Redis.Set(nameof(DeviceDataPack), pack);
+                //YGWCS150Redis.Set(nameof(DeviceDataPack), pack);
                 sw.Stop();
                 Console.ForegroundColor = ConsoleColor.Blue;
                 Console.WriteLine($"Redis耗时{sw.ElapsedMilliseconds}");
                 Console.ResetColor();
 
+                //Redis.RPush("Packs", pack);
+                //YGWCS150Redis.RPush("Packs", pack);
+
+                //var len = Redis.LLen("Packs");
+                //if (len > 150000)
+                //{
+                //    Redis.LTrim("Packs", 20000, len);
+                //}
+
+
+                //var len1 = YGWCS150Redis.LLen("Packs");
+                //if (len1 > 150000)
+                //{
+                //    YGWCS150Redis.LTrim("Packs", 20000, len1);
+                //}
+
                 foreach (var data in AllDatas)
                 {
                     LastInfo[data.Key] = data.Value.Info;
@@ -202,6 +255,7 @@ namespace WCS.Service
             catch (Exception ex)
             {
             }
+            //Datas.Clear();
         }
     }
 

+ 9 - 0
WCS.Core/DataTrans/DataBlock.cs

@@ -155,11 +155,20 @@ namespace WCS.Core
                 var revers = Entity.PLC.TYPE == PLCType.西门子;
 
                 return ReadPrimitive(type, ref bitStart, revers);
+
+                //var revers = Entity.PLC.TYPE == PLCType.西门子;
+
+                //return ReadPrimitive(type, ref bitStart, false);
             }
             else
             {
                 if (type.IsValueType)
                 {
+                    //ushort size = (ushort)Marshal.SizeOf(type);
+                    //var s = bitStart;
+                    //var bytes = ReadBytes(ref s, size).Reverse().ToArray();
+                    //var o = ByteToStruct(type, bytes);
+
                     var res = Activator.CreateInstance(type);
                     foreach (var p in type.GetProperties())
                     {

+ 51 - 0
WCS.Core/LogicHandler.cs

@@ -107,6 +107,41 @@ namespace WCS.Core
                 Console.ResetColor();
                 last = DateTime.Now;
 
+                //Configs.DoCmds(cmd =>
+                //{
+                //    try
+                //    {
+                //        if (!cmd.ENABLED)
+                //            return;
+
+                //        var obj = Device.Find(cmd.DEVICE_CODE).PROTOCOLS.Where(v => v.DB.PROTOCOL == cmd.PROTOCOL).FirstOrDefault();
+                //        //var obj = AllObjects.OfType<WCS_DEVICEPROTOCOL>().Where(v => v.DB.PROTOCOL == cmd.PROTOCOL && v.DEVICE.CODE == cmd.DEVICE_CODE).FirstOrDefault();
+                //        if (obj != null)
+                //        {
+                //            var proxy = obj.Data() as ProtocolProxyBase;
+                //            if (proxy.WCSVersion != cmd.WCSVERSION && cmd.WCSVERSION >= 0)
+                //            {
+                //                throw new Exception("WCS数据已变更,无法执行CMD。ID:" + cmd.ID);
+                //            }
+                //            var prop = proxy.GetType().GetProperty(cmd.PROPERTY);
+                //            if (prop.PropertyType.IsEnum)
+                //            {
+                //                var value = Enum.Parse(prop.PropertyType, cmd.VALUE);
+                //                proxy.Update(cmd.PROPERTY, value, cmd.UPDATEUSER);
+                //            }
+                //            else
+                //            {
+                //                var value = Convert.ChangeType(cmd.VALUE, prop.PropertyType);
+                //                proxy.Update(cmd.PROPERTY, value, cmd.UPDATEUSER);
+                //            }
+                //        }
+                //    }
+                //    catch (Exception ex)
+                //    {
+                //        Console.WriteLine(ex.Message);
+                //    }
+                //});
+
                 Parallel.ForEach<LogicHandler>(Handlers, m =>
                 {
                     var dm = DateTime.Now;
@@ -116,10 +151,26 @@ namespace WCS.Core
                     }
                     catch (Exception ex)
                     {
+                        //Console.WriteLine(ex.GetBaseException().Message);
                     }
                     var dm2 = (DateTime.Now - dm).TotalMilliseconds;
+                    //Console.WriteLine(m.GetType().Name + ":" + dm2);
                 });
 
+                //foreach (var m in Handlers)
+                //{
+                //    var dm = DateTime.Now;
+                //    try
+                //    {
+                //        m.Update(total);
+                //    }
+                //    catch (Exception ex)
+                //    {
+                //        //Console.WriteLine(ex.GetBaseException().Message);
+                //    }
+                //    var dm2 = (DateTime.Now - dm).TotalMilliseconds;
+                //}
+
                 Configs.Publish();
                 logicTimes = (int)(DateTime.Now - last).TotalMilliseconds;
             }