diff --git a/DMS.Application/Interfaces/IDataCenterService.cs b/DMS.Application/Interfaces/IDataCenterService.cs new file mode 100644 index 0000000..51157c4 --- /dev/null +++ b/DMS.Application/Interfaces/IDataCenterService.cs @@ -0,0 +1,241 @@ +using DMS.Application.DTOs; +using DMS.Core.Models; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace DMS.Application.Interfaces; + +/// +/// 定义数据管理相关的应用服务操作,负责管理所有的数据,包括设备、变量表和变量。 +/// +public interface IDataCenterService +{ + #region 设备管理 + + /// + /// 异步根据ID获取设备DTO。 + /// + Task GetDeviceByIdAsync(int id); + + /// + /// 异步获取所有设备DTO列表。 + /// + Task> GetAllDevicesAsync(); + + /// + /// 异步创建一个新设备及其关联的变量表和菜单(事务性操作)。 + /// + /// 包含设备、变量表和菜单信息的DTO。 + /// 新创建设备的DTO。 + Task CreateDeviceWithDetailsAsync(CreateDeviceWithDetailsDto dto); + + /// + /// 异步更新一个已存在的设备。 + /// + Task UpdateDeviceAsync(DeviceDto deviceDto); + + /// + /// 异步删除一个设备。 + /// + Task DeleteDeviceByIdAsync(int deviceId); + + /// + /// 异步切换设备的激活状态。 + /// + Task ToggleDeviceActiveStateAsync(int id); + + /// + /// 在内存中添加设备 + /// + void AddDeviceToMemory(DeviceDto deviceDto); + + /// + /// 在内存中更新设备 + /// + void UpdateDeviceInMemory(DeviceDto deviceDto); + + /// + /// 在内存中删除设备 + /// + void RemoveDeviceFromMemory(int deviceId); + + #endregion + + #region 变量表管理 + + /// + /// 异步根据ID获取变量表DTO。 + /// + Task GetVariableTableByIdAsync(int id); + + /// + /// 异步获取所有变量表DTO列表。 + /// + Task> GetAllVariableTablesAsync(); + + /// + /// 异步创建一个新变量表及其关联菜单(事务性操作)。 + /// + /// 包含变量表和菜单信息的DTO。 + /// 新创建变量表的DTO。 + Task CreateVariableTableAsync(CreateVariableTableWithMenuDto dto); + + /// + /// 异步更新一个已存在的变量表。 + /// + Task UpdateVariableTableAsync(VariableTableDto variableTableDto); + + /// + /// 异步删除一个变量表。 + /// + Task DeleteVariableTableAsync(int id); + + /// + /// 在内存中添加变量表 + /// + void AddVariableTableToMemory(VariableTableDto variableTableDto); + + /// + /// 在内存中更新变量表 + /// + void UpdateVariableTableInMemory(VariableTableDto variableTableDto); + + /// + /// 在内存中删除变量表 + /// + void RemoveVariableTableFromMemory(int variableTableId); + + #endregion + + #region 变量管理 + + /// + /// 异步根据ID获取变量DTO。 + /// + Task GetVariableByIdAsync(int id); + + /// + /// 异步获取所有变量DTO列表。 + /// + Task> GetAllVariablesAsync(); + + /// + /// 异步创建一个新变量(事务性操作)。 + /// + Task CreateVariableAsync(VariableDto variableDto); + + /// + /// 异步更新一个已存在的变量(事务性操作)。 + /// + Task UpdateVariableAsync(VariableDto variableDto); + + /// + /// 异步批量更新变量(事务性操作)。 + /// + Task UpdateVariablesAsync(List variableDtos); + + /// + /// 异步删除一个变量(事务性操作)。 + /// + Task DeleteVariableAsync(int id); + + /// + /// 异步批量删除变量(事务性操作)。 + /// + Task DeleteVariablesAsync(List ids); + + /// + /// 异步批量导入变量。 + /// + Task BatchImportVariablesAsync(List variables); + + /// + /// 检测一组变量是否已存在。 + /// + /// 要检查的变量列表。 + /// 返回输入列表中已存在的变量。 + Task> FindExistingVariablesAsync(IEnumerable variablesToCheck); + + /// + /// 检测单个变量是否已存在。 + /// + /// 要检查的变量。 + /// 如果变量已存在则返回该变量,否则返回null。 + Task FindExistingVariableAsync(VariableDto variableToCheck); + + /// + /// 在内存中添加变量 + /// + void AddVariableToMemory(VariableDto variableDto); + + /// + /// 在内存中更新变量 + /// + void UpdateVariableInMemory(VariableDto variableDto); + + /// + /// 在内存中删除变量 + /// + void RemoveVariableFromMemory(int variableId); + + /// + /// 批量在内存中添加变量 + /// + void AddVariablesToMemory(List variables); + + /// + /// 批量在内存中更新变量 + /// + void UpdateVariablesInMemory(List variables); + + /// + /// 批量在内存中删除变量 + /// + void RemoveVariablesFromMemory(List variableIds); + + #endregion + + #region 数据存储访问 + + /// + /// 获取所有设备的安全字典。 + /// + ConcurrentDictionary Devices { get; } + + /// + /// 获取所有变量表的安全字典。 + /// + ConcurrentDictionary VariableTables { get; } + + /// + /// 获取所有变量的安全字典。 + /// + ConcurrentDictionary Variables { get; } + + #endregion + + #region 数据加载和初始化 + + /// + /// 异步加载所有设备及其关联数据到内存中。 + /// + Task LoadAllDataToMemoryAsync(); + + /// + /// 异步加载所有设备及其关联数据。 + /// + Task> LoadAllDevicesAsync(); + + /// + /// 异步加载所有变量表及其关联数据。 + /// + Task> LoadAllVariableTablesAsync(); + + /// + /// 异步加载所有变量数据。 + /// + Task> LoadAllVariablesAsync(); + + #endregion +} \ No newline at end of file diff --git a/DMS.Application/Services/DataCenterService.cs b/DMS.Application/Services/DataCenterService.cs new file mode 100644 index 0000000..46c341c --- /dev/null +++ b/DMS.Application/Services/DataCenterService.cs @@ -0,0 +1,490 @@ +using AutoMapper; +using DMS.Application.DTOs; +using DMS.Application.Interfaces; +using DMS.Core.Interfaces; +using DMS.Core.Models; +using DMS.Core.Enums; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Threading.Tasks; +using System; +using System.Linq; + +namespace DMS.Application.Services; + +/// +/// 数据中心服务,负责管理所有的数据,包括设备、变量表和变量。 +/// 实现 接口。 +/// +public class DataCenterService : IDataCenterService +{ + private readonly IRepositoryManager _repositoryManager; + private readonly IMapper _mapper; + private readonly IDeviceAppService _deviceAppService; + private readonly IVariableTableAppService _variableTableAppService; + private readonly IVariableAppService _variableAppService; + + /// + /// 安全字典,用于存储所有设备数据 + /// + public ConcurrentDictionary Devices { get; } = new(); + + /// + /// 安全字典,用于存储所有变量表数据 + /// + public ConcurrentDictionary VariableTables { get; } = new(); + + /// + /// 安全字典,用于存储所有变量数据 + /// + public ConcurrentDictionary Variables { get; } = new(); + + /// + /// 构造函数,通过依赖注入获取仓储管理器和相关服务实例。 + /// + /// 仓储管理器实例。 + /// AutoMapper 实例。 + /// 设备应用服务实例。 + /// 变量表应用服务实例。 + /// 变量应用服务实例。 + public DataCenterService( + IRepositoryManager repositoryManager, + IMapper mapper, + IDeviceAppService deviceAppService, + IVariableTableAppService variableTableAppService, + IVariableAppService variableAppService) + { + _repositoryManager = repositoryManager; + _mapper = mapper; + _deviceAppService = deviceAppService; + _variableTableAppService = variableTableAppService; + _variableAppService = variableAppService; + } + + #region 设备管理 + + /// + /// 异步根据ID获取设备DTO。 + /// + public async Task GetDeviceByIdAsync(int id) + { + return await _deviceAppService.GetDeviceByIdAsync(id); + } + + /// + /// 异步获取所有设备DTO列表。 + /// + public async Task> GetAllDevicesAsync() + { + return await _deviceAppService.GetAllDevicesAsync(); + } + + /// + /// 异步创建一个新设备及其关联的变量表和菜单(事务性操作)。 + /// + public async Task CreateDeviceWithDetailsAsync(CreateDeviceWithDetailsDto dto) + { + return await _deviceAppService.CreateDeviceWithDetailsAsync(dto); + } + + /// + /// 异步更新一个已存在的设备。 + /// + public async Task UpdateDeviceAsync(DeviceDto deviceDto) + { + return await _deviceAppService.UpdateDeviceAsync(deviceDto); + } + + /// + /// 异步删除一个设备。 + /// + public async Task DeleteDeviceByIdAsync(int deviceId) + { + return await _deviceAppService.DeleteDeviceByIdAsync(deviceId); + } + + /// + /// 异步切换设备的激活状态。 + /// + public async Task ToggleDeviceActiveStateAsync(int id) + { + await _deviceAppService.ToggleDeviceActiveStateAsync(id); + } + + /// + /// 在内存中添加设备 + /// + public void AddDeviceToMemory(DeviceDto deviceDto) + { + Devices.TryAdd(deviceDto.Id, deviceDto); + } + + /// + /// 在内存中更新设备 + /// + public void UpdateDeviceInMemory(DeviceDto deviceDto) + { + Devices.AddOrUpdate(deviceDto.Id, deviceDto, (key, oldValue) => deviceDto); + } + + /// + /// 在内存中删除设备 + /// + public void RemoveDeviceFromMemory(int deviceId) + { + Devices.TryRemove(deviceId, out _); + } + + #endregion + + #region 变量表管理 + + /// + /// 异步根据ID获取变量表DTO。 + /// + public async Task GetVariableTableByIdAsync(int id) + { + return await _variableTableAppService.GetVariableTableByIdAsync(id); + } + + /// + /// 异步获取所有变量表DTO列表。 + /// + public async Task> GetAllVariableTablesAsync() + { + return await _variableTableAppService.GetAllVariableTablesAsync(); + } + + /// + /// 异步创建一个新变量表及其关联菜单(事务性操作)。 + /// + public async Task CreateVariableTableAsync(CreateVariableTableWithMenuDto dto) + { + return await _variableTableAppService.CreateVariableTableAsync(dto); + } + + /// + /// 异步更新一个已存在的变量表。 + /// + public async Task UpdateVariableTableAsync(VariableTableDto variableTableDto) + { + return await _variableTableAppService.UpdateVariableTableAsync(variableTableDto); + } + + /// + /// 异步删除一个变量表。 + /// + public async Task DeleteVariableTableAsync(int id) + { + return await _variableTableAppService.DeleteVariableTableAsync(id); + } + + /// + /// 在内存中添加变量表 + /// + public void AddVariableTableToMemory(VariableTableDto variableTableDto) + { + VariableTables.TryAdd(variableTableDto.Id, variableTableDto); + } + + /// + /// 在内存中更新变量表 + /// + public void UpdateVariableTableInMemory(VariableTableDto variableTableDto) + { + VariableTables.AddOrUpdate(variableTableDto.Id, variableTableDto, (key, oldValue) => variableTableDto); + } + + /// + /// 在内存中删除变量表 + /// + public void RemoveVariableTableFromMemory(int variableTableId) + { + VariableTables.TryRemove(variableTableId, out _); + } + + #endregion + + #region 变量管理 + + /// + /// 异步根据ID获取变量DTO。 + /// + public async Task GetVariableByIdAsync(int id) + { + return await _variableAppService.GetVariableByIdAsync(id); + } + + /// + /// 异步获取所有变量DTO列表。 + /// + public async Task> GetAllVariablesAsync() + { + return await _variableAppService.GetAllVariablesAsync(); + } + + /// + /// 异步创建一个新变量(事务性操作)。 + /// + public async Task CreateVariableAsync(VariableDto variableDto) + { + return await _variableAppService.CreateVariableAsync(variableDto); + } + + /// + /// 异步更新一个已存在的变量(事务性操作)。 + /// + public async Task UpdateVariableAsync(VariableDto variableDto) + { + return await _variableAppService.UpdateVariableAsync(variableDto); + } + + /// + /// 异步批量更新变量(事务性操作)。 + /// + public async Task UpdateVariablesAsync(List variableDtos) + { + return await _variableAppService.UpdateVariablesAsync(variableDtos); + } + + /// + /// 异步删除一个变量(事务性操作)。 + /// + public async Task DeleteVariableAsync(int id) + { + return await _variableAppService.DeleteVariableAsync(id); + } + + /// + /// 异步批量删除变量(事务性操作)。 + /// + public async Task DeleteVariablesAsync(List ids) + { + return await _variableAppService.DeleteVariablesAsync(ids); + } + + /// + /// 异步批量导入变量。 + /// + public async Task BatchImportVariablesAsync(List variables) + { + return await _variableAppService.BatchImportVariablesAsync(variables); + } + + /// + /// 检测一组变量是否已存在。 + /// + public async Task> FindExistingVariablesAsync(IEnumerable variablesToCheck) + { + return await _variableAppService.FindExistingVariablesAsync(variablesToCheck); + } + + /// + /// 检测单个变量是否已存在。 + /// + public async Task FindExistingVariableAsync(VariableDto variableToCheck) + { + return await _variableAppService.FindExistingVariableAsync(variableToCheck); + } + + /// + /// 在内存中添加变量 + /// + public void AddVariableToMemory(VariableDto variableDto) + { + Variables.TryAdd(variableDto.Id, variableDto); + } + + /// + /// 在内存中更新变量 + /// + public void UpdateVariableInMemory(VariableDto variableDto) + { + Variables.AddOrUpdate(variableDto.Id, variableDto, (key, oldValue) => variableDto); + } + + /// + /// 在内存中删除变量 + /// + public void RemoveVariableFromMemory(int variableId) + { + Variables.TryRemove(variableId, out _); + } + + /// + /// 批量在内存中添加变量 + /// + public void AddVariablesToMemory(List variables) + { + foreach (var variable in variables) + { + Variables.TryAdd(variable.Id, variable); + } + } + + /// + /// 批量在内存中更新变量 + /// + public void UpdateVariablesInMemory(List variables) + { + foreach (var variable in variables) + { + Variables.AddOrUpdate(variable.Id, variable, (key, oldValue) => variable); + } + } + + /// + /// 批量在内存中删除变量 + /// + public void RemoveVariablesFromMemory(List variableIds) + { + foreach (var variableId in variableIds) + { + Variables.TryRemove(variableId, out _); + } + } + + #endregion + + #region 数据加载和初始化 + + /// + /// 异步加载所有设备及其关联数据到内存中。 + /// + public async Task LoadAllDataToMemoryAsync() + { + try + { + // 清空现有数据 + Devices.Clear(); + VariableTables.Clear(); + Variables.Clear(); + + // 加载所有设备 + var devices = await _repositoryManager.Devices.GetAllAsync(); + var deviceDtos = _mapper.Map>(devices); + + // 加载所有变量表 + var variableTables = await _repositoryManager.VariableTables.GetAllAsync(); + var variableTableDtos = _mapper.Map>(variableTables); + + // 加载所有变量 + var variables = await _repositoryManager.Variables.GetAllAsync(); + var variableDtos = _mapper.Map>(variables); + + // 建立设备与变量表的关联 + foreach (var deviceDto in deviceDtos) + { + deviceDto.VariableTables = variableTableDtos + .Where(vt => vt.DeviceId == deviceDto.Id) + .ToList(); + + // 将设备添加到安全字典 + Devices.TryAdd(deviceDto.Id, deviceDto); + } + + // 建立变量表与变量的关联 + foreach (var variableTableDto in variableTableDtos) + { + variableTableDto.Variables = variableDtos + .Where(v => v.VariableTableId == variableTableDto.Id) + .ToList(); + + // 将变量表添加到安全字典 + VariableTables.TryAdd(variableTableDto.Id, variableTableDto); + } + + // 将变量添加到安全字典 + foreach (var variableDto in variableDtos) + { + Variables.TryAdd(variableDto.Id, variableDto); + } + } + catch (Exception ex) + { + throw new ApplicationException($"加载所有数据到内存时发生错误,错误信息:{ex.Message}", ex); + } + } + + /// + /// 异步加载所有设备及其关联数据。 + /// + public async Task> LoadAllDevicesAsync() + { + try + { + // 获取所有设备 + var devices = await _repositoryManager.Devices.GetAllAsync(); + var deviceDtos = _mapper.Map>(devices); + + // 为每个设备加载关联的变量表和变量 + foreach (var deviceDto in deviceDtos) + { + // 获取设备的所有变量表 + var variableTables = await _repositoryManager.VariableTables.GetAllAsync(); + var deviceVariableTables = variableTables.Where(vt => vt.DeviceId == deviceDto.Id).ToList(); + deviceDto.VariableTables = _mapper.Map>(deviceVariableTables); + + // 为每个变量表加载关联的变量 + foreach (var variableTableDto in deviceDto.VariableTables) + { + var variables = await _repositoryManager.Variables.GetAllAsync(); + var tableVariables = variables.Where(v => v.VariableTableId == variableTableDto.Id).ToList(); + variableTableDto.Variables = _mapper.Map>(tableVariables); + } + } + + return deviceDtos; + } + catch (Exception ex) + { + throw new ApplicationException($"加载所有设备数据时发生错误,错误信息:{ex.Message}", ex); + } + } + + /// + /// 异步加载所有变量表及其关联数据。 + /// + public async Task> LoadAllVariableTablesAsync() + { + try + { + // 获取所有变量表 + var variableTables = await _repositoryManager.VariableTables.GetAllAsync(); + var variableTableDtos = _mapper.Map>(variableTables); + + // 为每个变量表加载关联的变量 + foreach (var variableTableDto in variableTableDtos) + { + var variables = await _repositoryManager.Variables.GetAllAsync(); + var tableVariables = variables.Where(v => v.VariableTableId == variableTableDto.Id).ToList(); + variableTableDto.Variables = _mapper.Map>(tableVariables); + } + + return variableTableDtos; + } + catch (Exception ex) + { + throw new ApplicationException($"加载所有变量表数据时发生错误,错误信息:{ex.Message}", ex); + } + } + + /// + /// 异步加载所有变量数据。 + /// + public async Task> LoadAllVariablesAsync() + { + try + { + // 获取所有变量 + var variables = await _repositoryManager.Variables.GetAllAsync(); + return _mapper.Map>(variables); + } + catch (Exception ex) + { + throw new ApplicationException($"加载所有变量数据时发生错误,错误信息:{ex.Message}", ex); + } + } + + #endregion +} \ No newline at end of file diff --git a/DMS.Infrastructure.UnitTests/DataCenterServiceTests.cs b/DMS.Infrastructure.UnitTests/DataCenterServiceTests.cs new file mode 100644 index 0000000..75cbf7f --- /dev/null +++ b/DMS.Infrastructure.UnitTests/DataCenterServiceTests.cs @@ -0,0 +1,143 @@ +using DMS.Application.DTOs; +using DMS.Application.Interfaces; +using DMS.Application.Services; +using DMS.Core.Interfaces; +using Moq; +using System.Collections.Concurrent; +using Xunit; + +namespace DMS.Infrastructure.UnitTests +{ + public class DataCenterServiceTests + { + [Fact] + public void DataCenterService_Should_Implement_All_Required_Methods() + { + // Arrange + var mockRepositoryManager = new Mock(); + var mockMapper = new Mock(); + var mockDeviceAppService = new Mock(); + var mockVariableTableAppService = new Mock(); + var mockVariableAppService = new Mock(); + + // Act + var dataCenterService = new DataCenterService( + mockRepositoryManager.Object, + mockMapper.Object, + mockDeviceAppService.Object, + mockVariableTableAppService.Object, + mockVariableAppService.Object); + + // Assert - Verify that service implements the interface + Assert.IsAssignableFrom(dataCenterService); + } + + [Fact] + public void DataCenterService_Should_Have_ConcurrentDictionary_Properties() + { + // Arrange + var mockRepositoryManager = new Mock(); + var mockMapper = new Mock(); + var mockDeviceAppService = new Mock(); + var mockVariableTableAppService = new Mock(); + var mockVariableAppService = new Mock(); + + // Act + var dataCenterService = new DataCenterService( + mockRepositoryManager.Object, + mockMapper.Object, + mockDeviceAppService.Object, + mockVariableTableAppService.Object, + mockVariableAppService.Object); + + // Assert + Assert.NotNull(dataCenterService.Devices); + Assert.NotNull(dataCenterService.VariableTables); + Assert.NotNull(dataCenterService.Variables); + Assert.IsType>(dataCenterService.Devices); + Assert.IsType>(dataCenterService.VariableTables); + Assert.IsType>(dataCenterService.Variables); + } + + [Fact] + public void DataCenterService_AddDeviceToMemory_Should_Add_Device_To_Dictionary() + { + // Arrange + var mockRepositoryManager = new Mock(); + var mockMapper = new Mock(); + var mockDeviceAppService = new Mock(); + var mockVariableTableAppService = new Mock(); + var mockVariableAppService = new Mock(); + var dataCenterService = new DataCenterService( + mockRepositoryManager.Object, + mockMapper.Object, + mockDeviceAppService.Object, + mockVariableTableAppService.Object, + mockVariableAppService.Object); + + var deviceDto = new DeviceDto { Id = 1, Name = "Test Device" }; + + // Act + dataCenterService.AddDeviceToMemory(deviceDto); + + // Assert + Assert.True(dataCenterService.Devices.ContainsKey(1)); + Assert.Equal(deviceDto, dataCenterService.Devices[1]); + } + + [Fact] + public void DataCenterService_UpdateDeviceInMemory_Should_Update_Device_In_Dictionary() + { + // Arrange + var mockRepositoryManager = new Mock(); + var mockMapper = new Mock(); + var mockDeviceAppService = new Mock(); + var mockVariableTableAppService = new Mock(); + var mockVariableAppService = new Mock(); + var dataCenterService = new DataCenterService( + mockRepositoryManager.Object, + mockMapper.Object, + mockDeviceAppService.Object, + mockVariableTableAppService.Object, + mockVariableAppService.Object); + + var deviceDto = new DeviceDto { Id = 1, Name = "Test Device" }; + var updatedDeviceDto = new DeviceDto { Id = 1, Name = "Updated Device" }; + + // Act + dataCenterService.AddDeviceToMemory(deviceDto); + dataCenterService.UpdateDeviceInMemory(updatedDeviceDto); + + // Assert + Assert.True(dataCenterService.Devices.ContainsKey(1)); + Assert.Equal(updatedDeviceDto, dataCenterService.Devices[1]); + Assert.Equal("Updated Device", dataCenterService.Devices[1].Name); + } + + [Fact] + public void DataCenterService_RemoveDeviceFromMemory_Should_Remove_Device_From_Dictionary() + { + // Arrange + var mockRepositoryManager = new Mock(); + var mockMapper = new Mock(); + var mockDeviceAppService = new Mock(); + var mockVariableTableAppService = new Mock(); + var mockVariableAppService = new Mock(); + var dataCenterService = new DataCenterService( + mockRepositoryManager.Object, + mockMapper.Object, + mockDeviceAppService.Object, + mockVariableTableAppService.Object, + mockVariableAppService.Object); + + var deviceDto = new DeviceDto { Id = 1, Name = "Test Device" }; + + // Act + dataCenterService.AddDeviceToMemory(deviceDto); + dataCenterService.RemoveDeviceFromMemory(1); + + // Assert + Assert.False(dataCenterService.Devices.ContainsKey(1)); + } + } +} \ No newline at end of file diff --git a/DMS.Infrastructure/Services/OpcUaBackgroundService.cs b/DMS.Infrastructure/Services/OpcUaBackgroundService.cs index 87da528..ae60d6f 100644 --- a/DMS.Infrastructure/Services/OpcUaBackgroundService.cs +++ b/DMS.Infrastructure/Services/OpcUaBackgroundService.cs @@ -64,7 +64,7 @@ public class OpcUaBackgroundService : BackgroundService { PollLevelType.ThirtyMinutes, TimeSpan.FromMilliseconds((int)PollLevelType.ThirtyMinutes) } }; - public OpcUaBackgroundService(IDeviceDataService deviceDataService, IDataProcessingService dataProcessingService, ILogger logger) + public OpcUaBackgroundService(IDeviceDataService deviceDataService, IDataCenterService dataCenterService, IDataProcessingService dataProcessingService, ILogger logger) { _deviceDataService = deviceDataService; _dataProcessingService = dataProcessingService; diff --git a/DMS.WPF/App.xaml.cs b/DMS.WPF/App.xaml.cs index 21724e5..1bceb16 100644 --- a/DMS.WPF/App.xaml.cs +++ b/DMS.WPF/App.xaml.cs @@ -167,6 +167,7 @@ public partial class App : System.Windows.Application services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); + services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); diff --git a/DMS.WPF/ViewModels/SplashViewModel.cs b/DMS.WPF/ViewModels/SplashViewModel.cs index 8ba5137..7c2bc15 100644 --- a/DMS.WPF/ViewModels/SplashViewModel.cs +++ b/DMS.WPF/ViewModels/SplashViewModel.cs @@ -18,15 +18,17 @@ public partial class SplashViewModel : ObservableObject { private readonly IServiceProvider _serviceProvider; private readonly IInitializeService _initializeService; + private readonly IDataCenterService _dataCenterService; private readonly DataServices _dataServices; [ObservableProperty] private string _loadingMessage = "正在加载..."; - public SplashViewModel(IServiceProvider serviceProvider, IInitializeService initializeService,DataServices dataServices) + public SplashViewModel(IServiceProvider serviceProvider, IInitializeService initializeService,IDataCenterService dataCenterService, DataServices dataServices) { _serviceProvider = serviceProvider; _initializeService = initializeService; + this._dataCenterService = dataCenterService; _dataServices = dataServices; } @@ -46,7 +48,9 @@ public partial class SplashViewModel : ObservableObject await _dataServices.LoadVariableTables(); await _dataServices.LoadVariables(); await _dataServices.LoadMenus(); - + + await _dataCenterService.LoadAllDataToMemoryAsync(); + _dataServices.AssociateVariableTablesToDevices(); _dataServices.AssociateVariablesToVariableTables(); diff --git a/DMS.sln b/DMS.sln index b62cc28..0562014 100644 --- a/DMS.sln +++ b/DMS.sln @@ -24,8 +24,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DMS.Infrastructure.UnitTest EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DMS.WPF.UnitTests", "DMS.WPF.UnitTests\DMS.WPF.UnitTests.csproj", "{C15E6B39-211C-417A-BC3F-551AD17C8905}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpcUaTestApp", "OpcUaTestApp\OpcUaTestApp.csproj", "{FD58DDF1-340B-4946-28B7-5B905832858E}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -56,10 +54,6 @@ Global {C15E6B39-211C-417A-BC3F-551AD17C8905}.Debug|Any CPU.Build.0 = Debug|Any CPU {C15E6B39-211C-417A-BC3F-551AD17C8905}.Release|Any CPU.ActiveCfg = Release|Any CPU {C15E6B39-211C-417A-BC3F-551AD17C8905}.Release|Any CPU.Build.0 = Release|Any CPU - {FD58DDF1-340B-4946-28B7-5B905832858E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {FD58DDF1-340B-4946-28B7-5B905832858E}.Debug|Any CPU.Build.0 = Debug|Any CPU - {FD58DDF1-340B-4946-28B7-5B905832858E}.Release|Any CPU.ActiveCfg = Release|Any CPU - {FD58DDF1-340B-4946-28B7-5B905832858E}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE