本次提交对系统进行了两项主要的重构和优化:
1. 重构数据处理链:
* 移除了 CheckValueChangedProcessor 和 LoggingProcessor,简化了数据处理流程。
* 调整了 App.xaml.cs 中的处理器注册顺序,使处理链更加清晰。
2. 优化OPC UA变量变更处理:
* 完全重构了 OpcUaServiceManager 中的 OnVariableChanged 事件处理方法。
* 新逻辑能够根据变量属性(IsActive, PollingInterval 等)的变化,进行精确的、针对单个节点的订阅和取消订阅操作,取代了之前重置整个设备订阅的低效方式。
* 实现了对已删除变量的订阅取消逻辑,确保了资源的正确释放。
这些变更显著提升了 OPC UA 订阅管理的效率和精确性。
This commit is contained in:
@@ -1,30 +0,0 @@
|
||||
using DMS.Core.Models;
|
||||
using DMS.Application.Interfaces;
|
||||
using DMS.Application.Models;
|
||||
|
||||
namespace DMS.Application.Services.Processors;
|
||||
|
||||
public class CheckValueChangedProcessor : IVariableProcessor
|
||||
{
|
||||
|
||||
|
||||
public Task ProcessAsync(VariableContext context)
|
||||
{
|
||||
// Variable newVariable = context.Data;
|
||||
// if (!_dataServices.AllVariables.TryGetValue(newVariable.Id, out Variable oldVariable))
|
||||
// {
|
||||
// NlogHelper.Warn($"检查变量值是否改变时在_dataServices.AllVariables中找不到Id:{newVariable.Id},Name:{newVariable.Name}的变量。");
|
||||
// context.IsHandled = true;
|
||||
// return Task.CompletedTask;
|
||||
// }
|
||||
|
||||
// if (newVariable.DataValue == oldVariable.DataValue)
|
||||
// {
|
||||
// // 值没有变化,直接完成
|
||||
// context.IsHandled = true;
|
||||
// }
|
||||
//
|
||||
// 在这里处理 context.Data
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
using DMS.Application.Interfaces;
|
||||
using DMS.Application.Models;
|
||||
|
||||
|
||||
namespace DMS.Application.Services.Processors;
|
||||
|
||||
/// <summary>
|
||||
/// 一个简单的数据处理器实现,用于演示。
|
||||
/// 其主要功能是记录接收到的变量数据的名称和值。
|
||||
/// </summary>
|
||||
public class LoggingProcessor : IVariableProcessor
|
||||
{
|
||||
public LoggingProcessor()
|
||||
{
|
||||
}
|
||||
|
||||
public Task ProcessAsync(VariableContext context)
|
||||
{
|
||||
// NlogHelper.Info($"处理数据: {context.Data.Name}, 值: {context.Data.DataValue}");
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
@@ -37,14 +37,6 @@ public class UpdateDbVariableProcessor : IVariableProcessor, IDisposable
|
||||
|
||||
public async Task ProcessAsync(VariableContext context)
|
||||
{
|
||||
// 检查新值是否有效,以及是否与旧值不同
|
||||
if (context.NewValue == null || Equals(context.Data.DataValue, context.NewValue?.ToString()))
|
||||
{
|
||||
return; // 值未变或新值无效,跳过
|
||||
}
|
||||
|
||||
// 用新值更新上下文中的数据,确保处理链的后续环节能看到最新值
|
||||
context.Data.DataValue = context.NewValue?.ToString();
|
||||
|
||||
_queue.Enqueue(context.Data);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user