林豪 左 2 năm trước cách đây
mục cha
commit
9375502ec2
1 tập tin đã thay đổi với 8 bổ sung64 xóa
  1. 8 64
      Projects/永冠OPP/WCS.Service/ProtocolProxy.cs

+ 8 - 64
Projects/永冠OPP/WCS.Service/ProtocolProxy.cs

@@ -2,7 +2,6 @@
 using FreeRedis;
 using MessagePack;
 using MessagePack.Resolvers;
-using Microsoft.CodeAnalysis.Differencing;
 using Microsoft.EntityFrameworkCore;
 using System;
 using System.Collections.Concurrent;
@@ -11,7 +10,6 @@ using System.Diagnostics;
 using System.Linq;
 using System.Linq.Dynamic.Core;
 using System.Reflection;
-using System.Threading.Tasks;
 using WCS.Core;
 using WCS.Entity;
 using WCS.Entity.Protocol;
@@ -60,10 +58,10 @@ namespace WCS.Service
                 for (int i = 0; i < list.Count - 1; i++)
                 {
                     var obj = list[i];
-                    db.Default.Attach(obj);
+                    //db.Default.Attach(obj);
                     obj.ISLAST = false;
                 }
-                db.Default.SaveChanges();
+                //db.Default.SaveChanges();
             }
             var res = Enumerable.LastOrDefault(list);
             return res;
@@ -77,62 +75,35 @@ namespace WCS.Service
 
             if (last != null)
             {
-                db.Default.Attach(last);
+                //db.Default.Attach(last);
                 last.ISLAST = false;
             }
 
-            db.Default.Attach(PROTOCOL.DEVICE);
+            //db.Default.Attach(PROTOCOL.DEVICE);
 
             newobj.DEVICE = PROTOCOL.DEVICE;
             newobj.ISLAST = true;
             newobj.UPDATETIME = DateTime.Now;
             newobj.UPDATEUSER = user;
             newobj.FRAME = LogicHandler.Frame;
-            db.Default.Add(newobj);
-            db.Default.SaveChanges();
+            //db.Default.Add(newobj);
+            //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
@@ -193,15 +164,6 @@ 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)
@@ -216,29 +178,12 @@ 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;
@@ -255,7 +200,6 @@ namespace WCS.Service
             catch (Exception ex)
             {
             }
-            //Datas.Clear();
         }
     }
 
@@ -265,4 +209,4 @@ namespace WCS.Service
 
         public byte[] Data { get; set; }
     }
-}
+}