2025-07-18 19:56:00 +08:00
|
|
|
using DMS.Helper;
|
2025-07-19 11:11:01 +08:00
|
|
|
using DMS.WPF.Models;
|
2025-07-16 15:08:56 +08:00
|
|
|
|
2025-07-18 19:56:00 +08:00
|
|
|
namespace DMS.Services.Processors;
|
2025-07-16 15:08:56 +08:00
|
|
|
|
2025-07-17 20:13:21 +08:00
|
|
|
public class CheckValueChangedProcessor : IVariableProcessor
|
2025-07-16 15:08:56 +08:00
|
|
|
{
|
|
|
|
|
private readonly DataServices _dataServices;
|
|
|
|
|
|
|
|
|
|
public CheckValueChangedProcessor(DataServices dataServices)
|
|
|
|
|
{
|
|
|
|
|
_dataServices = dataServices;
|
|
|
|
|
}
|
2025-07-17 20:13:21 +08:00
|
|
|
public Task ProcessAsync(VariableContext context)
|
2025-07-16 15:08:56 +08:00
|
|
|
{
|
2025-07-17 20:13:21 +08:00
|
|
|
Variable newVariable = context.Data;
|
|
|
|
|
if (!_dataServices.AllVariables.TryGetValue(newVariable.Id, out Variable oldVariable))
|
2025-07-16 15:08:56 +08:00
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|