2025-09-09 13:35:16 +08:00
|
|
|
using DMS.Application.Interfaces;
|
|
|
|
|
using System.Collections.Concurrent;
|
2025-09-16 14:42:23 +08:00
|
|
|
using DMS.Application.Events;
|
2025-09-23 09:28:08 +08:00
|
|
|
using DMS.Application.Interfaces.Management;
|
2025-09-23 06:51:29 +08:00
|
|
|
using DMS.Application.Services.Management;
|
2025-09-09 18:17:15 +08:00
|
|
|
using DMS.Core.Models;
|
2025-09-23 05:48:21 +08:00
|
|
|
using DMS.Core.Models.Triggers;
|
|
|
|
|
using DMS.Application.Services.Triggers;
|
2025-09-09 13:35:16 +08:00
|
|
|
|
|
|
|
|
namespace DMS.Application.Services;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 数据加载服务,负责从数据源加载数据到内存中
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class DataLoaderService : IDataLoaderService
|
|
|
|
|
{
|
2025-10-18 17:59:21 +08:00
|
|
|
private readonly IMqttManagementService _mqttManagementService;
|
2025-10-11 18:07:01 +08:00
|
|
|
private readonly IMqttAliasManagementService _mqttAliasManagementService;
|
2025-09-23 05:48:21 +08:00
|
|
|
private readonly ITriggerManagementService _triggerManagementService; // 添加触发器管理服务
|
2025-10-05 11:21:05 +08:00
|
|
|
private readonly IEventService _eventService; // 添加事件服务
|
2025-10-18 17:59:21 +08:00
|
|
|
private readonly IDeviceManagementService _deviceManagementService; // 添加设备管理服务
|
|
|
|
|
private readonly IVariableTableManagementService _variableTableManagementService; // 添加变量表管理服务
|
|
|
|
|
private readonly IVariableManagementService _variableManagementService; // 添加变量管理服务
|
|
|
|
|
private readonly IMenuManagementService _menuManagementService; // 添加菜单管理服务
|
|
|
|
|
private readonly ILogManagementService _logManagementService; // 添加日志管理服务
|
2025-10-05 11:21:05 +08:00
|
|
|
|
2025-09-09 17:47:20 +08:00
|
|
|
|
2025-09-09 13:35:16 +08:00
|
|
|
|
2025-09-09 17:47:20 +08:00
|
|
|
public const int LoadLogCount =100;
|
2025-10-18 17:59:21 +08:00
|
|
|
public DataLoaderService(IMqttManagementService mqttManagementService,
|
|
|
|
|
IMqttAliasManagementService mqttAliasManagementService,
|
|
|
|
|
ITriggerManagementService triggerManagementService, // 添加触发器管理服务参数
|
|
|
|
|
IEventService eventService, // 添加事件服务参数
|
|
|
|
|
IDeviceManagementService deviceManagementService, // 添加设备管理服务参数
|
|
|
|
|
IVariableTableManagementService variableTableManagementService, // 添加变量表管理服务参数
|
|
|
|
|
IVariableManagementService variableManagementService, // 添加变量管理服务参数
|
|
|
|
|
IMenuManagementService menuManagementService, // 添加菜单管理服务参数
|
|
|
|
|
ILogManagementService logManagementService) // 添加日志管理服务参数
|
2025-09-09 13:35:16 +08:00
|
|
|
{
|
2025-10-18 17:59:21 +08:00
|
|
|
_mqttManagementService = mqttManagementService;
|
|
|
|
|
_mqttAliasManagementService = mqttAliasManagementService;
|
2025-09-23 05:48:21 +08:00
|
|
|
_triggerManagementService = triggerManagementService; // 初始化触发器管理服务
|
2025-10-05 11:21:05 +08:00
|
|
|
_eventService = eventService; // 初始化事件服务
|
2025-10-18 17:59:21 +08:00
|
|
|
_deviceManagementService = deviceManagementService; // 初始化设备管理服务
|
|
|
|
|
_variableTableManagementService = variableTableManagementService; // 初始化变量表管理服务
|
|
|
|
|
_variableManagementService = variableManagementService; // 初始化变量管理服务
|
|
|
|
|
_menuManagementService = menuManagementService; // 初始化菜单管理服务
|
|
|
|
|
_logManagementService = logManagementService; // 初始化日志管理服务
|
2025-09-09 13:35:16 +08:00
|
|
|
}
|
|
|
|
|
|
2025-09-09 15:28:07 +08:00
|
|
|
|
2025-09-09 13:35:16 +08:00
|
|
|
/// <summary>
|
|
|
|
|
/// 异步加载所有设备及其关联数据到内存中
|
|
|
|
|
/// </summary>
|
2025-09-09 15:28:07 +08:00
|
|
|
public async Task LoadAllDataToMemoryAsync()
|
2025-09-09 13:35:16 +08:00
|
|
|
{
|
|
|
|
|
|
2025-10-18 17:59:21 +08:00
|
|
|
await _deviceManagementService.LoadAllDevicesAsync();
|
2025-09-09 13:35:16 +08:00
|
|
|
|
2025-10-18 17:59:21 +08:00
|
|
|
await _variableTableManagementService.LoadAllVariableTablesAsync();
|
2025-09-09 13:35:16 +08:00
|
|
|
|
2025-10-18 17:59:21 +08:00
|
|
|
await _variableManagementService.LoadAllVariablesAsync();
|
2025-09-09 13:35:16 +08:00
|
|
|
// 加载所有菜单
|
2025-10-18 17:59:21 +08:00
|
|
|
await _menuManagementService.LoadAllMenusAsync();
|
2025-09-09 13:35:16 +08:00
|
|
|
|
|
|
|
|
// 加载所有MQTT服务器
|
2025-10-18 17:59:21 +08:00
|
|
|
await _mqttManagementService.LoadAllMqttServersAsync();
|
2025-09-09 13:35:16 +08:00
|
|
|
|
|
|
|
|
// 加载所有日志
|
2025-10-18 17:59:21 +08:00
|
|
|
await _logManagementService.LoadAllNlogsAsync(LoadLogCount);
|
2025-09-09 13:35:16 +08:00
|
|
|
|
|
|
|
|
// 获取变量MQTT别名
|
2025-10-11 18:07:01 +08:00
|
|
|
await _mqttAliasManagementService.LoadAllMqttAliasAsync();
|
2025-09-23 05:48:21 +08:00
|
|
|
|
|
|
|
|
// 加载所有触发器
|
2025-10-18 17:59:21 +08:00
|
|
|
await _triggerManagementService.LoadAllTriggersAsync();
|
2025-09-09 17:47:20 +08:00
|
|
|
|
2025-10-05 11:21:05 +08:00
|
|
|
_eventService.RaiseLoadDataCompleted(this, new DataLoadCompletedEventArgs(true, "数据加载成功"));
|
2025-09-09 17:47:20 +08:00
|
|
|
}
|
|
|
|
|
|
2025-09-09 13:35:16 +08:00
|
|
|
}
|