|
@@ -19,20 +19,20 @@ namespace WCS.Service
|
|
|
{
|
|
|
public class ProtocolProxy : ProtocolProxyBase
|
|
|
{
|
|
|
- private MethodInfo SetMethod;
|
|
|
+ private readonly 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);
|
|
|
+ _setMethod = typeof(DbContext).GetMethod("Set", new Type[] { })?.MakeGenericMethod(this.ProtocolDataType);
|
|
|
}
|
|
|
|
|
|
- private static ConcurrentDictionary<Type, object[]> LastDatas = new ConcurrentDictionary<Type, object[]>();
|
|
|
+ private static readonly 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);
|
|
|
+ dynamic q = _setMethod.Invoke(db.Default, null);
|
|
|
q = DynamicQueryableExtensions.Where(q, "ISLAST==@0", true);
|
|
|
q = DynamicQueryableExtensions.OrderBy(q, "ID");
|
|
|
q = DynamicQueryableExtensions.Select(q, "new(it.DEVICE.CODE as Code,it as Data)");
|
|
@@ -56,15 +56,15 @@ namespace WCS.Service
|
|
|
obj.ISLAST = false;
|
|
|
}
|
|
|
}
|
|
|
- var res = Enumerable.LastOrDefault(list);
|
|
|
+ var res = list.LastOrDefault();
|
|
|
return res;
|
|
|
}
|
|
|
|
|
|
- private static int total;
|
|
|
+ private static int _total;
|
|
|
|
|
|
protected override WCS_PROTOCOLDATA SaveNewData(Db db, WCS_PROTOCOLDATA last, WCS_PROTOCOLDATA newobj, string user)
|
|
|
{
|
|
|
- total++;
|
|
|
+ _total++;
|
|
|
|
|
|
if (last != null)
|
|
|
{
|
|
@@ -84,12 +84,12 @@ namespace WCS.Service
|
|
|
}
|
|
|
|
|
|
//static ConcurrentQueue<PackInfo> Packs = new ConcurrentQueue<PackInfo>();
|
|
|
- private static Dictionary<string, Playerback> Clients = new Dictionary<string, Playerback>();
|
|
|
+ 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;
|
|
|
+ private static readonly RedisClient Redis;
|
|
|
+ public static RedisClient Yg150Redis;
|
|
|
+ public static RedisClient Ygwms150Redis;
|
|
|
+ public static RedisClient Ygwcs150Redis;
|
|
|
|
|
|
static ProtocolProxy()
|
|
|
{
|
|
@@ -107,15 +107,15 @@ namespace WCS.Service
|
|
|
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 =>
|
|
|
+ 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) =>
|
|
|
+ Ygwcs150Redis.DeserializeRaw = (bytes, type) =>
|
|
|
{
|
|
|
var obj = MessagePackSerializer.Deserialize(type, bytes);
|
|
|
return obj;
|
|
@@ -127,30 +127,30 @@ namespace WCS.Service
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
- var Datas = AllDatas;
|
|
|
+ var datas = AllDatas;
|
|
|
if (code.StartsWith("SRM"))
|
|
|
{
|
|
|
- if (!Datas.ContainsKey(code))
|
|
|
- Datas[code] = new SCData { Code = code };
|
|
|
+ if (!datas.ContainsKey(code))
|
|
|
+ datas[code] = new SCData { Code = code };
|
|
|
}
|
|
|
else if (code.StartsWith("RGV"))
|
|
|
{
|
|
|
- if (!Datas.ContainsKey(code))
|
|
|
- Datas[code] = new RGVData { Code = code };
|
|
|
+ if (!datas.ContainsKey(code))
|
|
|
+ datas[code] = new RGVData { Code = code };
|
|
|
}
|
|
|
else if (code == "Robot")
|
|
|
{
|
|
|
- if (!Datas.ContainsKey(code))
|
|
|
- Datas[code] = new RobotData { Code = code };
|
|
|
+ if (!datas.ContainsKey(code))
|
|
|
+ datas[code] = new RobotData { Code = code };
|
|
|
}
|
|
|
else if (code.Length == 4)
|
|
|
{
|
|
|
- if (!Datas.ContainsKey(code))
|
|
|
- Datas[code] = new StationData { Code = code };
|
|
|
+ if (!datas.ContainsKey(code))
|
|
|
+ datas[code] = new StationData { Code = code };
|
|
|
}
|
|
|
|
|
|
- if (!Datas.ContainsKey(code)) return;
|
|
|
- var data = Datas[code];
|
|
|
+ if (!datas.ContainsKey(code)) return;
|
|
|
+ var data = datas[code];
|
|
|
data.Frame = LogicHandler.Frame;
|
|
|
var p = data.GetType().GetProperties().FirstOrDefault(v => v.PropertyType == obj.GetType());
|
|
|
if (p == null)
|
|
@@ -168,16 +168,16 @@ namespace WCS.Service
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private 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;
|
|
|
- Console.WriteLine($"更改:{total}");
|
|
|
+ Console.WriteLine($"更改:{_total}");
|
|
|
Console.ResetColor();
|
|
|
- total = 0;
|
|
|
+ _total = 0;
|
|
|
try
|
|
|
{
|
|
|
var gs = AllDatas.GroupBy(v => v.Value.GetType());
|
|
@@ -190,8 +190,10 @@ namespace WCS.Service
|
|
|
// var coll = Activator.CreateInstance(type, LogicHandler.Frame, value);
|
|
|
// Redis.Set(etype.Name, coll);
|
|
|
//});
|
|
|
- DeviceDataPack pack = new DeviceDataPack();
|
|
|
- pack.Frame = LogicHandler.Frame;
|
|
|
+ var pack = new DeviceDataPack
|
|
|
+ {
|
|
|
+ Frame = LogicHandler.Frame
|
|
|
+ };
|
|
|
foreach (var g in gs)
|
|
|
{
|
|
|
var value = g.Select(v => v.Value).ToArray();
|
|
@@ -205,20 +207,20 @@ namespace WCS.Service
|
|
|
var sw = new Stopwatch();
|
|
|
sw.Start();
|
|
|
Redis.Set(nameof(DeviceDataPack), pack);
|
|
|
- YGWCS150Redis.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);
|
|
|
+ Ygwcs150Redis.RPush("Packs", pack);
|
|
|
|
|
|
var len = Redis.LLen("Packs");
|
|
|
if (len > 150000)
|
|
|
{
|
|
|
Redis.LTrim("Packs", 20000, len);
|
|
|
- YGWCS150Redis.LTrim("Packs", 20000, len);
|
|
|
+ Ygwcs150Redis.LTrim("Packs", 20000, len);
|
|
|
}
|
|
|
|
|
|
foreach (var data in AllDatas)
|
|
@@ -231,10 +233,9 @@ namespace WCS.Service
|
|
|
pld.Code = data.Key;
|
|
|
}
|
|
|
}
|
|
|
- catch (Exception ex)
|
|
|
+ catch (Exception)
|
|
|
{
|
|
|
}
|
|
|
- //Datas.Clear();
|
|
|
}
|
|
|
}
|
|
|
|