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

@@ -17,8 +17,8 @@ namespace DMS.Infrastructure.Services.Mqtt
private readonly ILogger<MqttBackgroundService> _logger;
private readonly IMqttServiceManager _mqttServiceManager;
private readonly IEventService _eventService;
private readonly IAppDataStorageService _appDataStorageService;
private readonly IAppDataCenterService _appDataCenterService;
private readonly IAppStorageService _appStorageService;
private readonly IAppCenterService _appCenterService;
private readonly ConcurrentDictionary<int, MqttServer> _mqttServers;
private readonly SemaphoreSlim _reloadSemaphore = new(0);
@@ -26,14 +26,14 @@ namespace DMS.Infrastructure.Services.Mqtt
ILogger<MqttBackgroundService> logger,
IMqttServiceManager mqttServiceManager,
IEventService eventService,
IAppDataStorageService appDataStorageService,
IAppDataCenterService appDataCenterService)
IAppStorageService appStorageService,
IAppCenterService appCenterService)
{
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
_mqttServiceManager = mqttServiceManager ?? throw new ArgumentNullException(nameof(mqttServiceManager));
_eventService = eventService;
_appDataStorageService = appDataStorageService;
_appDataCenterService = appDataCenterService ?? throw new ArgumentNullException(nameof(appDataCenterService));
_appStorageService = appStorageService;
_appCenterService = appCenterService ?? throw new ArgumentNullException(nameof(appCenterService));
_mqttServers = new ConcurrentDictionary<int, MqttServer>();
_eventService.OnLoadDataCompleted += OnLoadDataCompleted;
@@ -186,7 +186,7 @@ namespace DMS.Infrastructure.Services.Mqtt
_mqttServers.Clear();
// 从数据服务中心获取所有激活的MQTT服务器
var mqttServers = _appDataStorageService.MqttServers.Values.ToList();
var mqttServers = _appStorageService.MqttServers.Values.ToList();
foreach (var mqttServer in mqttServers)
{

View File

@@ -28,14 +28,14 @@ namespace DMS.Infrastructure.Services.Mqtt
/// <summary>
/// 与该MQTT服务器关联的所有变量MQTT别名
/// </summary>
public ConcurrentDictionary<int, MqttAlias> VariableMqttAliases { get; set; }
public ConcurrentDictionary<int, MqttAlias> MqttAliases { get; set; }
/// <summary>
/// 构造函数
/// </summary>
public MqttDeviceContext()
{
VariableMqttAliases = new ConcurrentDictionary<int, MqttAlias>();
MqttAliases = new ConcurrentDictionary<int, MqttAlias>();
ReconnectAttempts = 0;
}
}

View File

@@ -19,7 +19,7 @@ namespace DMS.Infrastructure.Services.Mqtt
{
private readonly ILogger<MqttServiceManager> _logger;
private readonly IDataProcessingService _dataProcessingService;
private readonly IAppDataCenterService _appDataCenterService;
private readonly IAppCenterService _appDataCenterService;
private readonly IMqttServiceFactory _mqttServiceFactory;
private readonly IEventService _eventService;
@@ -30,7 +30,7 @@ namespace DMS.Infrastructure.Services.Mqtt
public MqttServiceManager(
ILogger<MqttServiceManager> logger,
IDataProcessingService dataProcessingService,
IAppDataCenterService appDataCenterService,
IAppCenterService appDataCenterService,
IMqttServiceFactory mqttServiceFactory,
IEventService eventService)
{
@@ -91,16 +91,16 @@ namespace DMS.Infrastructure.Services.Mqtt
/// <summary>
/// 更新MQTT服务器变量别名
/// </summary>
public void UpdateVariableMqttAliases(int mqttServerId, List<MqttAlias> variableMqttAliases)
public void UpdateMqttAliases(int mqttServerId, List<MqttAlias> mqttAliases)
{
if (_mqttContexts.TryGetValue(mqttServerId, out var context))
{
context.VariableMqttAliases.Clear();
foreach (var alias in variableMqttAliases)
context.MqttAliases.Clear();
foreach (var alias in mqttAliases)
{
context.VariableMqttAliases.AddOrUpdate(alias.Id, alias, (key, oldValue) => alias);
context.MqttAliases.AddOrUpdate(alias.Id, alias, (key, oldValue) => alias);
}
_logger.LogInformation("已更新MQTT服务器 {MqttServerId} 的变量别名列表,共 {Count} 个别名", mqttServerId, variableMqttAliases.Count);
_logger.LogInformation("已更新MQTT服务器 {MqttServerId} 的变量别名列表,共 {Count} 个别名", mqttServerId, mqttAliases.Count);
}
}