WIP
This commit is contained in:
@@ -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类的构造函数。
|
||||
/// </summary>
|
||||
public DataEventService(IMapper mapper,
|
||||
IDataStorageService dataStorageService,
|
||||
IWpfDataService dataStorageService,
|
||||
IEventService eventService,
|
||||
INotificationService notificationService,
|
||||
IAppCenterService appCenterService,
|
||||
|
||||
@@ -15,16 +15,16 @@ namespace DMS.WPF.Services;
|
||||
/// <summary>
|
||||
/// 设备数据服务类,负责管理设备相关的数据和操作。
|
||||
/// </summary>
|
||||
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
|
||||
/// </summary>
|
||||
/// <param name="mapper">AutoMapper 实例。</param>
|
||||
/// <param name="appCenterService">数据服务中心实例。</param>
|
||||
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
|
||||
/// <summary>
|
||||
/// 添加设备。
|
||||
/// </summary>
|
||||
public async Task<CreateDeviceWithDetailsDto> AddDevice(CreateDeviceWithDetailsDto dto)
|
||||
public async Task<CreateDeviceWithDetailsDto?> 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<DeviceItem>(addDto.Device));
|
||||
@@ -111,8 +108,8 @@ public class DeviceDataService : IDeviceDataService
|
||||
// 给界面添加设备菜单
|
||||
if (addDto.DeviceMenu != null)
|
||||
{
|
||||
await _menuDataService.AddMenuItem(_mapper.Map<MenuItem>(addDto.DeviceMenu));
|
||||
|
||||
_menuDataService.AddMenuToView(_mapper.Map<MenuItem>(addDto.DeviceMenu));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -124,13 +121,13 @@ public class DeviceDataService : IDeviceDataService
|
||||
|
||||
if (addDto.VariableTable != null && addDto.VariableTableMenu != null)
|
||||
{
|
||||
await _menuDataService.AddMenuItem(_mapper.Map<MenuItem>(addDto.VariableTableMenu));
|
||||
_menuDataService.AddMenuToView(_mapper.Map<MenuItem>(addDto.VariableTableMenu));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
return addDto;
|
||||
}
|
||||
@@ -140,28 +137,28 @@ public class DeviceDataService : IDeviceDataService
|
||||
/// </summary>
|
||||
public async Task<bool> 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;
|
||||
}
|
||||
@@ -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
|
||||
/// </summary>
|
||||
/// <param name="mapper">AutoMapper 实例。</param>
|
||||
/// <param name="appStorageService">数据服务中心实例。</param>
|
||||
public LogDataService(IMapper mapper,IDataStorageService dataStorageService, IAppStorageService appStorageService)
|
||||
public LogDataService(IMapper mapper,IWpfDataService dataStorageService, IAppStorageService appStorageService)
|
||||
{
|
||||
_mapper = mapper;
|
||||
_dataStorageService = dataStorageService;
|
||||
|
||||
@@ -13,10 +13,10 @@ namespace DMS.WPF.Services;
|
||||
/// <summary>
|
||||
/// 菜单数据服务类,负责管理菜单相关的数据和操作。
|
||||
/// </summary>
|
||||
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
|
||||
/// </summary>
|
||||
/// <param name="mapper">AutoMapper 实例。</param>
|
||||
/// <param name="appStorageService">数据服务中心实例。</param>
|
||||
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<ObservableCollection<MenuItem>>(_appStorageService.Menus.Values);
|
||||
_wpfDataService.Menus = _mapper.Map<ObservableCollection<MenuItem>>(_appStorageService.Menus.Values);
|
||||
BuildMenuTrees();
|
||||
}
|
||||
|
||||
@@ -46,11 +46,11 @@ public class MenuDataService : IMenuDataService
|
||||
/// </summary>
|
||||
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
|
||||
/// <summary>
|
||||
/// 添加菜单项。
|
||||
/// </summary>
|
||||
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<MenuBean>(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();
|
||||
@@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// 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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
/// <summary>
|
||||
@@ -29,7 +29,7 @@ public class MqttDataService : IMqttDataService
|
||||
/// </summary>
|
||||
/// <param name="mapper">AutoMapper 实例。</param>
|
||||
/// <param name="mqttAppService">MQTT应用服务实例。</param>
|
||||
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<MenuItem>(mqttServerMenu));
|
||||
await _menuDataService.AddMenuToView(_mapper.Map<MenuItem>(mqttServerMenu));
|
||||
}
|
||||
|
||||
return mqttServerItem;
|
||||
|
||||
@@ -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
|
||||
/// <param name="eventService">事件服务实例。</param>
|
||||
/// <param name="notificationService">通知服务实例。</param>
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
/// </summary>
|
||||
/// <param name="mapper">AutoMapper 实例。</param>
|
||||
/// <param name="appCenterService">数据服务中心实例。</param>
|
||||
public VariableDataService(IMapper mapper, IDataStorageService dataStorageService, IAppCenterService appCenterService)
|
||||
public VariableDataService(IMapper mapper, IWpfDataService dataStorageService, IAppCenterService appCenterService)
|
||||
{
|
||||
_mapper = mapper;
|
||||
_dataStorageService = dataStorageService;
|
||||
|
||||
@@ -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<MenuItem>(resDto.Menu));
|
||||
await _menuDataService.AddMenuToView(_mapper.Map<MenuItem>(resDto.Menu));
|
||||
return resDto.VariableTable.Id;
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ public class WPFDataService : IWPFDataService
|
||||
/// <summary>
|
||||
/// 菜单数据服务。
|
||||
/// </summary>
|
||||
public IMenuDataService MenuDataService { get; }
|
||||
public IMenuWpfService MenuDataService { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 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,
|
||||
|
||||
@@ -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
|
||||
/// </summary>
|
||||
public ObservableDictionary<int, TriggerItem> Triggers { get; set; }
|
||||
|
||||
public DataStorageService()
|
||||
public WpfDataService()
|
||||
{
|
||||
Devices=new ObservableDictionary<int,DeviceItem>();
|
||||
VariableTables = new ObservableDictionary<int,VariableTableItem>();
|
||||
Reference in New Issue
Block a user