From 62ce7093cf3c42154882bf44398f81fe9d51cc68 Mon Sep 17 00:00:00 2001 From: "David P.G" Date: Wed, 1 Oct 2025 18:15:51 +0800 Subject: [PATCH] =?UTF-8?q?=201.=20=E4=BB=8E=20IDeviceManagementService=20?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E4=B8=AD=E7=A7=BB=E9=99=A4=E4=BA=86=20OnDevi?= =?UTF-8?q?ceChanged=20=E4=BA=8B=E4=BB=B6=20=20=20=202.=20=E5=9C=A8=20Devi?= =?UTF-8?q?ceManagementService=20=E4=B8=AD=E6=B7=BB=E5=8A=A0=E4=BA=86?= =?UTF-8?q?=E5=AF=B9=20IEventService=20=E7=9A=84=E4=BE=9D=E8=B5=96=20=20?= =?UTF-8?q?=20=203.=20=E5=9C=A8=20DeviceManagementService=20=E7=9A=84?= =?UTF-8?q?=E4=B8=89=E4=B8=AA=E5=86=85=E5=AD=98=E6=93=8D=E4=BD=9C=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E4=B8=AD=EF=BC=8C=E5=B0=86=E7=9B=B4=E6=8E=A5=E4=BA=8B?= =?UTF-8?q?=E4=BB=B6=E8=A7=A6=E5=8F=91=E6=94=B9=E4=B8=BA=E9=80=9A=E8=BF=87?= =?UTF-8?q?=20=5FeventService.RaiseDeviceChanged=20=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E8=A7=A6=E5=8F=91=20=20=20=204.=20EventService=20=E6=9C=AC?= =?UTF-8?q?=E8=BA=AB=E5=B7=B2=E7=BB=8F=E5=AE=9E=E7=8E=B0=E4=BA=86=20OnDevi?= =?UTF-8?q?ceChanged=20=E4=BA=8B=E4=BB=B6=E5=92=8C=E5=AF=B9=E5=BA=94?= =?UTF-8?q?=E7=9A=84=20RaiseDeviceChanged=20=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Management/IDeviceManagementService.cs | 5 +---- .../Management/DeviceManagementService.cs | 15 ++++++--------- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/DMS.Application/Interfaces/Management/IDeviceManagementService.cs b/DMS.Application/Interfaces/Management/IDeviceManagementService.cs index 3354ceb..466db7c 100644 --- a/DMS.Application/Interfaces/Management/IDeviceManagementService.cs +++ b/DMS.Application/Interfaces/Management/IDeviceManagementService.cs @@ -5,10 +5,7 @@ namespace DMS.Application.Interfaces.Management; public interface IDeviceManagementService { - /// - /// 当设备数据发生变化时触发 - /// - event EventHandler OnDeviceChanged; + /// /// 异步根据ID获取设备DTO。 diff --git a/DMS.Application/Services/Management/DeviceManagementService.cs b/DMS.Application/Services/Management/DeviceManagementService.cs index 6a97871..9388a7e 100644 --- a/DMS.Application/Services/Management/DeviceManagementService.cs +++ b/DMS.Application/Services/Management/DeviceManagementService.cs @@ -14,16 +14,13 @@ public class DeviceManagementService : IDeviceManagementService { private readonly IDeviceAppService _deviceAppService; private readonly IAppDataStorageService _appDataStorageService; + private readonly IEventService _eventService; - /// - /// 当设备数据发生变化时触发 - /// - public event EventHandler OnDeviceChanged; - - public DeviceManagementService(IDeviceAppService deviceAppService,IAppDataStorageService appDataStorageService) + public DeviceManagementService(IDeviceAppService deviceAppService, IAppDataStorageService appDataStorageService, IEventService eventService) { _deviceAppService = deviceAppService; _appDataStorageService = appDataStorageService; + _eventService = eventService; } /// @@ -113,7 +110,7 @@ public class DeviceManagementService : IDeviceManagementService { if (_appDataStorageService.Devices.TryAdd(deviceDto.Id, deviceDto)) { - OnDeviceChanged?.Invoke(this,new DeviceChangedEventArgs(DataChangeType.Added, deviceDto)); + _eventService.RaiseDeviceChanged(this, new DeviceChangedEventArgs(DataChangeType.Added, deviceDto)); } } @@ -123,7 +120,7 @@ public class DeviceManagementService : IDeviceManagementService public void UpdateDeviceInMemory(DeviceDto deviceDto) { _appDataStorageService.Devices.AddOrUpdate(deviceDto.Id, deviceDto, (key, oldValue) => deviceDto); - OnDeviceChanged?.Invoke(this,new DeviceChangedEventArgs(DataChangeType.Updated, deviceDto)); + _eventService.RaiseDeviceChanged(this, new DeviceChangedEventArgs(DataChangeType.Updated, deviceDto)); } /// @@ -145,7 +142,7 @@ public class DeviceManagementService : IDeviceManagementService _appDataStorageService.Devices.TryRemove(deviceId, out _); - OnDeviceChanged?.Invoke(this,new DeviceChangedEventArgs(DataChangeType.Deleted, deviceDto)); + _eventService.RaiseDeviceChanged(this, new DeviceChangedEventArgs(DataChangeType.Deleted, deviceDto)); } }