|
|
@@ -155,75 +155,81 @@ namespace YSAI.Core.subscription
|
|
|
lock (basics.Address) //锁住不让其他操作
|
|
|
{
|
|
|
//执行委托
|
|
|
- OperateResult values = basics.Function?.Invoke(basics.Address);
|
|
|
-
|
|
|
- //完成后的数据复制
|
|
|
- OperateResult value = values;
|
|
|
- //判断数据类型
|
|
|
- switch (value.RType)
|
|
|
+ OperateResult value = basics.Function?.Invoke(basics.Address);
|
|
|
+ //状态判断
|
|
|
+ if (value.State)
|
|
|
{
|
|
|
- case @enum.ResultType.KeyValue:
|
|
|
- ConcurrentDictionary<string, AddressValue>? RData = value.RData as ConcurrentDictionary<string, AddressValue>;
|
|
|
- //做流程处理
|
|
|
- if (basics.DataChangeOut)
|
|
|
- {
|
|
|
+ //判断数据类型
|
|
|
+ switch (value.RType)
|
|
|
+ {
|
|
|
+ case @enum.ResultType.KeyValue:
|
|
|
+ ConcurrentDictionary<string, AddressValue>? RData = value.RData as ConcurrentDictionary<string, AddressValue>;
|
|
|
+ //做流程处理
|
|
|
+ if (basics.DataChangeOut)
|
|
|
+ {
|
|
|
+ //实例化对象
|
|
|
+ if (UpParam == null)
|
|
|
+ {
|
|
|
+ UpParam = new ConcurrentDictionary<string, AddressValue>();
|
|
|
+ }
|
|
|
+ //空数据不做处理
|
|
|
+ if (RData != null && RData.Count > 0)
|
|
|
+ {
|
|
|
+ //获取到第一次数据,准备节点检测数据是否变化
|
|
|
+ if (!ConcurrentDictionaryEquals(UpParam, RData))
|
|
|
+ {
|
|
|
+ //当节点数据变化,有一项数据未变化,也把这未变项与变化项一同抛出,在特殊用途中,确保此批点位数据都存在
|
|
|
+ if (basics.SameDataOut)
|
|
|
+ {
|
|
|
+ //抛出差异数据
|
|
|
+ OnEventHandler?.Invoke(this, new SubscribeData.EventParam() { Message = "存在变化数据", Params = RData, State = true });
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //如果不一致,就找寻里面不一样的 键、值
|
|
|
+ ConcurrentDictionary<string, AddressValue> data = new ConcurrentDictionary<string, AddressValue>(RData.Except(UpParam).ToDictionary(x => x.Key, x => x.Value));
|
|
|
+ //抛出差异数据
|
|
|
+ OnEventHandler?.Invoke(this, new SubscribeData.EventParam() { Message = "变化数据", Params = data, State = true });
|
|
|
+ }
|
|
|
+ //把这次新数据 赋值到历史数据中
|
|
|
+ UpParam = RData;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ OnEventHandler?.Invoke(this, new SubscribeData.EventParam() { Message = "实时数据", Params = RData, State = true });
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case @enum.ResultType.KeyValueArray:
|
|
|
+ List<ConcurrentDictionary<string, AddressValue>>? RDataArray = value.RData as List<ConcurrentDictionary<string, AddressValue>>;
|
|
|
//实例化对象
|
|
|
- if (UpParam == null)
|
|
|
+ if (UpParamArray == null)
|
|
|
{
|
|
|
- UpParam = new ConcurrentDictionary<string, AddressValue>();
|
|
|
+ UpParamArray = new List<ConcurrentDictionary<string, AddressValue>>();
|
|
|
}
|
|
|
//空数据不做处理
|
|
|
- if (RData != null && RData.Count > 0)
|
|
|
+ if (RDataArray != null && RDataArray.Count > 0)
|
|
|
{
|
|
|
//获取到第一次数据,准备节点检测数据是否变化
|
|
|
- if (!ConcurrentDictionaryEquals(UpParam, RData))
|
|
|
+ if (!ConcurrentDictionaryEquals(UpParamArray, RDataArray))
|
|
|
{
|
|
|
- //当节点数据变化,有一项数据未变化,也把这未变项与变化项一同抛出,在特殊用途中,确保此批点位数据都存在
|
|
|
- if (basics.SameDataOut)
|
|
|
+ foreach (var item in RDataArray)
|
|
|
{
|
|
|
//抛出差异数据
|
|
|
- OnEventHandler?.Invoke(this, new SubscribeData.EventParam() { Message = "存在变化数据", Params = RData, State = true });
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- //如果不一致,就找寻里面不一样的 键、值
|
|
|
- ConcurrentDictionary<string, AddressValue> data = new ConcurrentDictionary<string, AddressValue>(RData.Except(UpParam).ToDictionary(x => x.Key, x => x.Value));
|
|
|
- //抛出差异数据
|
|
|
- OnEventHandler?.Invoke(this, new SubscribeData.EventParam() { Message = "变化数据", Params = data, State = true });
|
|
|
+ OnEventHandler?.Invoke(this, new SubscribeData.EventParam() { Message = "存在变化数据", Params = item, State = true });
|
|
|
}
|
|
|
//把这次新数据 赋值到历史数据中
|
|
|
- UpParam = RData;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- OnEventHandler?.Invoke(this, new SubscribeData.EventParam() { Message = "实时数据", Params = RData, State = true });
|
|
|
- }
|
|
|
- break;
|
|
|
- case @enum.ResultType.KeyValueArray:
|
|
|
- List<ConcurrentDictionary<string, AddressValue>>? RDataArray = value.RData as List<ConcurrentDictionary<string, AddressValue>>;
|
|
|
- //实例化对象
|
|
|
- if (UpParamArray == null)
|
|
|
- {
|
|
|
- UpParamArray = new List<ConcurrentDictionary<string, AddressValue>>();
|
|
|
- }
|
|
|
- //空数据不做处理
|
|
|
- if (RDataArray != null && RDataArray.Count > 0)
|
|
|
- {
|
|
|
- //获取到第一次数据,准备节点检测数据是否变化
|
|
|
- if (!ConcurrentDictionaryEquals(UpParamArray, RDataArray))
|
|
|
- {
|
|
|
- foreach (var item in RDataArray)
|
|
|
- {
|
|
|
- //抛出差异数据
|
|
|
- OnEventHandler?.Invoke(this, new SubscribeData.EventParam() { Message = "存在变化数据", Params = item, State = true });
|
|
|
+ UpParamArray = RDataArray;
|
|
|
}
|
|
|
- //把这次新数据 赋值到历史数据中
|
|
|
- UpParamArray = RDataArray;
|
|
|
}
|
|
|
- }
|
|
|
- break;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //当状态为false 说明读取失败,写入日志
|
|
|
+ OnEventHandler?.Invoke(this, new SubscribeData.EventParam() { Message = $"自定义订阅轮询异常:{value.Message}", State = false });
|
|
|
}
|
|
|
}
|
|
|
}
|