主要变更:
1. 创建了 DeviceStateType 枚举来区分状态类型(激活/连接) 2. 创建了 DeviceStateChangedEventArgs 统一事件类 3. 更新了 IEventService 接口,将两个事件合并为一个 4. 更新了 EventService 实现以支持新事件 5. 更新了所有相关服务(DeviceMonitoringService, OpcUaServiceManager, S7ServiceManager, DeviceDataService, DeviceItemViewModel) 关键优点: - 减少了事件类型的数量,简化了事件系统 - 为设备状态变化提供了一致的处理方式 - 保持了向后兼容性,将旧类标记为 [Obsolete]
This commit is contained in:
18
DMS.Core/Enums/DeviceStateType.cs
Normal file
18
DMS.Core/Enums/DeviceStateType.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
namespace DMS.Core.Enums
|
||||
{
|
||||
/// <summary>
|
||||
/// 设备状态类型枚举
|
||||
/// </summary>
|
||||
public enum DeviceStateType
|
||||
{
|
||||
/// <summary>
|
||||
/// 激活状态
|
||||
/// </summary>
|
||||
Active,
|
||||
|
||||
/// <summary>
|
||||
/// 连接状态
|
||||
/// </summary>
|
||||
Connection
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,9 @@ namespace DMS.Core.Events;
|
||||
|
||||
/// <summary>
|
||||
/// 设备状态改变事件参数
|
||||
/// 已弃用:请使用 DeviceStateChangedEventArgs 替代
|
||||
/// </summary>
|
||||
[Obsolete("Use DeviceStateChangedEventArgs instead")]
|
||||
public class DeviceActiveChangedEventArgs : EventArgs
|
||||
{
|
||||
/// <summary>
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
namespace DMS.Core.Events;
|
||||
|
||||
/// <summary>
|
||||
/// 已弃用:请使用 DeviceStateChangedEventArgs 替代
|
||||
/// </summary>
|
||||
[Obsolete("Use DeviceStateChangedEventArgs instead")]
|
||||
public class DeviceConnectChangedEventArgs
|
||||
{
|
||||
/// <summary>
|
||||
|
||||
52
DMS.Core/Events/DeviceStateChangedEventArgs.cs
Normal file
52
DMS.Core/Events/DeviceStateChangedEventArgs.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using DMS.Core.Enums;
|
||||
|
||||
namespace DMS.Core.Events
|
||||
{
|
||||
/// <summary>
|
||||
/// 设备状态改变事件参数
|
||||
/// 统一处理设备激活状态和连接状态的变更
|
||||
/// </summary>
|
||||
public class DeviceStateChangedEventArgs : System.EventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// 设备ID
|
||||
/// </summary>
|
||||
public int DeviceId { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 设备名称
|
||||
/// </summary>
|
||||
public string DeviceName { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 状态值
|
||||
/// </summary>
|
||||
public bool StateValue { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 状态类型 (激活状态或连接状态)
|
||||
/// </summary>
|
||||
public DeviceStateType StateType { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 状态改变时间
|
||||
/// </summary>
|
||||
public DateTime ChangeTime { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 初始化DeviceStateChangedEventArgs类的新实例
|
||||
/// </summary>
|
||||
/// <param name="deviceId">设备ID</param>
|
||||
/// <param name="deviceName">设备名称</param>
|
||||
/// <param name="stateValue">状态值</param>
|
||||
/// <param name="stateType">状态类型</param>
|
||||
public DeviceStateChangedEventArgs(int deviceId, string deviceName, bool stateValue, DeviceStateType stateType)
|
||||
{
|
||||
DeviceId = deviceId;
|
||||
DeviceName = deviceName ?? string.Empty;
|
||||
StateValue = stateValue;
|
||||
StateType = stateType;
|
||||
ChangeTime = DateTime.Now;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user