Files
DMS/DMS.Application/Interfaces/Management/IDeviceManagementService.cs
David P.G 2dda2029bd 1. 重构 DeviceManagementService 类:
- 修改 CreateDeviceWithDetailsAsync 方法,在数据库创建成功后自动添加到内存
      - 修改 UpdateDeviceAsync 方法,在数据库更新成功后自动更新内存
      - 修改 DeleteDeviceByIdAsync 方法,在数据库删除成功后自动从内存移除
      - 修改 ToggleDeviceActiveStateAsync 方法,在数据库切换激活状态后更新内存

   2. 更新 DeviceDataService 类:
      - 移除了在 AddDevice 方法中的独立 AddDeviceToMemory 调用
      - 移除了在 DeleteDevice 方法中的独立 RemoveDeviceFromMemory 调用
      - 为 UpdateDevice 方法添加了注释,说明内存自动更新

   3. 更新 DeviceMonitoringService 类:
      - 在 OnDeviceActiveChanged 方法中使用 Task 运行异步的 UpdateDeviceAsync 调用

   4. 更新接口文档:
      - 在 IDeviceManagementService 接口中更新了内存操作方法的注释,说明通常由其他操作自动调用
2025-10-01 18:09:30 +08:00

62 lines
1.9 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using DMS.Application.DTOs;
using DMS.Application.Events;
namespace DMS.Application.Interfaces.Management;
public interface IDeviceManagementService
{
/// <summary>
/// 当设备数据发生变化时触发
/// </summary>
event EventHandler<DeviceChangedEventArgs> OnDeviceChanged;
/// <summary>
/// 异步根据ID获取设备DTO。
/// </summary>
Task<DeviceDto> GetDeviceByIdAsync(int id);
/// <summary>
/// 异步获取所有设备DTO列表。
/// </summary>
Task<List<DeviceDto>> GetAllDevicesAsync();
/// <summary>
/// 异步创建一个新设备及其关联的变量表和菜单(事务性操作)。
/// </summary>
Task<CreateDeviceWithDetailsDto> CreateDeviceWithDetailsAsync(CreateDeviceWithDetailsDto dto);
/// <summary>
/// 异步更新一个已存在的设备。
/// </summary>
Task<int> UpdateDeviceAsync(DeviceDto deviceDto);
/// <summary>
/// 异步删除一个设备。
/// </summary>
Task<bool> DeleteDeviceByIdAsync(int deviceId);
/// <summary>
/// 异步切换设备的激活状态。
/// </summary>
Task ToggleDeviceActiveStateAsync(int id);
/// <summary>
/// 在内存中添加设备
/// 注意此方法通常由其他操作如CreateDeviceWithDetailsAsync自动调用一般不需要直接调用
/// </summary>
void AddDeviceToMemory(DeviceDto deviceDto);
/// <summary>
/// 在内存中更新设备
/// 注意此方法通常由其他操作如UpdateDeviceAsync自动调用一般不需要直接调用
/// </summary>
void UpdateDeviceInMemory(DeviceDto deviceDto);
/// <summary>
/// 在内存中删除设备
/// 注意此方法通常由其他操作如DeleteDeviceByIdAsync自动调用一般不需要直接调用
/// </summary>
void RemoveDeviceFromMemory(int deviceId);
}