|
@@ -3,17 +3,13 @@ using FreeRedis;
|
|
|
using MessagePack;
|
|
|
using MessagePack.Resolvers;
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
-using Newtonsoft.Json;
|
|
|
using System;
|
|
|
using System.Collections.Concurrent;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Diagnostics;
|
|
|
-using System.IO;
|
|
|
using System.Linq;
|
|
|
using System.Linq.Dynamic.Core;
|
|
|
using System.Reflection;
|
|
|
-using System.Text;
|
|
|
-using System.Threading.Tasks;
|
|
|
using WCS.Core;
|
|
|
using WCS.Entity;
|
|
|
using WCS.Entity.Protocol;
|
|
@@ -22,19 +18,19 @@ namespace WCS.Service
|
|
|
{
|
|
|
public class ProtocolProxy : ProtocolProxyBase
|
|
|
{
|
|
|
- MethodInfo SetMethod;
|
|
|
+ private MethodInfo SetMethod;
|
|
|
+
|
|
|
public ProtocolProxy(string id, WCS_DATABLOCK db, ushort start, WCS_DEVICEPROTOCOL protocol) : base(id, db, start, protocol)
|
|
|
{
|
|
|
SetMethod = typeof(DbContext).GetMethod("Set", new Type[] { }).MakeGenericMethod(this.ProtocolDataType);
|
|
|
}
|
|
|
|
|
|
- static ConcurrentDictionary<Type, object[]> LastDatas = new ConcurrentDictionary<Type, object[]>();
|
|
|
+ private static ConcurrentDictionary<Type, object[]> LastDatas = new ConcurrentDictionary<Type, object[]>();
|
|
|
|
|
|
protected override WCS_PROTOCOLDATA GetLastData(DB db)
|
|
|
{
|
|
|
if (!LastDatas.ContainsKey(this.ProtocolDataType))
|
|
|
{
|
|
|
-
|
|
|
dynamic q = SetMethod.Invoke(db.Default, null);
|
|
|
try
|
|
|
{
|
|
@@ -48,7 +44,6 @@ namespace WCS.Service
|
|
|
{
|
|
|
throw;
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
dynamic datas = LastDatas[this.ProtocolDataType];
|
|
|
var list = new List<WCS_PROTOCOLDATA>();
|
|
@@ -60,7 +55,6 @@ namespace WCS.Service
|
|
|
|
|
|
if (list.Count > 1)
|
|
|
{
|
|
|
-
|
|
|
for (int i = 0; i < list.Count - 1; i++)
|
|
|
{
|
|
|
var obj = list[i];
|
|
@@ -68,15 +62,13 @@ namespace WCS.Service
|
|
|
obj.ISLAST = false;
|
|
|
}
|
|
|
db.Default.SaveChanges();
|
|
|
-
|
|
|
}
|
|
|
var res = Enumerable.LastOrDefault(list);
|
|
|
return res;
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
|
|
|
- static int total;
|
|
|
+ private static int total;
|
|
|
+
|
|
|
protected override WCS_PROTOCOLDATA SaveNewData(DB db, WCS_PROTOCOLDATA last, WCS_PROTOCOLDATA newobj, string user)
|
|
|
{
|
|
|
total++;
|
|
@@ -97,15 +89,15 @@ namespace WCS.Service
|
|
|
db.Default.Add(newobj);
|
|
|
db.Default.SaveChanges();
|
|
|
return newobj;
|
|
|
-
|
|
|
}
|
|
|
|
|
|
-
|
|
|
//static ConcurrentQueue<PackInfo> Packs = new ConcurrentQueue<PackInfo>();
|
|
|
- static Dictionary<string, Playerback> Clients = new Dictionary<string, Playerback>();
|
|
|
- static RedisClient Redis;
|
|
|
+ private static Dictionary<string, Playerback> Clients = new Dictionary<string, Playerback>();
|
|
|
+
|
|
|
+ private static RedisClient Redis;
|
|
|
public static RedisClient YGWCS150Redis;
|
|
|
public static RedisClient WMS120Redis;
|
|
|
+
|
|
|
static ProtocolProxy()
|
|
|
{
|
|
|
MessagePackSerializer.DefaultOptions = StandardResolver.Options.WithCompression(MessagePackCompression.Lz4Block);
|
|
@@ -198,9 +190,10 @@ namespace WCS.Service
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- static Dictionary<string, string> LastInfo = new Dictionary<string, string>();
|
|
|
+ private static Dictionary<string, string> LastInfo = new Dictionary<string, string>();
|
|
|
|
|
|
public static ConcurrentDictionary<string, DeviceData> AllDatas = new ConcurrentDictionary<string, DeviceData>();
|
|
|
+
|
|
|
public static void Do()
|
|
|
{
|
|
|
Console.ForegroundColor = ConsoleColor.Green;
|
|
@@ -231,30 +224,29 @@ namespace WCS.Service
|
|
|
p.SetValue(pack, coll);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
var sw = new Stopwatch();
|
|
|
sw.Start();
|
|
|
- Redis.Set(nameof(DeviceDataPack), pack);
|
|
|
YGWCS150Redis.Set(nameof(DeviceDataPack), pack);
|
|
|
+ Redis.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);
|
|
|
+ Redis.RPush("Packs", pack);
|
|
|
|
|
|
- var len = Redis.LLen("Packs");
|
|
|
var len1 = YGWCS150Redis.LLen("Packs");
|
|
|
- if (len > 150000)
|
|
|
- {
|
|
|
- Redis.LTrim("Packs", 20000, len);
|
|
|
- }
|
|
|
+ var len = Redis.LLen("Packs");
|
|
|
+
|
|
|
if (len1 > 150000)
|
|
|
{
|
|
|
YGWCS150Redis.LTrim("Packs", 20000, len);
|
|
|
}
|
|
|
-
|
|
|
+ if (len > 150000)
|
|
|
+ {
|
|
|
+ Redis.LTrim("Packs", 20000, len);
|
|
|
+ }
|
|
|
|
|
|
foreach (var data in AllDatas)
|
|
|
{
|
|
@@ -271,11 +263,9 @@ namespace WCS.Service
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
-
|
|
|
}
|
|
|
//Datas.Clear();
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
public class PackInfo
|