2025-09-12 13:25:39 +08:00
|
|
|
using System;
|
2025-09-12 14:59:32 +08:00
|
|
|
using DMS.Application.Events;
|
|
|
|
|
using DMS.Application.Interfaces;
|
2025-09-15 20:54:32 +08:00
|
|
|
using DMS.Core.Events;
|
2025-09-12 13:25:39 +08:00
|
|
|
|
2025-09-12 14:59:32 +08:00
|
|
|
namespace DMS.Application.Services;
|
2025-09-12 13:25:39 +08:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 事件服务实现类,用于统一管理应用程序中的各种事件
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class EventService : IEventService
|
|
|
|
|
{
|
2025-09-12 15:45:14 +08:00
|
|
|
private readonly IAppDataStorageService _appDataStorageService;
|
|
|
|
|
|
|
|
|
|
public EventService(IAppDataStorageService appDataStorageService)
|
|
|
|
|
{
|
|
|
|
|
_appDataStorageService = appDataStorageService;
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-12 13:25:39 +08:00
|
|
|
#region 设备事件
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 设备状态改变事件
|
|
|
|
|
/// </summary>
|
2025-09-12 14:59:32 +08:00
|
|
|
public event EventHandler<DeviceActiveChangedEventArgs> OnDeviceActiveChanged;
|
2025-09-12 17:22:15 +08:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 设备运行改变事件
|
|
|
|
|
/// </summary>
|
|
|
|
|
public event EventHandler<DeviceConnectChangedEventArgs> OnDeviceConnectChanged;
|
|
|
|
|
|
2025-10-01 18:02:33 +08:00
|
|
|
/// <summary>
|
|
|
|
|
/// 设备添加事件
|
|
|
|
|
/// </summary>
|
|
|
|
|
public event EventHandler<DeviceChangedEventArgs> OnDeviceChanged;
|
|
|
|
|
|
2025-09-12 13:25:39 +08:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 触发设备状态改变事件
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender">事件发送者</param>
|
|
|
|
|
/// <param name="e">设备状态改变事件参数</param>
|
2025-09-12 15:45:14 +08:00
|
|
|
public void RaiseDeviceActiveChanged(object sender, DeviceActiveChangedEventArgs e)
|
2025-09-12 13:25:39 +08:00
|
|
|
{
|
2025-09-12 15:45:14 +08:00
|
|
|
if (_appDataStorageService.Devices.TryGetValue(e.DeviceId, out var device))
|
|
|
|
|
{
|
|
|
|
|
if (device.IsActive != e.NewStatus)
|
|
|
|
|
{
|
|
|
|
|
device.IsActive = e.NewStatus;
|
|
|
|
|
OnDeviceActiveChanged?.Invoke(sender, e);
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-09-12 13:25:39 +08:00
|
|
|
}
|
|
|
|
|
|
2025-09-12 17:22:15 +08:00
|
|
|
/// <summary>
|
|
|
|
|
/// 触发设备状态改变事件
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender">事件发送者</param>
|
|
|
|
|
/// <param name="e">设备状态改变事件参数</param>
|
|
|
|
|
public void RaiseDeviceConnectChanged(object sender, DeviceConnectChangedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
OnDeviceConnectChanged?.Invoke(sender, e);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-01 18:02:33 +08:00
|
|
|
/// <summary>
|
|
|
|
|
/// 触发设备添加事件
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender">事件发送者</param>
|
|
|
|
|
/// <param name="e">设备变更事件参数</param>
|
|
|
|
|
public void RaiseDeviceChanged(object sender, DeviceChangedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
OnDeviceChanged?.Invoke(sender, e);
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-12 13:25:39 +08:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 变量事件
|
2025-09-15 20:54:32 +08:00
|
|
|
/// <summary>
|
|
|
|
|
/// 变量值改变事件
|
|
|
|
|
/// </summary>
|
|
|
|
|
public event EventHandler<VariableChangedEventArgs> OnVariableChanged;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 触发变量值改变事件
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender">事件发送者</param>
|
|
|
|
|
/// <param name="e">变量值改变事件参数</param>
|
|
|
|
|
public void RaiseVariableChanged(object sender, VariableChangedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
OnVariableChanged?.Invoke(sender, e);
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-16 14:42:23 +08:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 变量启停改变事件
|
|
|
|
|
/// </summary>
|
|
|
|
|
public event EventHandler<VariablesActiveChangedEventArgs> OnVariableActiveChanged;
|
|
|
|
|
public void RaiseVariableActiveChanged(object sender, VariablesActiveChangedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
OnVariableActiveChanged?.Invoke(sender, e);
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-12 13:25:39 +08:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 变量值改变事件
|
|
|
|
|
/// </summary>
|
2025-09-15 20:54:32 +08:00
|
|
|
public event EventHandler<VariableValueChangedEventArgs> OnVariableValueChanged;
|
2025-09-12 13:25:39 +08:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 触发变量值改变事件
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender">事件发送者</param>
|
|
|
|
|
/// <param name="e">变量值改变事件参数</param>
|
|
|
|
|
public void RaiseVariableValueChanged(object sender, VariableValueChangedEventArgs e)
|
|
|
|
|
{
|
2025-09-15 20:54:32 +08:00
|
|
|
OnVariableValueChanged?.Invoke(sender, e);
|
2025-09-12 13:25:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region MQTT事件
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// MQTT连接状态改变事件
|
|
|
|
|
/// </summary>
|
|
|
|
|
public event EventHandler<MqttConnectionChangedEventArgs> MqttConnectionChanged;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 触发MQTT连接状态改变事件
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender">事件发送者</param>
|
|
|
|
|
/// <param name="e">MQTT连接状态改变事件参数</param>
|
|
|
|
|
public void RaiseMqttConnectionChanged(object sender, MqttConnectionChangedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
MqttConnectionChanged?.Invoke(sender, e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|