完成S7变量启用和停用更新

This commit is contained in:
2025-09-16 14:42:23 +08:00
parent 3102938f92
commit 74fde6bd8b
59 changed files with 226 additions and 454 deletions

View File

@@ -1,7 +1,6 @@
using System;
using DMS.Core.Enums;
namespace DMS.Application.DTOs.Events
namespace DMS.Application.Events
{
/// <summary>
/// 数据变更事件参数基类

View File

@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
namespace DMS.Application.DTOs.Events
namespace DMS.Application.Events
{
/// <summary>
/// 数据加载完成事件参数

View File

@@ -1,45 +0,0 @@
using System;
namespace DMS.Application.Events;
/// <summary>
/// 设备状态改变事件参数
/// </summary>
public class DeviceActiveChangedEventArgs : EventArgs
{
/// <summary>
/// 设备ID
/// </summary>
public int DeviceId { get; }
/// <summary>
/// 设备名称
/// </summary>
public string DeviceName { get; }
/// <summary>
/// 新状态
/// </summary>
public bool NewStatus { get; }
/// <summary>
/// 状态改变时间
/// </summary>
public DateTime ChangeTime { get; }
/// <summary>
/// 初始化DeviceStatusChangedEventArgs类的新实例
/// </summary>
/// <param name="deviceId">设备ID</param>
/// <param name="deviceName">设备名称</param>
/// <param name="oldStatus">旧状态</param>
/// <param name="newStatus">新状态</param>
public DeviceActiveChangedEventArgs(int deviceId, string deviceName, bool newStatus)
{
DeviceId = deviceId;
DeviceName = deviceName;
NewStatus = newStatus;
ChangeTime = DateTime.Now;
}
}

View File

@@ -1,7 +1,7 @@
using System;
using DMS.Application.DTOs;
using DMS.Core.Enums;
namespace DMS.Application.DTOs.Events
namespace DMS.Application.Events
{
/// <summary>
/// 设备变更事件参数

View File

@@ -1,33 +0,0 @@
namespace DMS.Application.Events;
public class DeviceConnectChangedEventArgs
{
/// <summary>
/// 设备ID
/// </summary>
public int DeviceId { get; }
/// <summary>
/// 设备名称
/// </summary>
public string DeviceName { get; }
/// <summary>
/// 新状态
/// </summary>
public bool NewStatus { get; }
/// <summary>
/// 初始化DeviceStatusChangedEventArgs类的新实例
/// </summary>
/// <param name="deviceId">设备ID</param>
/// <param name="deviceName">设备名称</param>
/// <param name="oldStatus">旧状态</param>
/// <param name="newStatus">新状态</param>
public DeviceConnectChangedEventArgs(int deviceId, string deviceName, bool newStatus)
{
DeviceId = deviceId;
DeviceName = deviceName;
NewStatus = newStatus;
}
}

View File

@@ -1,7 +1,7 @@
using System;
using DMS.Application.DTOs;
using DMS.Core.Enums;
namespace DMS.Application.DTOs.Events
namespace DMS.Application.Events
{
/// <summary>
/// 菜单变更事件参数

View File

@@ -1,50 +0,0 @@
using System;
namespace DMS.Application.Events;
/// <summary>
/// MQTT连接状态改变事件参数
/// </summary>
public class MqttConnectionChangedEventArgs : EventArgs
{
/// <summary>
/// MQTT服务器ID
/// </summary>
public int MqttServerId { get; }
/// <summary>
/// MQTT服务器名称
/// </summary>
public string MqttServerName { get; }
/// <summary>
/// 旧连接状态
/// </summary>
public bool OldConnectionStatus { get; }
/// <summary>
/// 新连接状态
/// </summary>
public bool NewConnectionStatus { get; }
/// <summary>
/// 状态改变时间
/// </summary>
public DateTime ChangeTime { get; }
/// <summary>
/// 初始化MqttConnectionChangedEventArgs类的新实例
/// </summary>
/// <param name="mqttServerId">MQTT服务器ID</param>
/// <param name="mqttServerName">MQTT服务器名称</param>
/// <param name="oldStatus">旧连接状态</param>
/// <param name="newStatus">新连接状态</param>
public MqttConnectionChangedEventArgs(int mqttServerId, string mqttServerName, bool oldStatus, bool newStatus)
{
MqttServerId = mqttServerId;
MqttServerName = mqttServerName;
OldConnectionStatus = oldStatus;
NewConnectionStatus = newStatus;
ChangeTime = DateTime.Now;
}
}

View File

@@ -1,7 +1,7 @@
using System;
using DMS.Application.DTOs;
using DMS.Core.Enums;
namespace DMS.Application.DTOs.Events
namespace DMS.Application.Events
{
/// <summary>
/// MQTT服务器变更事件参数

View File

@@ -1,7 +1,7 @@
using System;
using DMS.Application.DTOs;
using DMS.Core.Enums;
namespace DMS.Application.DTOs.Events
namespace DMS.Application.Events
{
/// <summary>
/// Nlog日志变更事件参数

View File

@@ -1,7 +1,7 @@
using System;
using DMS.Application.DTOs;
using DMS.Core.Enums;
namespace DMS.Application.DTOs.Events
namespace DMS.Application.Events
{
/// <summary>
/// 变量变更事件参数

View File

@@ -1,7 +1,7 @@
using System;
using DMS.Application.DTOs;
using DMS.Core.Enums;
namespace DMS.Application.DTOs.Events
namespace DMS.Application.Events
{
/// <summary>
/// 变量表变更事件参数

View File

@@ -1,6 +1,5 @@
using System.Collections.Concurrent;
using DMS.Application.DTOs;
using DMS.Application.DTOs.Events;
using DMS.Application.Interfaces.Management;
using DMS.Application.Services;
using DMS.Core.Models;

View File

@@ -1,6 +1,6 @@
using System.Collections.Concurrent;
using DMS.Application.DTOs;
using DMS.Application.DTOs.Events;
using DMS.Application.Events;
namespace DMS.Application.Interfaces;

View File

@@ -1,5 +1,4 @@
using System;
using DMS.Application.Events;
namespace DMS.Application.Interfaces;

View File

@@ -1,5 +1,4 @@
using System;
using DMS.Application.DTOs.Events;
using DMS.Application.Events;
using DMS.Core.Events;
@@ -81,4 +80,11 @@ public interface IEventService
/// <param name="sender">事件发送者</param>
/// <param name="e">变量值改变事件参数</param>
void RaiseVariableChanged(object sender, VariableChangedEventArgs e);
void RaiseVariableActiveChanged(object sender,VariablesActiveChangedEventArgs e);
/// <summary>
/// 变量启停改变事件
/// </summary>
event EventHandler<VariablesActiveChangedEventArgs> OnVariableActiveChanged;
}

View File

@@ -1,5 +1,5 @@
using DMS.Application.DTOs;
using DMS.Application.DTOs.Events;
using DMS.Application.Events;
namespace DMS.Application.Interfaces.Management;

View File

@@ -1,5 +1,5 @@
using DMS.Application.DTOs;
using DMS.Application.DTOs.Events;
using DMS.Application.Events;
namespace DMS.Application.Interfaces.Management;

View File

@@ -1,5 +1,5 @@
using DMS.Application.DTOs;
using DMS.Application.DTOs.Events;
using DMS.Application.Events;
namespace DMS.Application.Interfaces.Management;

View File

@@ -1,6 +1,5 @@
using AutoMapper;
using DMS.Application.DTOs;
using DMS.Application.DTOs.Events;
using DMS.Core.Models;
using DMS.Application.Interfaces;
using DMS.Core.Interfaces;
@@ -11,6 +10,7 @@ using System.Collections.Generic;
using System.Threading.Tasks;
using System;
using System.Linq;
using DMS.Application.Events;
using DMS.Application.Interfaces.Management;
using DMS.Core.Events;

View File

@@ -3,7 +3,7 @@ using DMS.Application.DTOs;
using DMS.Application.Interfaces;
using DMS.Core.Interfaces;
using System.Collections.Concurrent;
using DMS.Application.DTOs.Events;
using DMS.Application.Events;
using DMS.Application.Interfaces.Database;
using DMS.Core.Models;

View File

@@ -1,5 +1,4 @@
using System;
using DMS.Application.DTOs.Events;
using DMS.Application.Events;
using DMS.Application.Interfaces;
using DMS.Core.Events;
@@ -77,6 +76,16 @@ public class EventService : IEventService
OnVariableChanged?.Invoke(sender, e);
}
/// <summary>
/// 变量启停改变事件
/// </summary>
public event EventHandler<VariablesActiveChangedEventArgs> OnVariableActiveChanged;
public void RaiseVariableActiveChanged(object sender, VariablesActiveChangedEventArgs e)
{
OnVariableActiveChanged?.Invoke(sender, e);
}
/// <summary>
/// 变量值改变事件

View File

@@ -1,5 +1,5 @@
using DMS.Application.DTOs;
using DMS.Application.DTOs.Events;
using DMS.Application.Events;
using DMS.Application.Interfaces;
using DMS.Application.Interfaces.Database;
using DMS.Application.Interfaces.Management;

View File

@@ -1,5 +1,5 @@
using DMS.Application.DTOs;
using DMS.Application.DTOs.Events;
using DMS.Application.Events;
using DMS.Application.Interfaces;
using DMS.Application.Interfaces.Database;
using DMS.Application.Interfaces.Management;

View File

@@ -1,5 +1,5 @@
using DMS.Application.DTOs;
using DMS.Application.DTOs.Events;
using DMS.Application.Events;
using DMS.Application.Interfaces;
using DMS.Application.Interfaces.Management;
using DMS.Core.Enums;

View File

@@ -1,5 +1,5 @@
using DMS.Application.DTOs;
using DMS.Application.DTOs.Events;
using DMS.Application.Events;
using DMS.Application.Interfaces;
using DMS.Application.Interfaces.Database;
using DMS.Application.Interfaces.Management;

View File

@@ -1,6 +1,6 @@
using System.Collections.Concurrent;
using DMS.Application.DTOs;
using DMS.Application.DTOs.Events;
using DMS.Application.Events;
using DMS.Application.Interfaces;
using DMS.Application.Interfaces.Database;
using DMS.Application.Interfaces.Management;

View File

@@ -1,6 +1,6 @@
using System.Collections.Concurrent;
using DMS.Application.DTOs;
using DMS.Application.DTOs.Events;
using DMS.Application.Events;
using DMS.Application.Interfaces;
using DMS.Application.Interfaces.Database;
using DMS.Application.Interfaces.Management;

View File

@@ -2,8 +2,8 @@ using System;
using System.Collections.Concurrent;
using System.Threading;
using System.Threading.Tasks;
using DMS.Application.Events;
using DMS.Application.Interfaces;
using DMS.Core.Events;
using DMS.Core.Models;
using Microsoft.Extensions.Logging;

View File

@@ -33,7 +33,7 @@ public class HistoryProcessor : IVariableProcessor, IDisposable
// 只有当数据需要保存时才记录历史
if (!context.Data.IsHistoryEnabled) // 如果数据已经被其他处理器处理过或者不需要保存,则跳过
{
_logger.LogDebug("变量 {VariableName} (ID: {VariableId}) 历史记录已禁用,跳过处理", context.Data.Name, context.Data.Id);
// _logger.LogDebug("变量 {VariableName} (ID: {VariableId}) 历史记录已禁用,跳过处理", context.Data.Name, context.Data.Id);
return;
}

View File

@@ -20,7 +20,7 @@ public class ValueConvertProcessor : IVariableProcessor
ConvertS7ValueToStringAndNumeric(context.Data, context.NewValue);
context.Data.UpdatedAt = DateTime.Now;
// 如何值没有变化则中断处理
if (context.Data.DataValue!=oldValue)
if (context.Data.DataValue==oldValue)
{
context.IsHandled = true;
}