refactor:将AppDataCenterService改为AppCenterService,将AppDataStorageService改为AppStorageService,将触发器的增删改成合并

This commit is contained in:
2025-10-18 17:18:09 +08:00
parent 816827e5e9
commit 595139fb02
64 changed files with 1159 additions and 599 deletions

View File

@@ -19,8 +19,8 @@ namespace DMS.Infrastructure.Services.S7;
/// </summary>
public class OptimizedS7BackgroundService : BackgroundService
{
private readonly IAppDataCenterService _appDataCenterService;
private readonly IAppDataStorageService _appDataStorageService;
private readonly IAppCenterService _appCenterService;
private readonly IAppStorageService _appStorageService;
private readonly IEventService _eventService;
private readonly IDataProcessingService _dataProcessingService;
private readonly IS7ServiceManager _s7ServiceManager;
@@ -38,15 +38,15 @@ public class OptimizedS7BackgroundService : BackgroundService
/// 构造函数,注入数据服务和数据处理服务。
/// </summary>
public OptimizedS7BackgroundService(
IAppDataCenterService appDataCenterService,
IAppDataStorageService appDataStorageService,
IAppCenterService appCenterService,
IAppStorageService appStorageService,
IEventService eventService,
IDataProcessingService dataProcessingService,
IS7ServiceManager s7ServiceManager,
ILogger<OptimizedS7BackgroundService> logger)
{
_appDataCenterService = appDataCenterService;
_appDataStorageService = appDataStorageService;
_appCenterService = appCenterService;
_appStorageService = appStorageService;
_eventService = eventService;
_dataProcessingService = dataProcessingService;
_s7ServiceManager = s7ServiceManager;
@@ -76,7 +76,7 @@ public class OptimizedS7BackgroundService : BackgroundService
break;
}
if (_appDataStorageService.Devices.IsEmpty)
if (_appStorageService.Devices.IsEmpty)
{
_logger.LogInformation("没有可用的S7设备等待设备列表更新...");
continue;
@@ -124,7 +124,7 @@ public class OptimizedS7BackgroundService : BackgroundService
_variablesByPollingInterval.Clear();
_logger.LogInformation("开始加载S7变量....");
var s7Devices = _appDataStorageService
var s7Devices = _appStorageService
.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 = _appDataStorageService
var s7Devices = _appStorageService
.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 (!_appDataStorageService.Devices.TryGetValue(context.Device.Id, out var device))
if (!_appStorageService.Devices.TryGetValue(context.Device.Id, out var device))
{
_logger.LogWarning($"轮询时没有找到设备ID{context.Device.Id}");
return;

View File

@@ -19,8 +19,8 @@ namespace DMS.Infrastructure.Services.S7
private readonly ILogger<S7ServiceManager> _logger;
private readonly IEventService _eventService;
private readonly IDataProcessingService _dataProcessingService;
private readonly IAppDataCenterService _appDataCenterService;
private readonly IAppDataStorageService _appDataStorageService;
private readonly IAppCenterService _appCenterService;
private readonly IAppStorageService _appStorageService;
private readonly IS7ServiceFactory _s7ServiceFactory;
private readonly ConcurrentDictionary<int, S7DeviceContext> _deviceContexts;
private readonly SemaphoreSlim _semaphore;
@@ -30,17 +30,17 @@ namespace DMS.Infrastructure.Services.S7
ILogger<S7ServiceManager> logger,
IEventService eventService,
IDataProcessingService dataProcessingService,
IAppDataCenterService appDataCenterService,
IAppDataStorageService appDataStorageService,
IAppCenterService appCenterService,
IAppStorageService appStorageService,
IS7ServiceFactory s7ServiceFactory)
{
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
_eventService = eventService;
_dataProcessingService
= dataProcessingService ?? throw new ArgumentNullException(nameof(dataProcessingService));
_appDataCenterService
= appDataCenterService ?? throw new ArgumentNullException(nameof(appDataCenterService));
_appDataStorageService = appDataStorageService;
_appCenterService
= appCenterService ?? throw new ArgumentNullException(nameof(appCenterService));
_appStorageService = 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 = _appDataStorageService.Variables.Values.Where(v => e.VariableIds.Contains(v.Id))
// var variables = _appStorageService.Variables.Values.Where(v => e.VariableIds.Contains(v.Id))
// .ToList();
// foreach (var variable in variables)
// {