refactor:完成重构设备的添加,删除,更新。

This commit is contained in:
2025-10-22 14:06:16 +08:00
parent e995ec7207
commit 54d040b45f
76 changed files with 1028 additions and 1161 deletions

View File

@@ -20,7 +20,7 @@ namespace DMS.Infrastructure.Services.S7;
public class OptimizedS7BackgroundService : BackgroundService
{
private readonly IAppCenterService _appCenterService;
private readonly IAppStorageService _appStorageService;
private readonly IAppDataService _appDataService;
private readonly IEventService _eventService;
private readonly IDataProcessingService _dataProcessingService;
private readonly IS7ServiceManager _s7ServiceManager;
@@ -39,14 +39,14 @@ public class OptimizedS7BackgroundService : BackgroundService
/// </summary>
public OptimizedS7BackgroundService(
IAppCenterService appCenterService,
IAppStorageService appStorageService,
IAppDataService appStorageService,
IEventService eventService,
IDataProcessingService dataProcessingService,
IS7ServiceManager s7ServiceManager,
ILogger<OptimizedS7BackgroundService> logger)
{
_appCenterService = appCenterService;
_appStorageService = appStorageService;
_appDataService = appStorageService;
_eventService = eventService;
_dataProcessingService = dataProcessingService;
_s7ServiceManager = s7ServiceManager;
@@ -76,7 +76,7 @@ public class OptimizedS7BackgroundService : BackgroundService
break;
}
if (_appStorageService.Devices.IsEmpty)
if (_appDataService.Devices.IsEmpty)
{
_logger.LogInformation("没有可用的S7设备等待设备列表更新...");
continue;
@@ -124,7 +124,7 @@ public class OptimizedS7BackgroundService : BackgroundService
_variablesByPollingInterval.Clear();
_logger.LogInformation("开始加载S7变量....");
var s7Devices = _appStorageService
var s7Devices = _appDataService
.Devices.Values.Where(d => d.Protocol == ProtocolType.S7 && d.IsActive == true)
.ToList();
@@ -161,7 +161,7 @@ public class OptimizedS7BackgroundService : BackgroundService
/// </summary>
private async Task ConnectS7ServiceAsync(CancellationToken stoppingToken)
{
var s7Devices = _appStorageService
var s7Devices = _appDataService
.Devices.Values.Where(d => d.Protocol == ProtocolType.S7 && d.IsActive == true)
.ToList();
@@ -207,7 +207,7 @@ public class OptimizedS7BackgroundService : BackgroundService
private async Task PollVariablesForDeviceAsync(S7DeviceContext context, List<Variable> variables,
CancellationToken stoppingToken)
{
if (!_appStorageService.Devices.TryGetValue(context.Device.Id, out var device))
if (!_appDataService.Devices.TryGetValue(context.Device.Id, out var device))
{
_logger.LogWarning($"轮询时没有找到设备ID{context.Device.Id}");
return;

View File

@@ -20,7 +20,7 @@ namespace DMS.Infrastructure.Services.S7
private readonly IEventService _eventService;
private readonly IDataProcessingService _dataProcessingService;
private readonly IAppCenterService _appCenterService;
private readonly IAppStorageService _appStorageService;
private readonly IAppDataService _appDataService;
private readonly IS7ServiceFactory _s7ServiceFactory;
private readonly ConcurrentDictionary<int, S7DeviceContext> _deviceContexts;
private readonly SemaphoreSlim _semaphore;
@@ -31,7 +31,7 @@ namespace DMS.Infrastructure.Services.S7
IEventService eventService,
IDataProcessingService dataProcessingService,
IAppCenterService appCenterService,
IAppStorageService appStorageService,
IAppDataService appStorageService,
IS7ServiceFactory s7ServiceFactory)
{
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
@@ -40,7 +40,7 @@ namespace DMS.Infrastructure.Services.S7
= dataProcessingService ?? throw new ArgumentNullException(nameof(dataProcessingService));
_appCenterService
= appCenterService ?? throw new ArgumentNullException(nameof(appCenterService));
_appStorageService = appStorageService;
_appDataService = appStorageService;
_s7ServiceFactory = s7ServiceFactory ?? throw new ArgumentNullException(nameof(s7ServiceFactory));
_deviceContexts = new ConcurrentDictionary<int, S7DeviceContext>();
_semaphore = new SemaphoreSlim(10, 10); // 默认最大并发连接数为10
@@ -54,7 +54,7 @@ namespace DMS.Infrastructure.Services.S7
// if (_deviceContexts.TryGetValue(e.DeviceId, out var s7DeviceContext))
// {
// var variables = _appStorageService.Variables.Values.Where(v => e.VariableIds.Contains(v.Id))
// var variables = _appDataService.Variables.Values.Where(v => e.VariableIds.Contains(v.Id))
// .ToList();
// foreach (var variable in variables)
// {