diff --git a/DMS.Application/Services/Database/DeviceAppService.cs b/DMS.Application/Services/Database/DeviceAppService.cs index 759abc2..5c4fc45 100644 --- a/DMS.Application/Services/Database/DeviceAppService.cs +++ b/DMS.Application/Services/Database/DeviceAppService.cs @@ -5,6 +5,7 @@ using DMS.Application.Interfaces.Database; using DMS.Core.Enums; using DMS.Core.Interfaces; using DMS.Core.Models; +using System.ComponentModel; namespace DMS.Application.Services.Database; @@ -61,59 +62,38 @@ public class DeviceAppService : IDeviceAppService { await _repoManager.BeginTranAsync(); - var addDevice = await _repoManager.Devices.AddAsync(dto.Device); - if (addDevice == null || addDevice.Id == 0) - { - throw new InvalidOperationException($"添加设备失败:{addDevice}"); - } + dto.Device = await _repoManager.Devices.AddAsync(dto.Device); - _mapper.Map(addDevice,dto.Device); - MenuBean addDeviceMenu = null; // 假设有设备菜单 - if (dto.DeviceMenu != null) + if (dto.DeviceMenu is not null) { - var deviceMenu = _mapper.Map(dto.DeviceMenu); - deviceMenu.ParentId = 2; // 假设父菜单ID为2 - deviceMenu.MenuType = MenuType.DeviceMenu; - deviceMenu.TargetId = addDevice.Id; - addDeviceMenu = await _repoManager.Menus.AddAsync(deviceMenu); - if (addDeviceMenu == null || addDeviceMenu.Id == 0) - { - throw new InvalidOperationException($"添加设备菜单失败:{addDeviceMenu}"); - } - _mapper.Map(addDeviceMenu,dto.DeviceMenu); + dto.DeviceMenu = await _repoManager.Menus.AddAsync(dto.DeviceMenu); } // 假设 CreateDeviceWithDetailsDto 包含了变量表和菜单信息 - if (dto.VariableTable != null) + if (dto.VariableTable is not null) { - var variableTable = _mapper.Map(dto.VariableTable); - variableTable.DeviceId = dto.Device.Id; // 关联新设备ID - variableTable.Protocol = dto.Device.Protocol; - var addVariableTable = await _repoManager.VariableTables.AddAsync(variableTable); - if (addVariableTable == null || addVariableTable.Id == 0) + dto.VariableTable.DeviceId = dto.Device.Id; // 关联新设备ID + dto.VariableTable.Protocol = dto.Device.Protocol; + dto.VariableTable = await _repoManager.VariableTables.AddAsync(dto.VariableTable); + if (dto.VariableTable == null || dto.VariableTable.Id == 0) { - throw new InvalidOperationException($"添加设备变量表失败,设备:{dto.Device.Name},变量表:{variableTable.Name}"); + throw new InvalidOperationException($"添加设备变量表失败,设备:{dto.Device.Name},变量表:{dto?.VariableTable?.Name}"); } - _mapper.Map(addVariableTable,dto.VariableTable); - dto.VariableTable.Device = dto.Device; // 假设有设备菜单 - if (dto.VariableTableMenu != null) + if (dto.VariableTableMenu is not null && dto.VariableTableMenu is not null) { - var menu = _mapper.Map(dto.VariableTableMenu); - menu.ParentId = addDeviceMenu.Id; // 关联设备菜单作为父级 - menu.MenuType = MenuType.VariableTableMenu; - menu.TargetId = addVariableTable.Id; - var addVariableTableMenu = await _repoManager.Menus.AddAsync(menu); - if (addVariableTableMenu == null || addVariableTableMenu.Id == 0) + dto.VariableTableMenu.ParentId = dto.DeviceMenu.Id; // 关联设备菜单作为父级 + dto.VariableTableMenu.TargetId = dto.VariableTable.Id; + dto.VariableTableMenu = await _repoManager.Menus.AddAsync(dto.VariableTableMenu); + if (dto.VariableTableMenu == null || dto.VariableTableMenu.Id == 0) { throw new InvalidOperationException( - $"添加设备变量表菜单失败,变量表:{variableTable.Name},变量表菜单:{menu.Header}"); + $"添加设备变量表菜单失败,变量表:{dto.VariableTable.Name},变量表菜单:{dto.VariableTableMenu.Header}"); } - _mapper.Map(menu,dto.VariableTableMenu); } } diff --git a/DMS.WPF/App.xaml.cs b/DMS.WPF/App.xaml.cs index a5f1211..fa6146b 100644 --- a/DMS.WPF/App.xaml.cs +++ b/DMS.WPF/App.xaml.cs @@ -302,16 +302,16 @@ public partial class App : System.Windows.Application services.AddSingleton(); // 注册新的数据服务 - services.AddSingleton(); + services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); - services.AddSingleton(); + services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); // 注册触发器数据服务 services.AddSingleton(); - services.AddSingleton(); + services.AddSingleton(); services.AddSingleton(); // 注册主数据服务 diff --git a/DMS.WPF/Interfaces/IDeviceDataService.cs b/DMS.WPF/Interfaces/IDeviceDataService.cs index fbf6b12..3f209fe 100644 --- a/DMS.WPF/Interfaces/IDeviceDataService.cs +++ b/DMS.WPF/Interfaces/IDeviceDataService.cs @@ -33,4 +33,5 @@ public interface IDeviceDataService /// 更新设备。 /// Task UpdateDevice(DeviceItem device); + Task AddDevice(CreateDeviceWithDetailsDto dto); } \ No newline at end of file diff --git a/DMS.WPF/Interfaces/IMenuDataService.cs b/DMS.WPF/Interfaces/IMenuWpfService.cs similarity index 84% rename from DMS.WPF/Interfaces/IMenuDataService.cs rename to DMS.WPF/Interfaces/IMenuWpfService.cs index cdc9b6d..08de4c3 100644 --- a/DMS.WPF/Interfaces/IMenuDataService.cs +++ b/DMS.WPF/Interfaces/IMenuWpfService.cs @@ -6,14 +6,14 @@ namespace DMS.WPF.Interfaces; /// /// 菜单数据服务接口。 /// -public interface IMenuDataService +public interface IMenuWpfService { /// /// 添加菜单项。 /// - Task AddMenuItem(MenuItem MenuItem); + void AddMenuToView(MenuItem MenuItem); /// /// 删除菜单项。 diff --git a/DMS.WPF/Interfaces/IWPFDataService.cs b/DMS.WPF/Interfaces/IWPFDataService.cs index 9097991..3cc61f2 100644 --- a/DMS.WPF/Interfaces/IWPFDataService.cs +++ b/DMS.WPF/Interfaces/IWPFDataService.cs @@ -24,7 +24,7 @@ public interface IWPFDataService /// /// 菜单数据服务。 /// - IMenuDataService MenuDataService { get; } + IMenuWpfService MenuDataService { get; } /// /// MQTT数据服务。 diff --git a/DMS.WPF/Interfaces/IDataStorageService.cs b/DMS.WPF/Interfaces/IWpfDataService_1.cs similarity index 97% rename from DMS.WPF/Interfaces/IDataStorageService.cs rename to DMS.WPF/Interfaces/IWpfDataService_1.cs index 5cbbd66..f0ae24b 100644 --- a/DMS.WPF/Interfaces/IDataStorageService.cs +++ b/DMS.WPF/Interfaces/IWpfDataService_1.cs @@ -5,7 +5,7 @@ using ObservableCollections; namespace DMS.WPF.Interfaces; -public interface IDataStorageService +public interface IWpfDataService { /// /// 设备列表。 diff --git a/DMS.WPF/Services/DataEventService.cs b/DMS.WPF/Services/DataEventService.cs index 62b409b..1b16a76 100644 --- a/DMS.WPF/Services/DataEventService.cs +++ b/DMS.WPF/Services/DataEventService.cs @@ -21,7 +21,7 @@ namespace DMS.WPF.Services; public class DataEventService : IDataEventService { private readonly IMapper _mapper; - private readonly IDataStorageService _dataStorageService; + private readonly IWpfDataService _dataStorageService; private readonly IEventService _eventService; private readonly INotificationService _notificationService; private readonly IAppCenterService _appCenterService; @@ -32,7 +32,7 @@ public class DataEventService : IDataEventService /// DataEventService类的构造函数。 /// public DataEventService(IMapper mapper, - IDataStorageService dataStorageService, + IWpfDataService dataStorageService, IEventService eventService, INotificationService notificationService, IAppCenterService appCenterService, diff --git a/DMS.WPF/Services/DeviceDataService.cs b/DMS.WPF/Services/DeviceWpfService.cs similarity index 80% rename from DMS.WPF/Services/DeviceDataService.cs rename to DMS.WPF/Services/DeviceWpfService.cs index fc611d8..032ad9a 100644 --- a/DMS.WPF/Services/DeviceDataService.cs +++ b/DMS.WPF/Services/DeviceWpfService.cs @@ -15,16 +15,16 @@ namespace DMS.WPF.Services; /// /// 设备数据服务类,负责管理设备相关的数据和操作。 /// -public class DeviceDataService : IDeviceDataService +public class DeviceWpfService : IDeviceDataService { private readonly IMapper _mapper; private readonly IAppCenterService _appCenterService; private readonly IAppStorageService _appStorageService; - private readonly IDataStorageService _dataStorageService; + private readonly IWpfDataService _dataStorageService; private readonly IVariableTableDataService _variableTableDataService; private readonly IEventService _eventService; private readonly INotificationService _notificationService; - private readonly IMenuDataService _menuDataService; + private readonly IMenuWpfService _menuDataService; private readonly IVariableDataService _variableDataService; private readonly Dispatcher _uiDispatcher; @@ -33,11 +33,12 @@ public class DeviceDataService : IDeviceDataService /// /// AutoMapper 实例。 /// 数据服务中心实例。 - public DeviceDataService(IMapper mapper, IAppCenterService appCenterService, - IAppStorageService appStorageService, IDataStorageService dataStorageService,IVariableTableDataService variableTableDataService, + public DeviceWpfService(IMapper mapper, IAppCenterService appCenterService, + IAppStorageService appStorageService, IWpfDataService dataStorageService, IVariableTableDataService variableTableDataService, IEventService eventService, INotificationService notificationService, - IMenuDataService menuDataService, IVariableDataService variableDataService) + IMenuWpfService menuDataService, IVariableDataService variableDataService) { + _mapper = mapper; _appCenterService = appCenterService; _appStorageService = appStorageService; @@ -91,19 +92,15 @@ public class DeviceDataService : IDeviceDataService /// /// 添加设备。 /// - public async Task AddDevice(CreateDeviceWithDetailsDto dto) + public async Task AddDevice(CreateDeviceWithDetailsDto dto) { // 添加null检查 - if (dto == null) - return null; + if (dto is null) return null; var addDto = await _appCenterService.DeviceManagementService.CreateDeviceWithDetailsAsync(dto); // 添加null检查 - if (addDto == null && addDto.Device == null) - { - return null; - } + if (addDto is null) return null; //给界面添加设备 _dataStorageService.Devices.Add(addDto.Device.Id, _mapper.Map(addDto.Device)); @@ -111,8 +108,8 @@ public class DeviceDataService : IDeviceDataService // 给界面添加设备菜单 if (addDto.DeviceMenu != null) { - await _menuDataService.AddMenuItem(_mapper.Map(addDto.DeviceMenu)); - + _menuDataService.AddMenuToView(_mapper.Map(addDto.DeviceMenu)); + } @@ -124,13 +121,13 @@ public class DeviceDataService : IDeviceDataService if (addDto.VariableTable != null && addDto.VariableTableMenu != null) { - await _menuDataService.AddMenuItem(_mapper.Map(addDto.VariableTableMenu)); + _menuDataService.AddMenuToView(_mapper.Map(addDto.VariableTableMenu)); } } - + return addDto; } @@ -140,28 +137,28 @@ public class DeviceDataService : IDeviceDataService /// public async Task DeleteDevice(DeviceItem device) { - + //从数据库和内存中删除设备相关数据 if (!await _appCenterService.DeviceManagementService.DeleteDeviceByIdAsync(device.Id)) { return false; } - + // 从界面删除设备相关数据集 var variableTablesCopy = device.VariableTables.ToList(); foreach (var variableTable in variableTablesCopy) { - await _variableTableDataService.DeleteVariableTable(variableTable); + await _variableTableDataService.DeleteVariableTable(variableTable); } - var deviceMenu= _dataStorageService.Menus.FirstOrDefault(m => m.MenuType == MenuType.DeviceMenu && m.TargetId == device.Id); + var deviceMenu = _dataStorageService.Menus.FirstOrDefault(m => m.MenuType == MenuType.DeviceMenu && m.TargetId == device.Id); if (deviceMenu != null) { - await _menuDataService.DeleteMenuItem(deviceMenu); + await _menuDataService.DeleteMenuItem(deviceMenu); } _dataStorageService.Devices.Remove(device.Id); - + return true; } diff --git a/DMS.WPF/Services/LogDataService.cs b/DMS.WPF/Services/LogDataService.cs index 3326acd..cb1655f 100644 --- a/DMS.WPF/Services/LogDataService.cs +++ b/DMS.WPF/Services/LogDataService.cs @@ -16,7 +16,7 @@ namespace DMS.WPF.Services; public class LogDataService : ILogDataService { private readonly IMapper _mapper; - private readonly IDataStorageService _dataStorageService; + private readonly IWpfDataService _dataStorageService; private readonly IAppStorageService _appStorageService; @@ -26,7 +26,7 @@ public class LogDataService : ILogDataService /// /// AutoMapper 实例。 /// 数据服务中心实例。 - public LogDataService(IMapper mapper,IDataStorageService dataStorageService, IAppStorageService appStorageService) + public LogDataService(IMapper mapper,IWpfDataService dataStorageService, IAppStorageService appStorageService) { _mapper = mapper; _dataStorageService = dataStorageService; diff --git a/DMS.WPF/Services/MenuDataService.cs b/DMS.WPF/Services/MenuWpfService.cs similarity index 66% rename from DMS.WPF/Services/MenuDataService.cs rename to DMS.WPF/Services/MenuWpfService.cs index 7430f1c..838fd43 100644 --- a/DMS.WPF/Services/MenuDataService.cs +++ b/DMS.WPF/Services/MenuWpfService.cs @@ -13,10 +13,10 @@ namespace DMS.WPF.Services; /// /// 菜单数据服务类,负责管理菜单相关的数据和操作。 /// -public class MenuDataService : IMenuDataService +public class MenuWpfService : IMenuWpfService { private readonly IMapper _mapper; - private readonly IDataStorageService _dataStorageService; + private readonly IWpfDataService _wpfDataService; private readonly IAppStorageService _appStorageService; private readonly IMenuManagementService _menuManagementService; @@ -27,17 +27,17 @@ public class MenuDataService : IMenuDataService /// /// AutoMapper 实例。 /// 数据服务中心实例。 - public MenuDataService(IMapper mapper, IDataStorageService dataStorageService, IAppStorageService appStorageService, IMenuManagementService menuManagementService) + public MenuWpfService(IMapper mapper, IWpfDataService dataStorageService, IAppStorageService appStorageService, IMenuManagementService menuManagementService) { _mapper = mapper; - _dataStorageService = dataStorageService; + _wpfDataService = dataStorageService; _appStorageService = appStorageService; _menuManagementService = menuManagementService; } public void LoadAllMenus() { - _dataStorageService.Menus = _mapper.Map>(_appStorageService.Menus.Values); + _wpfDataService.Menus = _mapper.Map>(_appStorageService.Menus.Values); BuildMenuTrees(); } @@ -46,11 +46,11 @@ public class MenuDataService : IMenuDataService /// public void BuildMenuTrees() { - _dataStorageService.MenuTrees.Clear(); + _wpfDataService.MenuTrees.Clear(); // 遍历所有菜单项,构建树形结构 - foreach (var menu in _dataStorageService.Menus) + foreach (var menu in _wpfDataService.Menus) { - var parentMenu = _dataStorageService.Menus.FirstOrDefault(m => m.Id == menu.ParentId); + var parentMenu = _wpfDataService.Menus.FirstOrDefault(m => m.Id == menu.ParentId); // 检查是否有父ID,并且父ID不为0(通常0或null表示根节点) if (parentMenu != null && menu.ParentId != 0) { @@ -63,7 +63,7 @@ public class MenuDataService : IMenuDataService else { // 如果没有父ID,则这是一个根菜单 - _dataStorageService.MenuTrees.Add(menu); + _wpfDataService.MenuTrees.Add(menu); } } } @@ -71,22 +71,17 @@ public class MenuDataService : IMenuDataService /// /// 添加菜单项。 /// - public async Task AddMenuItem(MenuItem MenuItem) + public void AddMenuToView(MenuItem MenuItem) { if (MenuItem is null) return; - var deviceMenu = _dataStorageService.Menus.FirstOrDefault(m => m.Id == MenuItem.ParentId); + var deviceMenu = _wpfDataService.Menus.FirstOrDefault(m => m.Id == MenuItem.ParentId); if (deviceMenu is not null) { - var menuId = await _menuManagementService.CreateMenuAsync(_mapper.Map(MenuItem)); - if (menuId > 0) - { - MenuItem.Id = menuId; - deviceMenu.Children.Add(MenuItem); - _dataStorageService.Menus.Add(MenuItem); - BuildMenuTrees(); - } + deviceMenu.Children.Add(MenuItem); + _wpfDataService.Menus.Add(MenuItem); + BuildMenuTrees(); } } @@ -98,7 +93,7 @@ public class MenuDataService : IMenuDataService { if (MenuItem is null) return; - var menu = _dataStorageService.Menus.FirstOrDefault(m => m.Id == MenuItem.Id); + var menu = _wpfDataService.Menus.FirstOrDefault(m => m.Id == MenuItem.Id); if (menu is not null) { @@ -122,19 +117,19 @@ public class MenuDataService : IMenuDataService await _menuManagementService.DeleteMenuAsync(MenuItem.Id); // 从扁平菜单列表中移除 - _dataStorageService.Menus.Remove(MenuItem); + _wpfDataService.Menus.Remove(MenuItem); //// 从树形结构中移除 if (MenuItem.ParentId.HasValue && MenuItem.ParentId.Value != 0) { // 如果有父菜单,从父菜单的Children中移除 - var parentMenu = _dataStorageService.Menus.FirstOrDefault(m => m.Id == MenuItem.ParentId.Value); + var parentMenu = _wpfDataService.Menus.FirstOrDefault(m => m.Id == MenuItem.ParentId.Value); parentMenu?.Children.Remove(MenuItem); } else { // 如果是根菜单,从MenuTrees中移除 - _dataStorageService.MenuTrees.Remove(MenuItem); + _wpfDataService.MenuTrees.Remove(MenuItem); } //BuildMenuTrees(); diff --git a/DMS.WPF/Services/MqttAliasDataService.cs b/DMS.WPF/Services/MqttAliasDataService.cs index 69881f6..eb5478a 100644 --- a/DMS.WPF/Services/MqttAliasDataService.cs +++ b/DMS.WPF/Services/MqttAliasDataService.cs @@ -15,7 +15,7 @@ public class MqttAliasDataService : IMqttAliasDataService private readonly IMapper _mapper; private readonly IAppStorageService _appStorageService; private readonly IMqttAliasManagementService _mqttAliasManagementService; - private readonly IDataStorageService _dataStorageService; + private readonly IWpfDataService _dataStorageService; /// /// MqttAliasDataService类的构造函数。 @@ -27,7 +27,7 @@ public class MqttAliasDataService : IMqttAliasDataService public MqttAliasDataService(IMapper mapper, IAppStorageService appStorageService, IMqttAliasManagementService mqttAliasManagementService, - IDataStorageService dataStorageService) + IWpfDataService dataStorageService) { _mapper = mapper; _appStorageService = appStorageService; diff --git a/DMS.WPF/Services/MqttDataService.cs b/DMS.WPF/Services/MqttDataService.cs index 597441f..1fdf49f 100644 --- a/DMS.WPF/Services/MqttDataService.cs +++ b/DMS.WPF/Services/MqttDataService.cs @@ -19,9 +19,9 @@ public class MqttDataService : IMqttDataService private readonly IMapper _mapper; private readonly IAppStorageService _appStorageService; private readonly IMqttManagementService _mqttManagementService; - private readonly IMenuDataService _menuDataService; + private readonly IMenuWpfService _menuDataService; private readonly IMenuManagementService _menuManagementServiceImpl; - private readonly IDataStorageService _dataStorageService; + private readonly IWpfDataService _dataStorageService; /// @@ -29,7 +29,7 @@ public class MqttDataService : IMqttDataService /// /// AutoMapper 实例。 /// MQTT应用服务实例。 - public MqttDataService(IMapper mapper, IAppStorageService appStorageService, IMqttManagementService mqttManagementService, IMenuDataService menuDataService, IMenuManagementService menuManagementServiceImpl, IDataStorageService dataStorageService) + public MqttDataService(IMapper mapper, IAppStorageService appStorageService, IMqttManagementService mqttManagementService, IMenuWpfService menuDataService, IMenuManagementService menuManagementServiceImpl, IWpfDataService dataStorageService) { _mapper = mapper; _appStorageService = appStorageService; @@ -87,7 +87,7 @@ public class MqttDataService : IMqttDataService MenuType = MenuType.MqttServerMenu, TargetViewKey = nameof(MqttServerDetailViewModel), }; - await _menuDataService.AddMenuItem(_mapper.Map(mqttServerMenu)); + await _menuDataService.AddMenuToView(_mapper.Map(mqttServerMenu)); } return mqttServerItem; diff --git a/DMS.WPF/Services/TriggerDataService.cs b/DMS.WPF/Services/TriggerDataService.cs index 921883b..d9d66ee 100644 --- a/DMS.WPF/Services/TriggerDataService.cs +++ b/DMS.WPF/Services/TriggerDataService.cs @@ -24,9 +24,9 @@ public class TriggerDataService : ITriggerDataService { private readonly IMapper _mapper; private readonly IAppCenterService _appCenterService; - private readonly IMenuDataService _menuDataService; + private readonly IMenuWpfService _menuDataService; private readonly IAppStorageService _appStorageService; - private readonly IDataStorageService _dataStorageService; + private readonly IWpfDataService _dataStorageService; private readonly IEventService _eventService; private readonly INotificationService _notificationService; private readonly Dispatcher _uiDispatcher; @@ -41,8 +41,8 @@ public class TriggerDataService : ITriggerDataService /// 事件服务实例。 /// 通知服务实例。 public TriggerDataService(IMapper mapper, IAppCenterService appCenterService, - IMenuDataService menuDataService, - IAppStorageService appStorageService, IDataStorageService dataStorageService, + IMenuWpfService menuDataService, + IAppStorageService appStorageService, IWpfDataService dataStorageService, IEventService eventService, INotificationService notificationService) { _mapper = mapper; @@ -111,7 +111,7 @@ public class TriggerDataService : ITriggerDataService Icon = "\uE945", // 使用触发器图标 TargetViewKey = nameof(TriggerDetailViewModel), }; - await _menuDataService.AddMenuItem(menuItem); + await _menuDataService.AddMenuToView(menuItem); } diff --git a/DMS.WPF/Services/VariableDataService.cs b/DMS.WPF/Services/VariableDataService.cs index 9c23fe0..d5b7017 100644 --- a/DMS.WPF/Services/VariableDataService.cs +++ b/DMS.WPF/Services/VariableDataService.cs @@ -16,7 +16,7 @@ namespace DMS.WPF.Services; public class VariableDataService : IVariableDataService { private readonly IMapper _mapper; - private readonly IDataStorageService _dataStorageService; + private readonly IWpfDataService _dataStorageService; private readonly IAppCenterService _appCenterService; @@ -26,7 +26,7 @@ public class VariableDataService : IVariableDataService /// /// AutoMapper 实例。 /// 数据服务中心实例。 - public VariableDataService(IMapper mapper, IDataStorageService dataStorageService, IAppCenterService appCenterService) + public VariableDataService(IMapper mapper, IWpfDataService dataStorageService, IAppCenterService appCenterService) { _mapper = mapper; _dataStorageService = dataStorageService; diff --git a/DMS.WPF/Services/VariableTableDataService.cs b/DMS.WPF/Services/VariableTableDataService.cs index 3e8a694..942f610 100644 --- a/DMS.WPF/Services/VariableTableDataService.cs +++ b/DMS.WPF/Services/VariableTableDataService.cs @@ -12,14 +12,14 @@ namespace DMS.WPF.Services; public class VariableTableDataService : IVariableTableDataService { private readonly IMapper _mapper; - private readonly IDataStorageService _dataStorageService; + private readonly IWpfDataService _dataStorageService; private readonly IAppCenterService _appCenterService; - private readonly IMenuDataService _menuDataService; + private readonly IMenuWpfService _menuDataService; - public VariableTableDataService(IMapper mapper, IDataStorageService dataStorageService, IAppCenterService appCenterService, - IMenuDataService menuDataService) + public VariableTableDataService(IMapper mapper, IWpfDataService dataStorageService, IAppCenterService appCenterService, + IMenuWpfService menuDataService) { _mapper = mapper; _dataStorageService = dataStorageService; @@ -53,7 +53,7 @@ public class VariableTableDataService : IVariableTableDataService createDto.Menu = menuDto; var resDto = await _appCenterService.VariableTableManagementService.CreateVariableTableAsync(createDto); - await _menuDataService.AddMenuItem(_mapper.Map(resDto.Menu)); + await _menuDataService.AddMenuToView(_mapper.Map(resDto.Menu)); return resDto.VariableTable.Id; } diff --git a/DMS.WPF/Services/WPFDataService.cs b/DMS.WPF/Services/WPFDataService.cs index 1a39d92..c09a20d 100644 --- a/DMS.WPF/Services/WPFDataService.cs +++ b/DMS.WPF/Services/WPFDataService.cs @@ -32,7 +32,7 @@ public class WPFDataService : IWPFDataService /// /// 菜单数据服务。 /// - public IMenuDataService MenuDataService { get; } + public IMenuWpfService MenuDataService { get; } /// /// MQTT数据服务。 @@ -62,7 +62,7 @@ public class WPFDataService : IWPFDataService IAppCenterService appCenterService, IDeviceDataService deviceDataService, IVariableDataService variableDataService, - IMenuDataService menuDataService, + IMenuWpfService menuDataService, IMqttDataService mqttDataService, ILogDataService logDataService, IVariableTableDataService variableTableDataService, diff --git a/DMS.WPF/Services/DataStorageService.cs b/DMS.WPF/Services/WpfDataService_1.cs similarity index 95% rename from DMS.WPF/Services/DataStorageService.cs rename to DMS.WPF/Services/WpfDataService_1.cs index 93a1f04..8232092 100644 --- a/DMS.WPF/Services/DataStorageService.cs +++ b/DMS.WPF/Services/WpfDataService_1.cs @@ -6,7 +6,7 @@ using ObservableCollections; namespace DMS.WPF.Services; -public class DataStorageService : IDataStorageService +public class WpfDataService : IWpfDataService { @@ -56,7 +56,7 @@ public class DataStorageService : IDataStorageService /// public ObservableDictionary Triggers { get; set; } - public DataStorageService() + public WpfDataService() { Devices=new ObservableDictionary(); VariableTables = new ObservableDictionary(); diff --git a/DMS.WPF/ViewModels/DeviceDetailViewModel.cs b/DMS.WPF/ViewModels/DeviceDetailViewModel.cs index 606228e..ee6abd3 100644 --- a/DMS.WPF/ViewModels/DeviceDetailViewModel.cs +++ b/DMS.WPF/ViewModels/DeviceDetailViewModel.cs @@ -20,7 +20,7 @@ public partial class DeviceDetailViewModel : ViewModelBase { private readonly IMapper _mapper; private readonly IDialogService _dialogService; - private readonly IDataStorageService _dataStorageService; + private readonly IWpfDataService _dataStorageService; private readonly INavigationService _navigationService; private readonly IWPFDataService _wpfDataService; @@ -36,7 +36,7 @@ public partial class DeviceDetailViewModel : ViewModelBase private readonly INotificationService _notificationService; - public DeviceDetailViewModel(IMapper mapper, IDialogService dialogService, IDataStorageService dataStorageService, + public DeviceDetailViewModel(IMapper mapper, IDialogService dialogService, IWpfDataService dataStorageService, INavigationService navigationService, IWPFDataService wpfDataService, INotificationService notificationService) { @@ -207,7 +207,7 @@ public partial class DeviceDetailViewModel : ViewModelBase public void NavigateToVariableTable() { if (SelectedVariableTable == null) return; - // var menu = _dataStorageService.Menus.FirstOrDefault(m => m.MenuType == MenuType.VariableTableMenu && + // var menu = _wpfDataService.Menus.FirstOrDefault(m => m.MenuType == MenuType.VariableTableMenu && // m.TargetId == SelectedVariableTable.Id); // if (menu == null) return; _navigationService.NavigateToAsync( diff --git a/DMS.WPF/ViewModels/DevicesViewModel.cs b/DMS.WPF/ViewModels/DevicesViewModel.cs index 76e59de..04fdf8a 100644 --- a/DMS.WPF/ViewModels/DevicesViewModel.cs +++ b/DMS.WPF/ViewModels/DevicesViewModel.cs @@ -24,7 +24,7 @@ public partial class DevicesViewModel : ViewModelBase, INavigatable private readonly IWPFDataService _wpfDataService; private readonly IDeviceAppService _deviceAppService; private readonly IMapper _mapper; - private readonly IDataStorageService _dataStorageService; + private readonly IWpfDataService _dataStorageService; private readonly IDialogService _dialogService; private readonly INavigationService _navigationService; @@ -54,7 +54,7 @@ public partial class DevicesViewModel : ViewModelBase, INavigatable /// 主数据服务。 /// 设备应用服务。 /// 通知服务。 - public DevicesViewModel(IMapper mapper, IDataStorageService dataStorageService, + public DevicesViewModel(IMapper mapper, IWpfDataService dataStorageService, IDialogService dialogService, INavigationService navigationService, IWPFDataService wpfDataService, IDeviceAppService deviceAppService, INotificationService notificationService) diff --git a/DMS.WPF/ViewModels/Dialogs/TriggerDialogViewModel.cs b/DMS.WPF/ViewModels/Dialogs/TriggerDialogViewModel.cs index 2d5365b..aed1ac9 100644 --- a/DMS.WPF/ViewModels/Dialogs/TriggerDialogViewModel.cs +++ b/DMS.WPF/ViewModels/Dialogs/TriggerDialogViewModel.cs @@ -21,7 +21,7 @@ namespace DMS.WPF.ViewModels.Dialogs { private readonly IDialogService _dialogService; - private readonly IDataStorageService _dataStorageService; + private readonly IWpfDataService _dataStorageService; private readonly INotificationService _notificationService; [ObservableProperty] @@ -39,7 +39,7 @@ namespace DMS.WPF.ViewModels.Dialogs public TriggerDialogViewModel( IDialogService dialogService, - IDataStorageService dataStorageService, + IWpfDataService dataStorageService, INotificationService notificationService) { _dialogService = dialogService ?? throw new ArgumentNullException(nameof(dialogService)); diff --git a/DMS.WPF/ViewModels/Dialogs/VariableDialogViewModel.cs b/DMS.WPF/ViewModels/Dialogs/VariableDialogViewModel.cs index ba4d860..f7c9e35 100644 --- a/DMS.WPF/ViewModels/Dialogs/VariableDialogViewModel.cs +++ b/DMS.WPF/ViewModels/Dialogs/VariableDialogViewModel.cs @@ -26,11 +26,11 @@ public partial class VariableDialogViewModel : DialogViewModelBase private bool _hasError; private readonly IWPFDataService _wpfDataService; - private readonly IDataStorageService _dataStorageService; + private readonly IWpfDataService _dataStorageService; private readonly IVariableAppService _variableAppService; private readonly IMapper _mapper; - public VariableDialogViewModel(IWPFDataService wpfDataService,IDataStorageService dataStorageService, IVariableAppService variableAppService, IMapper mapper) + public VariableDialogViewModel(IWPFDataService wpfDataService,IWpfDataService dataStorageService, IVariableAppService variableAppService, IMapper mapper) { Variable = new VariableItem(); diff --git a/DMS.WPF/ViewModels/LogHistoryViewModel.cs b/DMS.WPF/ViewModels/LogHistoryViewModel.cs index 82e641f..f042f47 100644 --- a/DMS.WPF/ViewModels/LogHistoryViewModel.cs +++ b/DMS.WPF/ViewModels/LogHistoryViewModel.cs @@ -28,7 +28,7 @@ partial class LogHistoryViewModel : ViewModelBase,IDisposable private readonly IMapper _mapper; private readonly INlogAppService _nlogAppService; private readonly IDialogService _dialogService; - private readonly IDataStorageService _dataStorageService; + private readonly IWpfDataService _dataStorageService; private readonly INotificationService _notificationService; private readonly IAppCenterService _appCenterService; @@ -50,7 +50,7 @@ partial class LogHistoryViewModel : ViewModelBase,IDisposable public ObservableCollection LogLevels { get; } = new ObservableCollection { "Trace", "Debug", "Info", "Warn", "Error", "Fatal" }; - public LogHistoryViewModel(IMapper mapper, INlogAppService nlogAppService, IDialogService dialogService, IDataStorageService dataStorageService + public LogHistoryViewModel(IMapper mapper, INlogAppService nlogAppService, IDialogService dialogService, IWpfDataService dataStorageService , INotificationService notificationService, IWPFDataService wpfDataService, IAppCenterService appCenterService) { _mapper = mapper; diff --git a/DMS.WPF/ViewModels/MainViewModel.cs b/DMS.WPF/ViewModels/MainViewModel.cs index c2b37e5..38d998b 100644 --- a/DMS.WPF/ViewModels/MainViewModel.cs +++ b/DMS.WPF/ViewModels/MainViewModel.cs @@ -22,7 +22,7 @@ public partial class MainViewModel : ViewModelBase { private readonly IDialogService _dialogService; private readonly IWPFDataService _wpfDataService; - private readonly IDataStorageService _dataStorageService; + private readonly IWpfDataService _dataStorageService; private readonly INavigationService _navigationService; private readonly ILogger _logger; @@ -46,7 +46,7 @@ public partial class MainViewModel : ViewModelBase /// 对话框服务。 /// 日志记录器。 /// - public MainViewModel(IWPFDataService wpfDataService ,IDataStorageService dataStorageService,INavigationService navigationService, + public MainViewModel(IWPFDataService wpfDataService ,IWpfDataService dataStorageService,INavigationService navigationService, ILogger logger) { _wpfDataService = wpfDataService; diff --git a/DMS.WPF/ViewModels/MqttServerDetailViewModel.cs b/DMS.WPF/ViewModels/MqttServerDetailViewModel.cs index 4dc02d9..cc66548 100644 --- a/DMS.WPF/ViewModels/MqttServerDetailViewModel.cs +++ b/DMS.WPF/ViewModels/MqttServerDetailViewModel.cs @@ -26,7 +26,7 @@ namespace DMS.WPF.ViewModels private readonly IMqttManagementService _mqttManagementService; private readonly IMqttAliasDataService _mqttAliasDataService; private readonly IWPFDataService _wpfDataService; - private readonly IDataStorageService _dataStorageService; + private readonly IWpfDataService _dataStorageService; private readonly INavigationService _navigationService; /// @@ -61,7 +61,7 @@ namespace DMS.WPF.ViewModels IMqttManagementService mqttManagementService, IMqttAliasDataService mqttAliasDataService, IWPFDataService wpfDataService, - IDataStorageService dataStorageService, + IWpfDataService dataStorageService, INavigationService navigationService) { _logger = logger; diff --git a/DMS.WPF/ViewModels/MqttsViewModel.cs b/DMS.WPF/ViewModels/MqttsViewModel.cs index 910d7dc..0b29e45 100644 --- a/DMS.WPF/ViewModels/MqttsViewModel.cs +++ b/DMS.WPF/ViewModels/MqttsViewModel.cs @@ -23,7 +23,7 @@ public partial class MqttsViewModel : ViewModelBase { private readonly IWPFDataService _wpfDataService; private readonly IMqttAppService _mqttAppService; - private readonly IDataStorageService _dataStorageService; + private readonly IWpfDataService _dataStorageService; private readonly IMapper _mapper; private readonly IDialogService _dialogService; private readonly INavigationService _navigationService; @@ -49,7 +49,7 @@ public partial class MqttsViewModel : ViewModelBase IDialogService dialogService, IWPFDataService wpfDataService, IMqttAppService mqttAppService, - IDataStorageService dataStorageService, + IWpfDataService dataStorageService, IMapper mapper, INavigationService navigationService, INotificationService notificationService diff --git a/DMS.WPF/ViewModels/TriggerDetailViewModel.cs b/DMS.WPF/ViewModels/TriggerDetailViewModel.cs index d0b7242..3746988 100644 --- a/DMS.WPF/ViewModels/TriggerDetailViewModel.cs +++ b/DMS.WPF/ViewModels/TriggerDetailViewModel.cs @@ -24,7 +24,7 @@ namespace DMS.WPF.ViewModels private readonly INotificationService _notificationService; private readonly ITriggerManagementService _triggerManagementService; private readonly ITriggerDataService _triggerDataService; - private readonly IDataStorageService _dataStorageService; + private readonly IWpfDataService _dataStorageService; private readonly INavigationService _navigationService; /// @@ -52,7 +52,7 @@ namespace DMS.WPF.ViewModels INotificationService notificationService, ITriggerManagementService triggerManagementService, ITriggerDataService triggerDataService, - IDataStorageService dataStorageService, + IWpfDataService dataStorageService, INavigationService navigationService) { _logger = logger; diff --git a/DMS.WPF/ViewModels/TriggersViewModel.cs b/DMS.WPF/ViewModels/TriggersViewModel.cs index c115761..3b6556b 100644 --- a/DMS.WPF/ViewModels/TriggersViewModel.cs +++ b/DMS.WPF/ViewModels/TriggersViewModel.cs @@ -21,7 +21,7 @@ namespace DMS.WPF.ViewModels { private readonly IMapper _mapper; private readonly ITriggerDataService _triggerDataService; - private readonly IDataStorageService _dataStorageService; + private readonly IWpfDataService _dataStorageService; private readonly IDialogService _dialogService; private readonly INotificationService _notificationService; private readonly INavigationService _navigationService; @@ -38,7 +38,7 @@ namespace DMS.WPF.ViewModels public TriggersViewModel( IMapper mapper, ITriggerDataService triggerDataService, - IDataStorageService dataStorageService, + IWpfDataService dataStorageService, IDialogService dialogService, INotificationService notificationService, INavigationService navigationService) diff --git a/DMS.WPF/ViewModels/VariableHistoryViewModel.cs b/DMS.WPF/ViewModels/VariableHistoryViewModel.cs index 82a71f8..9781e2f 100644 --- a/DMS.WPF/ViewModels/VariableHistoryViewModel.cs +++ b/DMS.WPF/ViewModels/VariableHistoryViewModel.cs @@ -27,7 +27,7 @@ partial class VariableHistoryViewModel : ViewModelBase, INavigatable private readonly IDialogService _dialogService; private readonly IHistoryAppService _historyAppService; private readonly IWPFDataService _wpfDataService; - private readonly IDataStorageService _dataStorageService; + private readonly IWpfDataService _dataStorageService; private readonly IEventService _eventService; private readonly INotificationService _notificationService; private readonly INavigationService _navigationService; @@ -85,7 +85,7 @@ partial class VariableHistoryViewModel : ViewModelBase, INavigatable private List _allVariableHistories; public VariableHistoryViewModel(IMapper mapper, IDialogService dialogService, IHistoryAppService historyAppService, - IWPFDataService wpfDataService, IDataStorageService dataStorageService, + IWPFDataService wpfDataService, IWpfDataService dataStorageService, IEventService eventService, INotificationService notificationService, INavigationService navigationService) { diff --git a/DMS.WPF/ViewModels/VariableTableViewModel.cs b/DMS.WPF/ViewModels/VariableTableViewModel.cs index 1d4d48b..f9fa306 100644 --- a/DMS.WPF/ViewModels/VariableTableViewModel.cs +++ b/DMS.WPF/ViewModels/VariableTableViewModel.cs @@ -85,7 +85,7 @@ partial class VariableTableViewModel : ViewModelBase, INavigatable /// 对话服务接口的实例。 private readonly IWPFDataService _wpfDataService; - private readonly IDataStorageService _dataStorageService; + private readonly IWpfDataService _dataStorageService; private readonly ObservableList _variableItemList; private readonly ISynchronizedView _synchronizedView; @@ -99,7 +99,7 @@ partial class VariableTableViewModel : ViewModelBase, INavigatable public VariableTableViewModel(IMapper mapper, IDialogService dialogService, IVariableManagementService variableManagementService, IEventService eventService, IMqttAliasAppService mqttAliasAppService, IMqttAppService mqttAppService, - IWPFDataService wpfDataService, IDataStorageService dataStorageService, + IWPFDataService wpfDataService, IWpfDataService dataStorageService, INotificationService notificationService, ITriggerAppService triggerAppService, ITriggerVariableAppService triggerVariableAppService) {