将S7后台服务移植到DMS.Infrastructure项目中

This commit is contained in:
2025-07-24 22:03:26 +08:00
parent 35e5033094
commit 58cb05645e
9 changed files with 597 additions and 3 deletions

View File

@@ -0,0 +1,56 @@
using DMS.Application.Interfaces;
using DMS.Core.Interfaces;
using DMS.Core.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace DMS.Infrastructure.Services;
public class DeviceDataService : IDeviceDataService
{
private readonly IRepositoryManager _repositoryManager;
private List<Device> _devices;
public List<Device> Devices => _devices;
public event Action<List<Device>> OnDeviceListChanged;
public event Action<Device, bool> OnDeviceIsActiveChanged;
public DeviceDataService(IRepositoryManager repositoryManager)
{
_repositoryManager = repositoryManager;
_devices = new List<Device>();
}
public async Task InitializeAsync()
{
await LoadDevicesAsync();
}
private async Task LoadDevicesAsync()
{
_devices = (await _repositoryManager.Devices.GetAllAsync()).ToList();
OnDeviceListChanged?.Invoke(_devices);
}
// 模拟设备激活状态变更,实际应用中可能由其他服务触发
public async Task SetDeviceIsActiveAsync(int deviceId, bool isActive)
{
var device = _devices.FirstOrDefault(d => d.Id == deviceId);
if (device != null)
{
device.IsActive = isActive;
OnDeviceIsActiveChanged?.Invoke(device, isActive);
// 实际应用中,这里可能还需要更新数据库
await _repositoryManager.Devices.UpdateAsync(device);
}
}
// 模拟设备列表变更,实际应用中可能由其他服务触发
public async Task RefreshDeviceListAsync()
{
await LoadDevicesAsync();
}
}