diff --git a/DMS.Application/Interfaces/Database/IMenuAppService.cs b/DMS.Application/Interfaces/Database/IMenuAppService.cs
index 42e8ffb..a3cb332 100644
--- a/DMS.Application/Interfaces/Database/IMenuAppService.cs
+++ b/DMS.Application/Interfaces/Database/IMenuAppService.cs
@@ -20,16 +20,16 @@ public interface IMenuAppService
///
/// 异步创建一个新菜单。
///
- Task CreateMenuAsync(MenuBean menu);
+ Task AddAsync(MenuBean menu);
///
/// 异步更新一个已存在的菜单。
///
- Task UpdateMenuAsync(MenuBean menu);
+ Task UpdateAsync(MenuBean menu);
///
/// 异步删除一个菜单。
///
- Task DeleteMenuAsync(int id);
+ Task DeleteAsync(MenuBean menu);
}
\ No newline at end of file
diff --git a/DMS.Application/Interfaces/Database/IVariableAppService.cs b/DMS.Application/Interfaces/Database/IVariableAppService.cs
index 96e23ac..86a5abb 100644
--- a/DMS.Application/Interfaces/Database/IVariableAppService.cs
+++ b/DMS.Application/Interfaces/Database/IVariableAppService.cs
@@ -13,15 +13,6 @@ public interface IVariableAppService
///
Task GetVariableByIdAsync(int id);
- ///
- /// 异步根据OPC UA NodeId获取变量DTO。
- ///
- Task GetVariableByOpcUaNodeIdAsync(string opcUaNodeId);
-
- ///
- /// 异步根据OPC UA NodeId列表获取变量DTO列表。
- ///
- Task> GetVariableByOpcUaNodeIdsAsync(List opcUaNodeIds);
///
/// 异步获取所有变量DTO列表。
@@ -31,44 +22,32 @@ public interface IVariableAppService
///
/// 异步创建一个新变量。
///
- Task CreateVariableAsync(Variable variable);
+ Task AddAsync(Variable variable);
///
/// 异步更新一个已存在的变量。
///
- Task UpdateVariableAsync(Variable variable);
+ Task UpdateAsync(Variable variable);
///
/// 异步更新一个已存在的变量。
///
- Task UpdateVariablesAsync(List variables);
+ Task UpdateAsync(List variables);
///
/// 异步删除一个变量。
///
- Task DeleteVariableAsync(int id);
+ Task DeleteAsync(Variable variable);
///
/// 异步批量删除变量。
///
- Task DeleteVariablesAsync(List ids);
+ Task DeleteAsync(List variables);
///
/// 异步批量导入变量。
///
- Task> BatchImportVariablesAsync(List variables);
+ Task> AddAsync(List variables);
- ///
- /// 检测一组变量是否已存在。
- ///
- /// 要检查的变量列表。
- /// 返回输入列表中已存在的变量。
- Task> FindExistingVariablesAsync(IEnumerable variablesToCheck);
- ///
- /// 检测单个变量是否已存在。
- ///
- /// 要检查的变量。
- /// 如果变量已存在则返回该变量,否则返回null。
- Task FindExistingVariableAsync(Variable variableToCheck);
}
\ No newline at end of file
diff --git a/DMS.Application/Interfaces/IAppStorageService.cs b/DMS.Application/Interfaces/IAppDataService.cs
similarity index 97%
rename from DMS.Application/Interfaces/IAppStorageService.cs
rename to DMS.Application/Interfaces/IAppDataService.cs
index 34d50bb..807f128 100644
--- a/DMS.Application/Interfaces/IAppStorageService.cs
+++ b/DMS.Application/Interfaces/IAppDataService.cs
@@ -5,7 +5,7 @@ using DMS.Core.Models.Triggers;
namespace DMS.Application.Interfaces;
-public interface IAppStorageService
+public interface IAppDataService
{
///
/// 安全字典,用于存储所有设备数据
diff --git a/DMS.Application/Interfaces/Management/IMenuManagementService.cs b/DMS.Application/Interfaces/Management/IMenuManagementService.cs
index e344956..32bef0f 100644
--- a/DMS.Application/Interfaces/Management/IMenuManagementService.cs
+++ b/DMS.Application/Interfaces/Management/IMenuManagementService.cs
@@ -17,34 +17,22 @@ public interface IMenuManagementService
///
/// 异步创建一个新菜单。
///
- Task CreateMenuAsync(MenuBean menu);
+ Task AddAsync(MenuBean menu);
///
/// 异步更新一个已存在的菜单。
///
- Task UpdateMenuAsync(MenuBean menu);
+ Task UpdateAsync(MenuBean menu);
///
/// 异步删除一个菜单。
///
- Task DeleteMenuAsync(int id);
-
- ///
- /// 获取根菜单列表
- ///
- List GetRootMenus();
-
- ///
- /// 根据父级ID获取子菜单列表
- ///
- /// 父级菜单ID
- /// 子菜单列表
- List GetChildMenus(int parentId);
+ Task DeleteAsync(MenuBean menu);
///
/// 构建菜单树结构
///
- void BuildMenuTree();
+ void BuildMenuTrees();
///
/// 当菜单数据发生变化时触发
diff --git a/DMS.Application/Interfaces/Management/IVariableManagementService.cs b/DMS.Application/Interfaces/Management/IVariableManagementService.cs
index beb6a51..e16daed 100644
--- a/DMS.Application/Interfaces/Management/IVariableManagementService.cs
+++ b/DMS.Application/Interfaces/Management/IVariableManagementService.cs
@@ -34,22 +34,18 @@ public interface IVariableManagementService
///
/// 异步删除一个变量。
///
- Task DeleteVariableAsync(int id);
+ Task DeleteAsync(Variable variable);
///
/// 异步批量删除变量。
///
- Task DeleteVariablesAsync(List ids);
+ Task DeleteAsync(List variables);
///
/// 异步批量导入变量。
///
- Task> BatchImportVariablesAsync(List variables);
+ Task> AddAsync(List variables);
- ///
- /// 查找已存在的变量。
- ///
- Task> FindExistingVariablesAsync(IEnumerable variablesToCheck);
///
/// 异步加载所有变量数据到内存中。
diff --git a/DMS.Application/Services/AppStorageService.cs b/DMS.Application/Services/AppDataService.cs
similarity index 92%
rename from DMS.Application/Services/AppStorageService.cs
rename to DMS.Application/Services/AppDataService.cs
index f7f8ff5..2261026 100644
--- a/DMS.Application/Services/AppStorageService.cs
+++ b/DMS.Application/Services/AppDataService.cs
@@ -6,12 +6,12 @@ using DMS.Core.Models.Triggers;
namespace DMS.Application.Services;
-public class AppStorageService : IAppStorageService
+public class AppDataService : IAppDataService
{
///
/// 安全字典,用于存储所有设备数据
///
- public ConcurrentDictionary Devices { get; } = new();
+ public ConcurrentDictionary Devices { get; } = new();
///
/// 安全字典,用于存储所有变量表数据
///
@@ -36,15 +36,15 @@ public class AppStorageService : IAppStorageService
/// 安全字典,用于存储所有MQTT服务器数据
///
public ConcurrentDictionary MqttServers { get; } = new();
-
-
+
+
///
/// 安全字典,用于存储所有MQTT变量别名的数据
///
public ConcurrentDictionary MqttAliases { get; } = new();
-
-
-
+
+
+
///
/// 安全字典,用于存储所有历史记录
///
@@ -54,7 +54,7 @@ public class AppStorageService : IAppStorageService
/// 安全字典,用于存储所有日志数据
///
public ConcurrentDictionary Nlogs { get; } = new();
-
+
///
/// 安全字典,用于存储所有触发器定义数据
///
diff --git a/DMS.Application/Services/Database/DeviceAppService.cs b/DMS.Application/Services/Database/DeviceAppService.cs
index 02fc376..ac6fbce 100644
--- a/DMS.Application/Services/Database/DeviceAppService.cs
+++ b/DMS.Application/Services/Database/DeviceAppService.cs
@@ -16,6 +16,7 @@ namespace DMS.Application.Services.Database;
public class DeviceAppService : IDeviceAppService
{
private readonly IRepositoryManager _repoManager;
+ private readonly IAppDataService _appDataService;
private readonly IMapper _mapper;
///
@@ -23,9 +24,10 @@ public class DeviceAppService : IDeviceAppService
///
/// 仓储管理器实例。
/// AutoMapper 实例。
- public DeviceAppService(IRepositoryManager repoManager, IMapper mapper)
+ public DeviceAppService(IRepositoryManager repoManager, IAppDataService appStorageService, IMapper mapper)
{
_repoManager = repoManager;
+ _appDataService = appStorageService;
_mapper = mapper;
}
@@ -39,7 +41,6 @@ public class DeviceAppService : IDeviceAppService
var device = await _repoManager.Devices.GetByIdAsync(id);
return device;
}
-
///
/// 异步获取所有设备数据传输对象列表。
///
@@ -86,7 +87,6 @@ public class DeviceAppService : IDeviceAppService
$"添加设备变量表失败,设备:{dto.Device.Name},变量表:{dto?.VariableTable?.Name}");
}
- dto.VariableTable.Device = dto.Device;
// 假设有设备菜单
if (dto.VariableTableMenu is not null && dto.VariableTableMenu is not null)
@@ -94,11 +94,6 @@ public class DeviceAppService : IDeviceAppService
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(
- $"添加设备变量表菜单失败,变量表:{dto.VariableTable.Name},变量表菜单:{dto.VariableTableMenu.Header}");
- }
}
}
@@ -123,16 +118,10 @@ public class DeviceAppService : IDeviceAppService
public async Task UpdateDeviceAsync(Device device)
{
await _repoManager.BeginTranAsync();
- var existingDevice = await _repoManager.Devices.GetByIdAsync(device.Id);
- if (existingDevice == null)
- {
- throw new ApplicationException($"Device with ID {device.Id} not found.");
- }
-
- _mapper.Map(device, existingDevice);
- int res = await _repoManager.Devices.UpdateAsync(existingDevice);
- var menu = await _repoManager.Menus.GetMenuByTargetIdAsync(MenuType.DeviceMenu, device.Id);
- if (menu != null)
+ int res = await _repoManager.Devices.UpdateAsync(device);
+ //获取到设备对应的菜单
+ var menu = _appDataService.Menus.Values.FirstOrDefault(m => m.MenuType == MenuType.DeviceMenu && m.TargetId == device.Id);
+ if (menu is not null && menu.Header!=device.Name)
{
menu.Header = device.Name;
await _repoManager.Menus.UpdateAsync(menu);
@@ -156,19 +145,17 @@ public class DeviceAppService : IDeviceAppService
{
await _repoManager.BeginTranAsync();
var delRes = await _repoManager.Devices.DeleteAsync(device);
- if (delRes == 0)
- {
- throw new InvalidOperationException($"删除设备失败:设备ID:{device.Id},请检查设备Id是否存在");
- }
-// 删除关联的变量
- await _repoManager.Variables.DeleteByVariableTableIdAsync(device.Id);
// 删除关联的变量表
await _repoManager.VariableTables.DeleteAsync(device.VariableTables);
-
- // 删除关联的菜单树
- await _repoManager.Menus.DeleteMenuTreeByTargetIdAsync(MenuType.DeviceMenu, device.Id);
+ var menu= _appDataService.Menus.Values.FirstOrDefault(m => m.MenuType == MenuType.DeviceMenu && m.TargetId == device.Id);
+ if (menu is not null)
+ {
+ // 删除关联的菜单树
+ await _repoManager.Menus.DeleteAsync(menu);
+ }
+
await _repoManager.CommitAsync();
return true;
diff --git a/DMS.Application/Services/Database/MenuAppService.cs b/DMS.Application/Services/Database/MenuAppService.cs
index c92778f..120dc10 100644
--- a/DMS.Application/Services/Database/MenuAppService.cs
+++ b/DMS.Application/Services/Database/MenuAppService.cs
@@ -1,8 +1,7 @@
using AutoMapper;
+using DMS.Application.Interfaces;
using DMS.Core.Interfaces;
using DMS.Core.Models;
-using DMS.Application.Interfaces.Database;
-using DMS.Application.Interfaces;
namespace DMS.Application.Services.Database;
@@ -53,20 +52,9 @@ public class MenuAppService : IMenuAppService
/// 要创建的菜单。
/// 新创建菜单的ID。
/// 如果创建菜单时发生错误。
- public async Task CreateMenuAsync(MenuBean menu)
+ public async Task AddAsync(MenuBean menu)
{
- try
- {
- await _repoManager.BeginTranAsync();
- await _repoManager.Menus.AddAsync(menu);
- await _repoManager.CommitAsync();
- return menu.Id;
- }
- catch (Exception ex)
- {
- await _repoManager.RollbackAsync();
- throw new ApplicationException("创建菜单时发生错误,操作已回滚。", ex);
- }
+ return await _repoManager.Menus.AddAsync(menu);
}
///
@@ -75,57 +63,20 @@ public class MenuAppService : IMenuAppService
/// 要更新的菜单。
/// 受影响的行数。
/// 如果找不到菜单或更新菜单时发生错误。
- public async Task UpdateMenuAsync(MenuBean menu)
+ public async Task UpdateAsync(MenuBean menu)
{
- try
- {
- await _repoManager.BeginTranAsync();
- var dbmenu = await _repoManager.Menus.GetByIdAsync(menu.Id);
- if (dbmenu == null)
- {
- throw new ApplicationException($"Menu with ID {menu.Id} not found.");
- }
- _mapper.Map(menu, dbmenu);
- int res = await _repoManager.Menus.UpdateAsync(dbmenu);
- await _repoManager.CommitAsync();
- return res;
- }
- catch (Exception ex)
- {
- await _repoManager.RollbackAsync();
- throw new ApplicationException("更新菜单时发生错误,操作已回滚。", ex);
- }
+ return await _repoManager.Menus.UpdateAsync(menu);
}
///
/// 异步删除一个菜单(事务性操作)。
///
- /// 要删除菜单的ID。
/// 如果删除成功则为 true,否则为 false。
/// 如果删除菜单失败。
/// 如果删除菜单时发生其他错误。
- public async Task DeleteMenuAsync(int id)
+ public async Task DeleteAsync(MenuBean menu)
{
- try
- {
- await _repoManager.BeginTranAsync();
- var menu = await _repoManager.Menus.GetByIdAsync(id);
- if (menu == null)
- {
- throw new InvalidOperationException($"删除菜单失败:菜单ID:{id},请检查菜单Id是否存在");
- }
- var delRes = await _repoManager.Menus.DeleteAsync(menu);
- if (delRes == 0)
- {
- throw new InvalidOperationException($"删除菜单失败:菜单ID:{id},请检查菜单Id是否存在");
- }
- await _repoManager.CommitAsync();
- return true;
- }
- catch (Exception ex)
- {
- await _repoManager.RollbackAsync();
- throw new ApplicationException("删除菜单时发生错误,操作已回滚。", ex);
- }
+ var delRes = await _repoManager.Menus.DeleteAsync(menu);
+ return delRes > 0;
}
}
\ No newline at end of file
diff --git a/DMS.Application/Services/Database/MqttAliasAppService.cs b/DMS.Application/Services/Database/MqttAliasAppService.cs
index 5c72015..17f5582 100644
--- a/DMS.Application/Services/Database/MqttAliasAppService.cs
+++ b/DMS.Application/Services/Database/MqttAliasAppService.cs
@@ -12,16 +12,16 @@ namespace DMS.Application.Services.Database;
public class MqttAliasAppService : IMqttAliasAppService
{
private readonly IRepositoryManager _repoManager;
- private readonly IAppStorageService _appStorageService;
+ private readonly IAppDataService _appDataService;
private readonly IMapper _mapper;
///
/// 构造函数。
///
- public MqttAliasAppService(IRepositoryManager repoManager,IAppStorageService appStorageService, IMapper mapper)
+ public MqttAliasAppService(IRepositoryManager repoManager,IAppDataService appStorageService, IMapper mapper)
{
_repoManager = repoManager;
- _appStorageService = appStorageService;
+ _appDataService = appStorageService;
_mapper = mapper;
}
diff --git a/DMS.Application/Services/Database/TriggerAppService.cs b/DMS.Application/Services/Database/TriggerAppService.cs
index 4172863..a5d9b65 100644
--- a/DMS.Application/Services/Database/TriggerAppService.cs
+++ b/DMS.Application/Services/Database/TriggerAppService.cs
@@ -107,24 +107,24 @@ namespace DMS.Application.Services.Database
if (dto.TriggerMenu != null)
{
// 使用现有的菜单查找逻辑来获取父菜单
- var parentMenu = await _repositoryManager.Menus.GetMenuByTargetIdAsync(Core.Enums.MenuType.TriggerMenu, 0);
- if (parentMenu != null)
- {
- // 设置菜单的关联信息
- dto.TriggerMenu.ParentId = parentMenu.Id;
- dto.TriggerMenu.MenuType = Core.Enums.MenuType.TriggerMenu;
- dto.TriggerMenu.TargetId = createdTrigger.Id;
+ //var parentMenu = await _repositoryManager.Menus.GetMenuByTargetIdAsync(Core.Enums.MenuType.TriggerMenu, 0);
+ //if (parentMenu != null)
+ //{
+ // // 设置菜单的关联信息
+ // dto.TriggerMenu.ParentId = parentMenu.Id;
+ // dto.TriggerMenu.MenuType = Core.Enums.MenuType.TriggerMenu;
+ // dto.TriggerMenu.TargetId = createdTrigger.Id;
- // 添加菜单到数据库
- var addMenu = await _repositoryManager.Menus.AddAsync(dto.TriggerMenu);
- if (addMenu == null || addMenu.Id == 0)
- {
- throw new InvalidOperationException($"添加触发器菜单失败:{addMenu}");
- }
+ // // 添加菜单到数据库
+ // var addMenu = await _repositoryManager.Menus.AddAsync(dto.TriggerMenu);
+ // if (addMenu == null || addMenu.Id == 0)
+ // {
+ // throw new InvalidOperationException($"添加触发器菜单失败:{addMenu}");
+ // }
- // 更新dto中的菜单对象
- dto.TriggerMenu = addMenu;
- }
+ // // 更新dto中的菜单对象
+ // dto.TriggerMenu = addMenu;
+ //}
}
await _repositoryManager.CommitAsync();
diff --git a/DMS.Application/Services/Database/VariableAppService.cs b/DMS.Application/Services/Database/VariableAppService.cs
index b39bb95..1765a5d 100644
--- a/DMS.Application/Services/Database/VariableAppService.cs
+++ b/DMS.Application/Services/Database/VariableAppService.cs
@@ -38,27 +38,7 @@ public class VariableAppService : IVariableAppService
return variable;
}
- ///
- /// 异步根据OPC UA NodeId获取变量数据传输对象。
- ///
- /// OPC UA NodeId。
- /// 变量数据传输对象。
- public async Task GetVariableByOpcUaNodeIdAsync(string opcUaNodeId)
- {
- var variable = await _repoManager.Variables.GetByOpcUaNodeIdAsync(opcUaNodeId);
- return variable ;
- }
- ///
- /// 异步根据OPC UA NodeId列表获取变量数据传输对象列表。
- ///
- /// OPC UA NodeId列表。
- /// 变量数据传输对象列表。
- public async Task> GetVariableByOpcUaNodeIdsAsync(List opcUaNodeIds)
- {
- var variables = await _repoManager.Variables.GetByOpcUaNodeIdsAsync(opcUaNodeIds);
- return variables;
- }
///
/// 异步获取所有变量数据传输对象列表。
@@ -73,13 +53,13 @@ public class VariableAppService : IVariableAppService
///
/// 异步创建一个新变量(事务性操作)。
///
-/// 要创建的变量数据传输对象。
- public async Task CreateVariableAsync(Variable variable)
+ /// 要创建的变量数据传输对象。
+ public async Task AddAsync(Variable variable)
{
try
{
await _repoManager.BeginTranAsync();
- var addedVariable = await _repoManager.Variables.AddAsync(variable); await _repoManager.CommitAsync();
+ var addedVariable = await _repoManager.Variables.AddAsync(variable); await _repoManager.CommitAsync();
return _mapper.Map(addedVariable);
}
catch (Exception ex)
@@ -92,8 +72,8 @@ public class VariableAppService : IVariableAppService
///
/// 异步更新一个已存在的变量(事务性操作)。
///
-/// 要更新的变量数据传输对象。
- public async Task UpdateVariableAsync(Variable variable)
+ /// 要更新的变量数据传输对象。
+ public async Task UpdateAsync(Variable variable)
{
try
{
@@ -121,13 +101,13 @@ public class VariableAppService : IVariableAppService
/// 要更新的变量数据传输对象列表。
/// 受影响的行数。
/// 如果更新变量时发生错误。
- public async Task UpdateVariablesAsync(List variables)
+ public async Task UpdateAsync(List variables)
{
try
{
await _repoManager.BeginTranAsync();
int totalAffected = 0;
-
+
foreach (var variable in variables)
{
var existingVariable = await _repoManager.Variables.GetByIdAsync(variable.Id);
@@ -139,7 +119,7 @@ public class VariableAppService : IVariableAppService
int res = await _repoManager.Variables.UpdateAsync(existingVariable);
totalAffected += res;
}
-
+
await _repoManager.CommitAsync();
return totalAffected;
}
@@ -153,24 +133,19 @@ public class VariableAppService : IVariableAppService
///
/// 异步删除一个变量(事务性操作)。
///
- /// 要删除变量的ID。
+ ///
/// 如果删除成功则为 true,否则为 false。
/// 如果删除变量失败。
/// 如果删除变量时发生其他错误。
- public async Task DeleteVariableAsync(int id)
+ public async Task DeleteAsync(Variable variable)
{
try
{
await _repoManager.BeginTranAsync();
- var variable = await _repoManager.Variables.GetByIdAsync(id);
- if (variable == null)
- {
- throw new InvalidOperationException($"删除变量失败:变量ID:{id},请检查变量Id是否存在");
- }
var delRes = await _repoManager.Variables.DeleteAsync(variable);
if (delRes == 0)
{
- throw new InvalidOperationException($"删除变量失败:变量ID:{id},请检查变量Id是否存在");
+ throw new InvalidOperationException($"删除变量失败:变量ID:{variable.Id},请检查变量Id是否存在");
}
await _repoManager.CommitAsync();
return true;
@@ -185,30 +160,26 @@ public class VariableAppService : IVariableAppService
///
/// 异步批量删除变量(事务性操作)。
///
- /// 要删除的变量ID列表。
+ ///
/// 如果删除成功则为 true,否则为 false。
/// 如果ID列表为空或null。
/// 如果删除变量时发生错误。
- public async Task DeleteVariablesAsync(List ids)
+ public async Task DeleteAsync(List variables)
{
- if (ids == null || !ids.Any())
- {
- throw new ArgumentException("变量ID列表不能为空", nameof(ids));
- }
try
{
await _repoManager.BeginTranAsync();
-
+
// 批量删除变量
- // var deletedCount = await _repoManager.Variables.DeleteByIdsAsync(ids);
- //
- // // 检查是否所有变量都被成功删除
- // if (deletedCount != ids.Count)
- // {
- // throw new InvalidOperationException($"删除变量失败:请求删除 {ids.Count} 个变量,实际删除 {deletedCount} 个变量");
- // }
-
+ var deletedCount = await _repoManager.Variables.DeleteAsync(variables);
+
+ // 检查是否所有变量都被成功删除
+ if (deletedCount != variables.Count)
+ {
+ throw new InvalidOperationException($"删除变量失败:请求删除 {variables.Count} 个变量,实际删除 {deletedCount} 个变量");
+ }
+
await _repoManager.CommitAsync();
return true;
}
@@ -219,68 +190,8 @@ public class VariableAppService : IVariableAppService
}
}
- public async Task> BatchImportVariablesAsync(List variables)
+ public async Task> AddAsync(List variables)
{
- try
- {
- var variableModels = _mapper.Map>(variables);
- var addedVariables = await _repoManager.Variables.AddAsync(variableModels);
- return _mapper.Map>(addedVariables);
- }
- catch (Exception ex)
- {
- throw new ApplicationException($"批量导入变量时发生错误,错误信息:{ex.Message}", ex);
- }
- }
-
- public async Task> FindExistingVariablesAsync(IEnumerable variablesToCheck)
- {
- if (variablesToCheck == null || !variablesToCheck.Any())
- {
- return new List();
- }
-
- var names = variablesToCheck.Select(v => v.Name).Where(n => !string.IsNullOrEmpty(n)).Distinct().ToList();
- var s7Addresses = variablesToCheck.Select(v => v.S7Address).Where(a => !string.IsNullOrEmpty(a)).Distinct().ToList();
- var opcUaNodeIds = variablesToCheck.Select(v => v.OpcUaNodeId).Where(id => !string.IsNullOrEmpty(id)).Distinct().ToList();
-
- var allVariables = await _repoManager.Variables.GetAllAsync();
- var existingVariablesFromDb = allVariables.Where(v =>
- (names.Any() && !string.IsNullOrEmpty(v.Name) && names.Contains(v.Name)) ||
- (s7Addresses.Any() && !string.IsNullOrEmpty(v.S7Address) && s7Addresses.Contains(v.S7Address)) ||
- (opcUaNodeIds.Any() && !string.IsNullOrEmpty(v.OpcUaNodeId) && opcUaNodeIds.Contains(v.OpcUaNodeId)))
- .ToList();
-
- if (existingVariablesFromDb == null || !existingVariablesFromDb.Any())
- {
- return new List();
- }
-
- var existingNames = new HashSet(existingVariablesFromDb.Select(v => v.Name).Where(n => !string.IsNullOrEmpty(n)));
- var existingS7Addresses = new HashSet(existingVariablesFromDb.Select(v => v.S7Address).Where(a => !string.IsNullOrEmpty(a)));
- var existingOpcUaNodeIds = new HashSet(existingVariablesFromDb.Select(v => v.OpcUaNodeId).Where(id => !string.IsNullOrEmpty(id)));
-
- var result = existingVariablesFromDb.Where(v =>
- (names.Any() && !string.IsNullOrEmpty(v.Name) && names.Contains(v.Name)) ||
- (s7Addresses.Any() && !string.IsNullOrEmpty(v.S7Address) && s7Addresses.Contains(v.S7Address)) ||
- (opcUaNodeIds.Any() && !string.IsNullOrEmpty(v.OpcUaNodeId) && opcUaNodeIds.Contains(v.OpcUaNodeId)))
- .ToList();
-
- return result;
- }
-
- public async Task FindExistingVariableAsync(Variable variableToCheck)
- {
- if (variableToCheck == null)
- {
- return null;
- }
-
- // 创建一个包含单个元素的列表以便复用现有的逻辑
- var variablesToCheck = new List { variableToCheck };
- var existingVariables = await FindExistingVariablesAsync(variablesToCheck);
-
- // 如果找到了匹配的变量,返回第一个(也是唯一一个)
- return existingVariables.FirstOrDefault();
+ return await _repoManager.Variables.AddAsync(variables);
}
}
\ No newline at end of file
diff --git a/DMS.Application/Services/Database/VariableTableAppService.cs b/DMS.Application/Services/Database/VariableTableAppService.cs
index 5299954..da452fe 100644
--- a/DMS.Application/Services/Database/VariableTableAppService.cs
+++ b/DMS.Application/Services/Database/VariableTableAppService.cs
@@ -74,21 +74,21 @@ namespace DMS.Application.Services.Database
if (createDto.Menu!=null)
{
// 获取设备菜单,作为变量表菜单的父级
- var deviceMenu
- = await _repositoryManager.Menus.GetMenuByTargetIdAsync(
- MenuType.DeviceMenu, createDto.DeviceId);
- if (deviceMenu == null)
- {
- throw new ApplicationException($"添加变量表菜单时,找不到设备ID:{createDto.DeviceId},请检查。");
- }
+ //var deviceMenu
+ // = await _repositoryManager.Menus.GetMenuByTargetIdAsync(
+ // MenuType.DeviceMenu, createDto.DeviceId);
+ //if (deviceMenu == null)
+ //{
+ // throw new ApplicationException($"添加变量表菜单时,找不到设备ID:{createDto.DeviceId},请检查。");
+ //}
// 映射菜单实体并设置关联信息
- var menu = _mapper.Map(createDto.Menu);
- menu.ParentId = deviceMenu.Id;
- menu.TargetId = createdVariableTable.Id;
- menu.MenuType = MenuType.VariableTableMenu;
- var addMenu= await _repositoryManager.Menus.AddAsync(menu);
- _mapper.Map(addMenu, createDto.Menu);
+ // var menu = _mapper.Map(createDto.Menu);
+ // menu.ParentId = deviceMenu.Id;
+ // menu.TargetId = createdVariableTable.Id;
+ // menu.MenuType = MenuType.VariableTableMenu;
+ //var addMenu= await _repositoryManager.Menus.AddAsync(menu);
+ //_mapper.Map(addMenu, createDto.Menu);
}
@@ -164,7 +164,7 @@ namespace DMS.Application.Services.Database
// await _repositoryManager.MqttAlias.DeleteByVariableTableIdAsync(id);
// 删除关联的菜单树
- await _repositoryManager.Menus.DeleteMenuTreeByTargetIdAsync(MenuType.VariableTableMenu, id);
+ //await _repositoryManager.Menus.DeleteMenuTreeByTargetIdAsync(MenuType.VariableTableMenu, id);
await _repositoryManager.CommitAsync();
return true;
diff --git a/DMS.Application/Services/EventService.cs b/DMS.Application/Services/EventService.cs
index 5bc0d12..6b400ec 100644
--- a/DMS.Application/Services/EventService.cs
+++ b/DMS.Application/Services/EventService.cs
@@ -9,11 +9,11 @@ namespace DMS.Application.Services;
///
public class EventService : IEventService
{
- private readonly IAppStorageService _appStorageService;
+ private readonly IAppDataService _appDataService;
- public EventService(IAppStorageService appStorageService)
+ public EventService(IAppDataService appStorageService)
{
- _appStorageService = appStorageService;
+ _appDataService = appStorageService;
}
#region 设备事件
diff --git a/DMS.Application/Services/Management/DeviceManagementService.cs b/DMS.Application/Services/Management/DeviceManagementService.cs
index 64f99b5..5f6ac07 100644
--- a/DMS.Application/Services/Management/DeviceManagementService.cs
+++ b/DMS.Application/Services/Management/DeviceManagementService.cs
@@ -1,3 +1,4 @@
+using AutoMapper;
using DMS.Application.DTOs;
using DMS.Application.Events;
using DMS.Application.Interfaces;
@@ -13,14 +14,16 @@ namespace DMS.Application.Services.Management;
///
public class DeviceManagementService : IDeviceManagementService
{
+ private readonly IMapper _mapper;
private readonly IDeviceAppService _deviceAppService;
- private readonly IAppStorageService _appStorageService;
+ private readonly IAppDataService _appDataService;
private readonly IEventService _eventService;
- public DeviceManagementService(IDeviceAppService deviceAppService, IAppStorageService appStorageService, IEventService eventService)
+ public DeviceManagementService(IMapper mapper, IDeviceAppService deviceAppService, IAppDataService appStorageService, IEventService eventService)
{
+ _mapper = mapper;
_deviceAppService = deviceAppService;
- _appStorageService = appStorageService;
+ _appDataService = appStorageService;
_eventService = eventService;
}
@@ -45,39 +48,58 @@ public class DeviceManagementService : IDeviceManagementService
///
public async Task CreateDeviceWithDetailsAsync(CreateDeviceWithDetailsDto dto)
{
-
-
-
+
+
+
var result = await _deviceAppService.CreateDeviceWithDetailsAsync(dto);
-
+
// 创建成功后,将设备添加到内存中
if (result?.Device != null)
{
- if (_appStorageService.Devices.TryAdd(result.Device.Id, result.Device))
+ if (_appDataService.Devices.TryAdd(result.Device.Id, result.Device))
{
+
+ if (result.VariableTable is not null)
+ {
+ if (_appDataService.VariableTables.TryAdd(result.VariableTable.Id, result.VariableTable))
+ {
+ result.VariableTable.Device = result.Device;
+ //将默认变量表添加到设备中
+ result.Device.VariableTables.Add(result.VariableTable);
+
+ _eventService.RaiseVariableTableChanged(this, new VariableTableChangedEventArgs(DataChangeType.Added, result.VariableTable));
+ }
+ }
+
_eventService.RaiseDeviceChanged(this, new DeviceChangedEventArgs(DataChangeType.Added, result.Device));
}
- if (result.VariableTable is not null)
- {
- if (_appStorageService.VariableTables.TryAdd(result.VariableTable.Id, result.VariableTable))
- {
- _eventService.RaiseVariableTableChanged(this, new VariableTableChangedEventArgs(DataChangeType.Added, result.VariableTable));
- }
- }
+ //关联菜单
if (result.DeviceMenu is not null)
{
- _appStorageService.Menus.TryAdd(result.DeviceMenu.Id, result.DeviceMenu);
+
+ var deviceRootMenu = _appDataService.Menus.Values.FirstOrDefault(m => m.TargetViewKey == "DevicesViewModel" && m.TargetId == 0);
+ if (deviceRootMenu is not null)
+ {
+ _appDataService.Menus.TryAdd(result.DeviceMenu.Id, result.DeviceMenu);
+ //将设备菜单添加到根菜单中
+ deviceRootMenu.Children.Add(result.DeviceMenu);
+
+ if (result.VariableTableMenu is not null)
+ {
+ _appDataService.Menus.TryAdd(result.VariableTableMenu.Id, result.VariableTableMenu);
+ //将变量表菜单添加到设备菜单中
+ result.DeviceMenu.Children.Add(result.VariableTableMenu);
+ }
+ }
+
}
- if (result.VariableTableMenu is not null)
- {
- _appStorageService.Menus.TryAdd(result.VariableTableMenu.Id, result.VariableTableMenu);
- }
+
}
-
+
return result;
}
@@ -87,14 +109,19 @@ public class DeviceManagementService : IDeviceManagementService
public async Task UpdateDeviceAsync(Device device)
{
var result = await _deviceAppService.UpdateDeviceAsync(device);
-
+
// 更新成功后,更新内存中的设备
- if (result > 0 && device != null)
+ if (result > 0)
{
- _appStorageService.Devices.AddOrUpdate(device.Id, device, (key, oldValue) => device);
+ var deviceMenu = _appDataService.Menus.Values.FirstOrDefault(m => m.MenuType == MenuType.DeviceMenu && m.TargetId == device.Id);
+ if (deviceMenu is not null && deviceMenu.Header != device.Name)
+ {
+ deviceMenu.Header = device.Name;
+ }
+
_eventService.RaiseDeviceChanged(this, new DeviceChangedEventArgs(DataChangeType.Updated, device));
}
-
+
return result;
}
@@ -104,28 +131,41 @@ public class DeviceManagementService : IDeviceManagementService
public async Task DeleteAsync(Device device)
{
var result = await _deviceAppService.DeleteAsync(device);
-
+
// 删除成功后,从内存中移除设备
- if (result )
+ if (result)
{
- if (_appStorageService.Devices.TryGetValue(device.Id, out var deviceInStorage))
+ if (_appDataService.Devices.TryGetValue(device.Id, out var deviceInStorage))
{
+ //删除设备的所有变量表和变量
foreach (var variableTable in deviceInStorage.VariableTables)
{
foreach (var variable in variableTable.Variables)
{
- _appStorageService.Variables.TryRemove(variable.Id, out _);
+ _appDataService.Variables.TryRemove(variable.Id, out _);
}
- _appStorageService.VariableTables.TryRemove(variableTable.Id, out _);
+ _appDataService.VariableTables.TryRemove(variableTable.Id, out _);
+ }
+ //删除菜单
+ var deviceMenu = _appDataService.Menus.Values.FirstOrDefault(m => m.MenuType == MenuType.DeviceMenu && m.TargetId == device.Id);
+ if (deviceMenu is not null)
+ {
+ foreach (var menu in deviceMenu.Children)
+ {
+ _appDataService.Menus.TryRemove(menu.Id, out _);
+ }
+
+ _appDataService.Menus.TryRemove(deviceMenu.Id, out _);
}
- _appStorageService.Devices.TryRemove(device.Id, out _);
+ //删除设备
+ _appDataService.Devices.TryRemove(device.Id, out _);
_eventService.RaiseDeviceChanged(this, new DeviceChangedEventArgs(DataChangeType.Deleted, deviceInStorage));
}
}
-
+
return result;
}
@@ -135,12 +175,12 @@ public class DeviceManagementService : IDeviceManagementService
public async Task ToggleDeviceActiveStateAsync(int id)
{
await _deviceAppService.ToggleDeviceActiveStateAsync(id);
-
+
// 更新内存中的设备状态
var device = await _deviceAppService.GetDeviceByIdAsync(id);
if (device != null)
{
- _appStorageService.Devices.AddOrUpdate(device.Id, device, (key, oldValue) => device);
+ _appDataService.Devices.AddOrUpdate(device.Id, device, (key, oldValue) => device);
_eventService.RaiseDeviceChanged(this, new DeviceChangedEventArgs(DataChangeType.Updated, device));
}
}
@@ -150,14 +190,14 @@ public class DeviceManagementService : IDeviceManagementService
///
public async Task LoadAllDevicesAsync()
{
- _appStorageService.Devices.Clear();
+ _appDataService.Devices.Clear();
var devices = await _deviceAppService.GetAllDevicesAsync();
-
+
// 建立设备与变量表的关联
foreach (var device in devices)
{
// 将设备添加到安全字典
- _appStorageService.Devices.TryAdd(device.Id, device);
+ _appDataService.Devices.TryAdd(device.Id, device);
}
}
diff --git a/DMS.Application/Services/Management/LogManagementService.cs b/DMS.Application/Services/Management/LogManagementService.cs
index c46cd75..1bd1979 100644
--- a/DMS.Application/Services/Management/LogManagementService.cs
+++ b/DMS.Application/Services/Management/LogManagementService.cs
@@ -13,17 +13,17 @@ namespace DMS.Application.Services.Management;
public class LogManagementService : ILogManagementService
{
private readonly INlogAppService _nlogAppService;
- private readonly IAppStorageService _appStorageService;
+ private readonly IAppDataService _appDataService;
///
/// 当日志数据发生变化时触发
///
public event EventHandler OnLogChanged;
- public LogManagementService(INlogAppService nlogAppService,IAppStorageService appStorageService)
+ public LogManagementService(INlogAppService nlogAppService,IAppDataService appStorageService)
{
_nlogAppService = nlogAppService;
- _appStorageService = appStorageService;
+ _appDataService = appStorageService;
}
///
@@ -63,7 +63,7 @@ public class LogManagementService : ILogManagementService
///
public void AddNlogToMemory(NlogDto nlogDto)
{
- if (_appStorageService.Nlogs.TryAdd(nlogDto.Id, nlogDto))
+ if (_appDataService.Nlogs.TryAdd(nlogDto.Id, nlogDto))
{
OnLogChanged?.Invoke(this,new NlogChangedEventArgs(DataChangeType.Added, nlogDto));
}
@@ -74,7 +74,7 @@ public class LogManagementService : ILogManagementService
///
public void UpdateNlogInMemory(NlogDto nlogDto)
{
- _appStorageService.Nlogs.AddOrUpdate(nlogDto.Id, nlogDto, (key, oldValue) => nlogDto);
+ _appDataService.Nlogs.AddOrUpdate(nlogDto.Id, nlogDto, (key, oldValue) => nlogDto);
OnLogChanged?.Invoke(this,new NlogChangedEventArgs(DataChangeType.Updated, nlogDto));
}
@@ -83,7 +83,7 @@ public class LogManagementService : ILogManagementService
///
public void RemoveNlogFromMemory(int nlogId)
{
- if (_appStorageService.Nlogs.TryRemove(nlogId, out var nlogDto))
+ if (_appDataService.Nlogs.TryRemove(nlogId, out var nlogDto))
{
OnLogChanged?.Invoke(this,new NlogChangedEventArgs(DataChangeType.Deleted, nlogDto));
}
@@ -94,12 +94,12 @@ public class LogManagementService : ILogManagementService
///
public async Task LoadAllNlogsAsync(int count)
{
- _appStorageService.Nlogs.Clear();
+ _appDataService.Nlogs.Clear();
var nlogDtos = await _nlogAppService.GetLatestLogsAsync(count);
// 加载日志数据到内存
foreach (var nlogDto in nlogDtos)
{
- _appStorageService.Nlogs.TryAdd(nlogDto.Id, nlogDto);
+ _appDataService.Nlogs.TryAdd(nlogDto.Id, nlogDto);
}
}
diff --git a/DMS.Application/Services/Management/MenuManagementService.cs b/DMS.Application/Services/Management/MenuManagementService.cs
index e97bcc1..f89fe84 100644
--- a/DMS.Application/Services/Management/MenuManagementService.cs
+++ b/DMS.Application/Services/Management/MenuManagementService.cs
@@ -12,7 +12,7 @@ namespace DMS.Application.Services.Management;
public class MenuManagementService : IMenuManagementService
{
private readonly IMenuAppService _menuService;
- private readonly IAppStorageService _appStorageService;
+ private readonly IAppDataService _appDataService;
private readonly IEventService _eventService;
///
@@ -20,10 +20,10 @@ public class MenuManagementService : IMenuManagementService
///
public event EventHandler MenuChanged;
- public MenuManagementService(IMenuAppService menuService, IAppStorageService appStorageService, IEventService eventService)
+ public MenuManagementService(IMenuAppService menuService, IAppDataService appStorageService, IEventService eventService)
{
_menuService = menuService;
- _appStorageService = appStorageService;
+ _appDataService = appStorageService;
_eventService = eventService;
}
@@ -46,41 +46,40 @@ public class MenuManagementService : IMenuManagementService
///
/// 异步创建一个新菜单。
///
- public async Task CreateMenuAsync(MenuBean menu)
+ public async Task AddAsync(MenuBean menu)
{
- var result = await _menuService.CreateMenuAsync(menu);
+ var resMenu = await _menuService.AddAsync(menu);
// 创建成功后,将菜单添加到内存中
- if (result > 0)
+ if (resMenu is not null)
{
- menu.Id = result; // 假设返回的ID是新创建的
- if (_appStorageService.Menus.TryAdd(menu.Id, menu))
+ if (_appDataService.Menus.TryAdd(resMenu.Id, resMenu))
{
MenuBean parentMenu = null;
- if (menu.ParentId > 0 && _appStorageService.Menus.TryGetValue(menu.ParentId.Value, out var parent))
+ if (resMenu.ParentId > 0 && _appDataService.Menus.TryGetValue(resMenu.ParentId.Value, out var parent))
{
parentMenu = parent;
- parent.Children.Add(menu);
+ parent.Children.Add(resMenu);
}
- _eventService.RaiseMenuChanged(this, new MenuChangedEventArgs(DataChangeType.Added, menu));
+ _eventService.RaiseMenuChanged(this, new MenuChangedEventArgs(DataChangeType.Added, resMenu));
}
}
- return result;
+ return resMenu;
}
///
/// 异步更新一个已存在的菜单。
///
- public async Task UpdateMenuAsync(MenuBean menu)
+ public async Task UpdateAsync(MenuBean menu)
{
- var result = await _menuService.UpdateMenuAsync(menu);
+ var result = await _menuService.UpdateAsync(menu);
// 更新成功后,更新内存中的菜单
if (result > 0)
{
- if (_appStorageService.Menus.TryGetValue(menu.Id,out var mMenu))
+ if (_appDataService.Menus.TryGetValue(menu.Id,out var mMenu))
{
mMenu.Header = menu.Header;
}
@@ -94,18 +93,17 @@ public class MenuManagementService : IMenuManagementService
///
/// 异步删除一个菜单。
///
- public async Task DeleteMenuAsync(int id)
+ public async Task DeleteAsync(MenuBean menu)
{
- var menu = await _menuService.GetMenuByIdAsync(id); // 获取菜单信息用于内存删除
- var result = await _menuService.DeleteMenuAsync(id);
+ var result = await _menuService.DeleteAsync(menu);
// 删除成功后,从内存中移除菜单
if (result && menu != null)
{
- if (_appStorageService.Menus.TryRemove(id, out var menuData))
+ if (_appDataService.Menus.TryRemove(menu.Id, out var menuData))
{
// 从父菜单中移除子菜单
- if (menuData.ParentId > 0 && _appStorageService.Menus.TryGetValue(menuData.ParentId.Value, out var parentMenu))
+ if (menuData.ParentId > 0 && _appDataService.Menus.TryGetValue(menuData.ParentId.Value, out var parentMenu))
{
parentMenu.Children.Remove(menuData);
}
@@ -117,41 +115,49 @@ public class MenuManagementService : IMenuManagementService
return result;
}
- ///
- /// 获取根菜单列表
- ///
- public List GetRootMenus()
- {
- return _appStorageService.Menus.Values.Where(m => m.ParentId == 0)
- .ToList();
- }
+
+
///
- /// 根据父级ID获取子菜单列表
+ /// 构建菜单树。
///
- /// 父级菜单ID
- /// 子菜单列表
- public List GetChildMenus(int parentId)
+ public void BuildMenuTrees()
{
- return _appStorageService.Menus.Values.Where(m => m.ParentId == parentId)
- .ToList();
- }
+ // 创建一个新的临时列表来存储根菜单
+ var newRootMenus = new List();
- ///
- /// 构建菜单树结构
- ///
- public void BuildMenuTree()
- {
- // 清空现有菜单树
- _appStorageService.MenuTrees.Clear();
-
- // 获取所有根菜单
- var rootMenus = GetRootMenus();
-
- // 将根菜单添加到菜单树中
- foreach (var rootMenu in rootMenus)
+ // 首先,确保所有菜单项的Children集合是干净的
+ foreach (var menu in _appDataService.Menus.Values)
{
- _appStorageService.MenuTrees.TryAdd(rootMenu.Id, rootMenu);
+ // 避免循环引用,清空Children集合
+ menu.Children.Clear();
+ }
+
+ // 遍历所有菜单项,构建树形结构
+ foreach (var menu in _appDataService.Menus.Values)
+ {
+ var parentMenu = _appDataService.Menus.Values.FirstOrDefault(m => m.Id == menu.ParentId);
+ // 检查是否有父ID,并且父ID不为0(通常0或null表示根节点)
+ if (parentMenu != null && menu.ParentId != 0)
+ {
+ // 将当前菜单添加到父菜单的Children列表中
+ if (!parentMenu.Children.Contains(menu))
+ {
+ parentMenu.Children.Add(menu);
+ }
+ }
+ else
+ {
+ // 如果没有父ID,则这是一个根菜单
+ newRootMenus.Add(menu);
+ }
+ }
+
+ // 在UI线程安全地更新MenuTrees集合
+ _appDataService.MenuTrees.Clear();
+ foreach (var rootMenu in newRootMenus)
+ {
+ _appDataService.MenuTrees.TryAdd(rootMenu.Id,rootMenu);
}
}
@@ -168,13 +174,15 @@ public class MenuManagementService : IMenuManagementService
///
public async Task LoadAllMenusAsync()
{
- _appStorageService.Menus.Clear();
- _appStorageService.MenuTrees.Clear();
+ _appDataService.Menus.Clear();
+ _appDataService.MenuTrees.Clear();
var menus = await _menuService.GetAllMenusAsync();
// 将菜单添加到安全字典
foreach (var menuBean in menus)
{
- _appStorageService.Menus.TryAdd(menuBean.Id, menuBean);
+ _appDataService.Menus.TryAdd(menuBean.Id, menuBean);
}
+
+ BuildMenuTrees();
}
}
\ No newline at end of file
diff --git a/DMS.Application/Services/Management/MqttAliasManagementService.cs b/DMS.Application/Services/Management/MqttAliasManagementService.cs
index 94c4225..47aa884 100644
--- a/DMS.Application/Services/Management/MqttAliasManagementService.cs
+++ b/DMS.Application/Services/Management/MqttAliasManagementService.cs
@@ -12,11 +12,11 @@ public class MqttAliasManagementService : IMqttAliasManagementService
{
private readonly IMqttAliasAppService _appService;
private readonly IEventService _eventService;
- private readonly IAppStorageService _storageService;
+ private readonly IAppDataService _storageService;
private readonly IMapper _mapper;
public MqttAliasManagementService(IMqttAliasAppService appService, IEventService eventService,
- IAppStorageService storageService, IMapper mapper)
+ IAppDataService storageService, IMapper mapper)
{
_appService = appService;
_eventService = eventService;
diff --git a/DMS.Application/Services/Management/MqttManagementService.cs b/DMS.Application/Services/Management/MqttManagementService.cs
index 958b9c6..387c4b7 100644
--- a/DMS.Application/Services/Management/MqttManagementService.cs
+++ b/DMS.Application/Services/Management/MqttManagementService.cs
@@ -15,15 +15,15 @@ namespace DMS.Application.Services.Management;
public class MqttManagementService : IMqttManagementService
{
private readonly IMqttAppService _mqttAppService;
- private readonly IAppStorageService _appStorageService;
+ private readonly IAppDataService _appDataService;
private readonly IEventService _eventService;
public MqttManagementService(IMqttAppService mqttAppService,
- IAppStorageService appStorageService,
+ IAppDataService appStorageService,
IEventService eventService)
{
_mqttAppService = mqttAppService;
- _appStorageService = appStorageService;
+ _appDataService = appStorageService;
_eventService = eventService;
}
@@ -32,7 +32,7 @@ public class MqttManagementService : IMqttManagementService
///
public async Task GetMqttServerByIdAsync(int id)
{
- if (_appStorageService.MqttServers.TryGetValue(id,out var mqttServer))
+ if (_appDataService.MqttServers.TryGetValue(id,out var mqttServer))
{
return mqttServer;
}
@@ -44,7 +44,7 @@ public class MqttManagementService : IMqttManagementService
///
public async Task> GetAllMqttServersAsync()
{
- return _appStorageService.MqttServers.Values.ToList();
+ return _appDataService.MqttServers.Values.ToList();
}
///
@@ -67,7 +67,7 @@ public class MqttManagementService : IMqttManagementService
{
foreach (var mqttServer in mqttServers)
{
- if (_appStorageService.MqttServers.TryGetValue(mqttServer.Id, out var mMqttServer))
+ if (_appDataService.MqttServers.TryGetValue(mqttServer.Id, out var mMqttServer))
{
// 比较旧值和新值,确定哪个属性发生了变化
var changedProperties = GetChangedProperties(mMqttServer, mqttServer);
@@ -99,7 +99,7 @@ public class MqttManagementService : IMqttManagementService
else
{
// 如果内存中不存在该MQTT服务器,则直接添加
- _appStorageService.MqttServers.TryAdd(mqttServer.Id, mqttServer);
+ _appDataService.MqttServers.TryAdd(mqttServer.Id, mqttServer);
_eventService.RaiseMqttServerChanged(
this, new MqttServerChangedEventArgs(ActionChangeType.Added, mqttServer, MqttServerPropertyType.All));
}
@@ -120,7 +120,7 @@ public class MqttManagementService : IMqttManagementService
// 删除成功后,从内存中移除MQTT服务器
if (result && mqttServer != null)
{
- if (_appStorageService.MqttServers.TryRemove(id, out var mqttServerFromCache))
+ if (_appDataService.MqttServers.TryRemove(id, out var mqttServerFromCache))
{
_eventService.RaiseMqttServerChanged(
this, new MqttServerChangedEventArgs(ActionChangeType.Deleted, mqttServerFromCache));
@@ -142,7 +142,7 @@ public class MqttManagementService : IMqttManagementService
// {
// foreach (var id in ids)
// {
- // if (_appStorageService.MqttServers.TryRemove(id, out var mqttServer))
+ // if (_appDataService.MqttServers.TryRemove(id, out var mqttServer))
// {
// _eventService.RaiseMqttServerChanged(
// this, new MqttServerChangedEventArgs(ActionChangeType.Deleted, mqttServer));
@@ -168,7 +168,7 @@ public class MqttManagementService : IMqttManagementService
// 将MQTT服务器添加到内存中
- if (_appStorageService.MqttServers.TryAdd(mqttServer.Id, mqttServer))
+ if (_appDataService.MqttServers.TryAdd(mqttServer.Id, mqttServer))
{
_eventService.RaiseMqttServerChanged(
this, new MqttServerChangedEventArgs(ActionChangeType.Added, mqttServer));
@@ -240,12 +240,12 @@ public class MqttManagementService : IMqttManagementService
///
public async Task LoadAllMqttServersAsync()
{
- _appStorageService.MqttServers.Clear();
+ _appDataService.MqttServers.Clear();
var mqttServers = await _mqttAppService.GetAllMqttServersAsync();
// 加载MQTT服务器数据到内存
foreach (var mqttServer in mqttServers)
{
- _appStorageService.MqttServers.TryAdd(mqttServer.Id, mqttServer);
+ _appDataService.MqttServers.TryAdd(mqttServer.Id, mqttServer);
}
}
}
\ No newline at end of file
diff --git a/DMS.Application/Services/Management/TriggerManagementService.cs b/DMS.Application/Services/Management/TriggerManagementService.cs
index 4ef842b..54beeb8 100644
--- a/DMS.Application/Services/Management/TriggerManagementService.cs
+++ b/DMS.Application/Services/Management/TriggerManagementService.cs
@@ -17,14 +17,14 @@ namespace DMS.Application.Services.Management
///
public class TriggerManagementService : ITriggerManagementService
{
- private readonly IAppStorageService _appStorageService;
+ private readonly IAppDataService _appDataService;
private readonly ITriggerAppService _triggerAppService;
private readonly IMapper _mapper;
private readonly IEventService _eventService;
- public TriggerManagementService(IAppStorageService appStorageService, ITriggerAppService triggerAppService, IMapper mapper, IEventService eventService)
+ public TriggerManagementService(IAppDataService appStorageService, ITriggerAppService triggerAppService, IMapper mapper, IEventService eventService)
{
- _appStorageService = appStorageService;
+ _appDataService = appStorageService;
_triggerAppService = triggerAppService;
_mapper = mapper ?? throw new ArgumentNullException(nameof(mapper));
_eventService = eventService;
@@ -35,7 +35,7 @@ namespace DMS.Application.Services.Management
///
public List GetAllTriggersAsync()
{
- var triggers = _appStorageService.Triggers.Values.ToList();
+ var triggers = _appDataService.Triggers.Values.ToList();
return _mapper.Map>(triggers);
}
@@ -44,7 +44,7 @@ namespace DMS.Application.Services.Management
///
public async Task GetTriggerByIdAsync(int id)
{
- _appStorageService.Triggers.TryGetValue(id, out var trigger);
+ _appDataService.Triggers.TryGetValue(id, out var trigger);
return trigger;
}
@@ -59,7 +59,7 @@ namespace DMS.Application.Services.Management
// 创建成功后,将触发器添加到内存中
if (createdTrigger != null)
{
- if (_appStorageService.Triggers.TryAdd(createdTrigger.Id, createdTrigger))
+ if (_appDataService.Triggers.TryAdd(createdTrigger.Id, createdTrigger))
{
_eventService.RaiseTriggerChanged(this, new TriggerChangedEventArgs(DataChangeType.Added, createdTrigger));
}
@@ -81,12 +81,12 @@ namespace DMS.Application.Services.Management
return null;
}
- if (_appStorageService.Triggers.TryAdd(result.Trigger.Id, result.Trigger))
+ if (_appDataService.Triggers.TryAdd(result.Trigger.Id, result.Trigger))
{
_eventService.RaiseTriggerChanged(this, new TriggerChangedEventArgs(DataChangeType.Added, result.Trigger));
}
- if (_appStorageService.Menus.TryAdd(result.TriggerMenu.Id, result.TriggerMenu))
+ if (_appDataService.Menus.TryAdd(result.TriggerMenu.Id, result.TriggerMenu))
{
_eventService.RaiseMenuChanged(this, new MenuChangedEventArgs(DataChangeType.Added, result.TriggerMenu));
}
@@ -107,7 +107,7 @@ namespace DMS.Application.Services.Management
return res;
// 6. 同步更新AppDataStorageService中的Triggers字典
- if (_appStorageService.Triggers.TryGetValue(trigger.Id, out var memTrigger))
+ if (_appDataService.Triggers.TryGetValue(trigger.Id, out var memTrigger))
{
_mapper.Map(trigger, memTrigger);
}
@@ -125,7 +125,7 @@ namespace DMS.Application.Services.Management
// 如果删除成功,也从AppDataStorageService中的Triggers字典中移除
if (await _triggerAppService.DeleteTriggerByIdAsync(id))
{
- _appStorageService.Triggers.TryRemove(id, out _);
+ _appDataService.Triggers.TryRemove(id, out _);
return true;
}
else
@@ -150,11 +150,11 @@ namespace DMS.Application.Services.Management
///
public async Task LoadAllTriggersAsync()
{
- _appStorageService.Triggers.Clear();
+ _appDataService.Triggers.Clear();
var triggerDefinitions = await _triggerAppService.GetAllTriggersAsync();
foreach (var triggerDefinition in triggerDefinitions)
{
- _appStorageService.Triggers.TryAdd(triggerDefinition.Id, triggerDefinition);
+ _appDataService.Triggers.TryAdd(triggerDefinition.Id, triggerDefinition);
}
}
diff --git a/DMS.Application/Services/Management/TriggerVariableManagementService.cs b/DMS.Application/Services/Management/TriggerVariableManagementService.cs
index be88e23..dbafa4c 100644
--- a/DMS.Application/Services/Management/TriggerVariableManagementService.cs
+++ b/DMS.Application/Services/Management/TriggerVariableManagementService.cs
@@ -12,13 +12,13 @@ namespace DMS.Application.Services.Management;
public class TriggerVariableManagementService : ITriggerVariableManagementService
{
private readonly ITriggerVariableAppService _triggerVariableAppService;
- private readonly IAppStorageService _appStorageService;
+ private readonly IAppDataService _appDataService;
private readonly IEventService _eventService;
- public TriggerVariableManagementService(ITriggerVariableAppService triggerVariableAppService,IAppStorageService appStorageService,IEventService eventService)
+ public TriggerVariableManagementService(ITriggerVariableAppService triggerVariableAppService,IAppDataService appStorageService,IEventService eventService)
{
_triggerVariableAppService = triggerVariableAppService;
- _appStorageService = appStorageService;
+ _appDataService = appStorageService;
_eventService = eventService;
}
@@ -28,7 +28,7 @@ public class TriggerVariableManagementService : ITriggerVariableManagementServic
if (newTriggerVariable != null)
{
// Add to cache
- _appStorageService.TriggerVariables.TryAdd(newTriggerVariable.Id, newTriggerVariable);
+ _appDataService.TriggerVariables.TryAdd(newTriggerVariable.Id, newTriggerVariable);
_eventService.RaiseTriggerVariableChanged(this, new TriggerVariableChangedEventArgs(ActionChangeType.Added, newTriggerVariable));
}
@@ -42,12 +42,12 @@ public class TriggerVariableManagementService : ITriggerVariableManagementServic
foreach (var triggerVariable in triggerVariables)
{
// Add to cache
- _appStorageService.TriggerVariables.TryAdd(triggerVariable.Id, triggerVariable);
+ _appDataService.TriggerVariables.TryAdd(triggerVariable.Id, triggerVariable);
- if (_appStorageService.Triggers.TryGetValue(triggerVariable.TriggerDefinitionId, out var trigger))
+ if (_appDataService.Triggers.TryGetValue(triggerVariable.TriggerDefinitionId, out var trigger))
{
- if (_appStorageService.Variables.TryGetValue(triggerVariable.VariableId, out var variable))
+ if (_appDataService.Variables.TryGetValue(triggerVariable.VariableId, out var variable))
{
trigger.Variables.Add(variable);
variable.Triggers.Add(trigger);
@@ -68,7 +68,7 @@ public class TriggerVariableManagementService : ITriggerVariableManagementServic
if (res > 0)
{
// Update cache
- if (_appStorageService.TriggerVariables.TryGetValue(triggerVariable.Id, out var existingTriggerVariable))
+ if (_appDataService.TriggerVariables.TryGetValue(triggerVariable.Id, out var existingTriggerVariable))
{
existingTriggerVariable.TriggerDefinitionId = triggerVariable.TriggerDefinitionId;
existingTriggerVariable.VariableId = triggerVariable.VariableId;
@@ -82,9 +82,9 @@ public class TriggerVariableManagementService : ITriggerVariableManagementServic
var result = await _triggerVariableAppService.RemoveTriggerVariableAsync(id);
if (result == 0) return false;
- if (_appStorageService.TriggerVariables.TryGetValue(id, out var triggerVariable))
+ if (_appDataService.TriggerVariables.TryGetValue(id, out var triggerVariable))
{
- _appStorageService.TriggerVariables.TryRemove(triggerVariable.Id, out _);
+ _appDataService.TriggerVariables.TryRemove(triggerVariable.Id, out _);
_eventService.RaiseTriggerVariableChanged(
this, new TriggerVariableChangedEventArgs(ActionChangeType.Deleted, triggerVariable));
}
@@ -107,7 +107,7 @@ public class TriggerVariableManagementService : ITriggerVariableManagementServic
foreach (var triggerVariable in addedTriggerVariables)
{
// Add to cache
- _appStorageService.TriggerVariables.TryAdd(triggerVariable.Id, triggerVariable);
+ _appDataService.TriggerVariables.TryAdd(triggerVariable.Id, triggerVariable);
_eventService.RaiseTriggerVariableChanged(this, new TriggerVariableChangedEventArgs(ActionChangeType.Added, triggerVariable));
}
diff --git a/DMS.Application/Services/Management/VariableManagementService.cs b/DMS.Application/Services/Management/VariableManagementService.cs
index f4ee821..fdbb25d 100644
--- a/DMS.Application/Services/Management/VariableManagementService.cs
+++ b/DMS.Application/Services/Management/VariableManagementService.cs
@@ -18,20 +18,20 @@ public class VariableManagementService : IVariableManagementService
private readonly IVariableAppService _variableAppService;
private readonly IEventService _eventService;
private readonly IMapper _mapper;
- private readonly IAppStorageService _appStorageService;
+ private readonly IAppDataService _appDataService;
private readonly IDataProcessingService _dataProcessingService;
public VariableManagementService(IVariableAppService variableAppService,
IEventService eventService,
IMapper mapper,
- IAppStorageService appStorageService,
+ IAppDataService appStorageService,
IDataProcessingService dataProcessingService)
{
_variableAppService = variableAppService;
_eventService = eventService;
_mapper = mapper;
- _appStorageService = appStorageService;
+ _appDataService = appStorageService;
_dataProcessingService = dataProcessingService;
}
@@ -56,24 +56,24 @@ public class VariableManagementService : IVariableManagementService
///
public async Task CreateVariableAsync(Variable variable)
{
- var result = await _variableAppService.CreateVariableAsync(variable);
-
+ var result = await _variableAppService.AddAsync(variable);
+
// 创建成功后,将变量添加到内存中
if (result != null)
{
- if (_appStorageService.VariableTables.TryGetValue(result.VariableTableId, out var variableTable))
+ if (_appDataService.VariableTables.TryGetValue(result.VariableTableId, out var variableTable))
{
result.VariableTable = variableTable;
variableTable.Variables.Add(result);
}
- if (_appStorageService.Variables.TryAdd(result.Id, result))
+ if (_appDataService.Variables.TryAdd(result.Id, result))
{
_eventService.RaiseVariableChanged(
this, new VariableChangedEventArgs(ActionChangeType.Added, result));
}
}
-
+
return result;
}
@@ -82,7 +82,7 @@ public class VariableManagementService : IVariableManagementService
///
public async Task UpdateVariableAsync(Variable variable)
{
- return await UpdateVariablesAsync(new List() { variable});
+ return await UpdateVariablesAsync(new List() { variable });
}
///
@@ -90,18 +90,18 @@ public class VariableManagementService : IVariableManagementService
///
public async Task UpdateVariablesAsync(List variables)
{
- var result = await _variableAppService.UpdateVariablesAsync(variables);
-
+ var result = await _variableAppService.UpdateAsync(variables);
+
// 批量更新成功后,更新内存中的变量
if (result > 0 && variables != null)
{
foreach (var variable in variables)
{
- if (_appStorageService.Variables.TryGetValue(variable.Id, out var mVariable))
+ if (_appDataService.Variables.TryGetValue(variable.Id, out var mVariable))
{
// 比较旧值和新值,确定哪个属性发生了变化
var changedProperties = GetChangedProperties(mVariable, variable);
-
+
// 更新内存中的变量
_mapper.Map(variable, mVariable);
@@ -111,81 +111,75 @@ public class VariableManagementService : IVariableManagementService
_eventService.RaiseVariableChanged(
this, new VariableChangedEventArgs(ActionChangeType.Updated, variable, property));
}
-
+
// 如果没有任何属性发生变化,至少触发一次更新事件
if (changedProperties.Count == 0)
{
_eventService.RaiseVariableChanged(
- this, new VariableChangedEventArgs(ActionChangeType.Updated, variable, VariablePropertyType.All));
+ this,
+ new VariableChangedEventArgs(ActionChangeType.Updated, variable, VariablePropertyType.All));
}
}
else
{
// 如果内存中不存在该变量,则直接添加
- _appStorageService.Variables.TryAdd(variable.Id, variable);
+ _appDataService.Variables.TryAdd(variable.Id, variable);
_eventService.RaiseVariableChanged(
this, new VariableChangedEventArgs(ActionChangeType.Added, variable, VariablePropertyType.All));
}
}
}
-
+
return result;
}
///
/// 异步删除一个变量。
///
- public async Task DeleteVariableAsync(int id)
+ public async Task DeleteAsync(Variable variable)
{
- var result = await _variableAppService.DeleteVariableAsync(id);
-
+ var result = await _variableAppService.DeleteAsync(variable);
+
// 删除成功后,从内存中移除变量
if (result)
{
- if (_appStorageService.Variables.TryRemove(id, out var variable))
+ if (_appDataService.Variables.TryRemove(variable.Id, out var mVariable))
{
- if (variable != null && _appStorageService.VariableTables.TryGetValue(variable.VariableTableId, out var variableTable))
+ if (variable != null &&
+ _appDataService.VariableTables.TryGetValue(variable.VariableTableId, out var variableTable))
{
variableTable.Variables.Remove(variable);
-
}
_eventService.RaiseVariableChanged(
- this, new VariableChangedEventArgs(ActionChangeType.Deleted, variable));
+ this, new VariableChangedEventArgs(ActionChangeType.Deleted, variable));
}
}
-
+
return result;
}
///
/// 异步批量导入变量。
///
- public async Task> BatchImportVariablesAsync(List variables)
+ public async Task> AddAsync(List variables)
{
- var result = await _variableAppService.BatchImportVariablesAsync(variables);
- foreach (var variable in result)
- {
- if (_appStorageService.VariableTables.TryGetValue(variable.VariableTableId ,out var variableTable))
- {
- variable.VariableTable = variableTable;
- }
-
- }
-
-
+ var result = await _variableAppService.AddAsync(variables);
// 批量导入成功后,触发批量导入事件
if (result != null && result.Any())
{
+ foreach (var variable in result)
+ {
+ if (_appDataService.VariableTables.TryGetValue(variable.VariableTableId, out var variableTable))
+ {
+ variable.VariableTable = variableTable;
+ variableTable.Variables.Add(variable);
+ }
+ }
_eventService.RaiseBatchImportVariables(this, new BatchImportVariablesEventArgs(result));
}
-
- return result;
- }
- public async Task> FindExistingVariablesAsync(IEnumerable variablesToCheck)
- {
- return await _variableAppService.FindExistingVariablesAsync(variablesToCheck);
+ return result;
}
///
@@ -200,45 +194,45 @@ public class VariableManagementService : IVariableManagementService
if (oldVariable.Name != newVariable.Name)
changedProperties.Add(VariablePropertyType.Name);
-
+
if (oldVariable.S7Address != newVariable.S7Address)
changedProperties.Add(VariablePropertyType.S7Address);
-
+
if (oldVariable.DataType != newVariable.DataType)
changedProperties.Add(VariablePropertyType.DataType);
-
+
if (oldVariable.ConversionFormula != newVariable.ConversionFormula)
changedProperties.Add(VariablePropertyType.ConversionFormula);
-
+
if (oldVariable.OpcUaUpdateType != newVariable.OpcUaUpdateType)
changedProperties.Add(VariablePropertyType.OpcUaUpdateType);
-
+
if (oldVariable.MqttAliases != newVariable.MqttAliases)
changedProperties.Add(VariablePropertyType.MqttAlias);
-
+
if (oldVariable.Description != newVariable.Description)
changedProperties.Add(VariablePropertyType.Description);
-
+
if (oldVariable.VariableTableId != newVariable.VariableTableId)
changedProperties.Add(VariablePropertyType.VariableTableId);
if (oldVariable.DataValue != newVariable.DataValue)
changedProperties.Add(VariablePropertyType.Value);
-
+
if (oldVariable.IsActive != newVariable.IsActive)
changedProperties.Add(VariablePropertyType.IsActive);
if (oldVariable.IsHistoryEnabled != newVariable.IsHistoryEnabled)
changedProperties.Add(VariablePropertyType.IsHistoryEnabled);
-
+
if (oldVariable.OpcUaNodeId != newVariable.OpcUaNodeId)
changedProperties.Add(VariablePropertyType.OpcUaNodeId);
-
+
if (oldVariable.PollingInterval != newVariable.PollingInterval)
changedProperties.Add(VariablePropertyType.PollingInterval);
-
+
if (oldVariable.SignalType != newVariable.SignalType)
changedProperties.Add(VariablePropertyType.SignalType);
-
+
if (oldVariable.Protocol != newVariable.Protocol)
changedProperties.Add(VariablePropertyType.Protocol);
@@ -249,52 +243,45 @@ public class VariableManagementService : IVariableManagementService
///
/// 异步批量删除变量。
///
- public async Task DeleteVariablesAsync(List ids)
+ public async Task DeleteAsync(List variables)
{
- var result = await _variableAppService.DeleteVariablesAsync(ids);
-
- // 批量删除成功后,从内存中移除变量
- if (result && ids != null)
- {
- foreach (var id in ids)
- {
- if (_appStorageService.Variables.TryRemove(id, out var variable))
- {
- if (variable != null && _appStorageService.VariableTables.TryGetValue(variable.VariableTableId, out var variableTable))
- {
- variableTable.Variables.Remove(variable);
- }
+ var result = await _variableAppService.DeleteAsync(variables);
- _eventService.RaiseVariableChanged(
- this, new VariableChangedEventArgs(ActionChangeType.Deleted, variable));
- }
+ // 批量删除成功后,从内存中移除变量
+ if (result)
+ {
+ foreach (var variable in variables)
+ {
+ variable.VariableTable.Variables.Remove(variable);
+ _appDataService.Variables.TryRemove(variable.Id, out _);
+ _eventService.RaiseVariableChanged(
+ this, new VariableChangedEventArgs(ActionChangeType.Deleted, variable));
}
}
-
+
return result;
}
-
+
///
/// 异步加载所有变量数据到内存中。
///
public async Task LoadAllVariablesAsync()
{
- _appStorageService.Variables.Clear();
+ _appDataService.Variables.Clear();
var variables = await _variableAppService.GetAllVariablesAsync();
// 将变量添加到安全字典
foreach (var variable in variables)
{
- if (_appStorageService.VariableTables.TryGetValue(variable.VariableTableId,
- out var variableTable))
+ if (_appDataService.VariableTables.TryGetValue(variable.VariableTableId,
+ out var variableTable))
{
variable.VariableTable = variableTable;
variableTable.Variables.Add(variable);
}
- _appStorageService.Variables.TryAdd(variable.Id, variable);
+ _appDataService.Variables.TryAdd(variable.Id, variable);
}
}
-
}
\ No newline at end of file
diff --git a/DMS.Application/Services/Management/VariableTableManagementService.cs b/DMS.Application/Services/Management/VariableTableManagementService.cs
index 536b186..e651279 100644
--- a/DMS.Application/Services/Management/VariableTableManagementService.cs
+++ b/DMS.Application/Services/Management/VariableTableManagementService.cs
@@ -14,7 +14,7 @@ namespace DMS.Application.Services.Management;
public class VariableTableManagementService : IVariableTableManagementService
{
private readonly IVariableTableAppService _variableTableAppService;
- private readonly IAppStorageService _appStorageService;
+ private readonly IAppDataService _appDataService;
private readonly IEventService _eventService;
///
@@ -23,11 +23,11 @@ public class VariableTableManagementService : IVariableTableManagementService
public event EventHandler OnVariableTableChanged;
public VariableTableManagementService(IVariableTableAppService variableTableAppService,
- IAppStorageService appStorageService,
+ IAppDataService appStorageService,
IEventService eventService)
{
_variableTableAppService = variableTableAppService;
- _appStorageService = appStorageService;
+ _appDataService = appStorageService;
_eventService = eventService;
}
@@ -58,8 +58,8 @@ public class VariableTableManagementService : IVariableTableManagementService
if (result?.VariableTable != null)
{
// 添加null检查
- if (_appStorageService.Devices != null &&
- _appStorageService.Devices.TryGetValue(result.VariableTable.DeviceId, out var device))
+ if (_appDataService.Devices != null &&
+ _appDataService.Devices.TryGetValue(result.VariableTable.DeviceId, out var device))
{
// 确保VariableTables不为null
if (device.VariableTables == null)
@@ -73,7 +73,7 @@ public class VariableTableManagementService : IVariableTableManagementService
}
// 确保_variableTables和result.VariableTable不为null
- if (_appStorageService.VariableTables.TryAdd(result.VariableTable.Id, result.VariableTable))
+ if (_appDataService.VariableTables.TryAdd(result.VariableTable.Id, result.VariableTable))
{
_eventService.RaiseVariableTableChanged(this, new VariableTableChangedEventArgs(
DataChangeType.Added,
@@ -94,7 +94,7 @@ public class VariableTableManagementService : IVariableTableManagementService
// 更新成功后,更新内存中的变量表
if (result > 0 && variableTable != null)
{
- _appStorageService.VariableTables.AddOrUpdate(variableTable.Id, variableTable, (key, oldValue) => variableTable);
+ _appDataService.VariableTables.AddOrUpdate(variableTable.Id, variableTable, (key, oldValue) => variableTable);
_eventService.RaiseVariableTableChanged(this, new VariableTableChangedEventArgs(
DataChangeType.Updated,
variableTable));
@@ -113,9 +113,9 @@ public class VariableTableManagementService : IVariableTableManagementService
// 删除成功后,从内存中移除变量表
if (result )
{
- if (_appStorageService.VariableTables.TryRemove(id, out var variableTable))
+ if (_appDataService.VariableTables.TryRemove(id, out var variableTable))
{
- if (variableTable != null && _appStorageService.Devices.TryGetValue(variableTable.DeviceId, out var device))
+ if (variableTable != null && _appDataService.Devices.TryGetValue(variableTable.DeviceId, out var device))
{
if (device.VariableTables != null)
device.VariableTables.Remove(variableTable);
@@ -136,12 +136,12 @@ public class VariableTableManagementService : IVariableTableManagementService
///
public async Task LoadAllVariableTablesAsync()
{
- _appStorageService.VariableTables.Clear();
+ _appDataService.VariableTables.Clear();
var variableTables = await _variableTableAppService.GetAllVariableTablesAsync();
// 建立变量表与变量的关联
foreach (var variableTable in variableTables)
{
- if (_appStorageService.Devices.TryGetValue(variableTable.DeviceId, out var device))
+ if (_appDataService.Devices.TryGetValue(variableTable.DeviceId, out var device))
{
variableTable.Device = device;
if (device.VariableTables == null)
@@ -150,7 +150,7 @@ public class VariableTableManagementService : IVariableTableManagementService
}
// 将变量表添加到安全字典
- _appStorageService.VariableTables.TryAdd(variableTable.Id, variableTable);
+ _appDataService.VariableTables.TryAdd(variableTable.Id, variableTable);
}
}
diff --git a/DMS.Application/Services/Monitoring/DeviceMonitoringService.cs b/DMS.Application/Services/Monitoring/DeviceMonitoringService.cs
index e64b1c4..320f8ed 100644
--- a/DMS.Application/Services/Monitoring/DeviceMonitoringService.cs
+++ b/DMS.Application/Services/Monitoring/DeviceMonitoringService.cs
@@ -17,7 +17,7 @@ public class DeviceMonitoringService : IDeviceMonitoringService, IDisposable
{
private readonly ILogger _logger;
private readonly IEventService _eventService;
- private readonly IAppStorageService _appStorageService;
+ private readonly IAppDataService _appDataService;
private readonly IAppCenterService _appCenterService;
@@ -27,12 +27,12 @@ public class DeviceMonitoringService : IDeviceMonitoringService, IDisposable
/// 日志记录器
/// 设备应用服务
public DeviceMonitoringService(ILogger logger, IEventService eventService,
- IAppStorageService appStorageService,
+ IAppDataService appStorageService,
IAppCenterService appCenterService)
{
_logger = logger;
_eventService = eventService;
- _appStorageService = appStorageService;
+ _appDataService = appStorageService;
_appCenterService = appCenterService;
_eventService.OnDeviceStateChanged += OnDeviceStateChanged;
}
@@ -42,7 +42,7 @@ public class DeviceMonitoringService : IDeviceMonitoringService, IDisposable
// 只处理激活状态变化事件
if (e.StateType == Core.Enums.DeviceStateType.Active)
{
- if (_appStorageService.Devices.TryGetValue(e.DeviceId, out var device))
+ if (_appDataService.Devices.TryGetValue(e.DeviceId, out var device))
{
// 更新设备激活状态 - 同时更新数据库和内存
_ = Task.Run(async () =>
diff --git a/DMS.Core/Interfaces/Repositories/IMenuRepository.cs b/DMS.Core/Interfaces/Repositories/IMenuRepository.cs
index 0cf8332..7198e46 100644
--- a/DMS.Core/Interfaces/Repositories/IMenuRepository.cs
+++ b/DMS.Core/Interfaces/Repositories/IMenuRepository.cs
@@ -6,8 +6,5 @@ namespace DMS.Core.Interfaces.Repositories
{
public interface IMenuRepository:IBaseRepository
{
- Task DeleteMenuTreeByIdAsync(int id);
- Task DeleteMenuTreeByTargetIdAsync(MenuType menuType, int targetId);
- Task GetMenuByTargetIdAsync(MenuType menuType, int targetId);
}
}
\ No newline at end of file
diff --git a/DMS.Infrastructure/Repositories/AlarmHistoryRepository.cs b/DMS.Infrastructure/Repositories/AlarmHistoryRepository.cs
index 713e34c..aeb78c0 100644
--- a/DMS.Infrastructure/Repositories/AlarmHistoryRepository.cs
+++ b/DMS.Infrastructure/Repositories/AlarmHistoryRepository.cs
@@ -31,7 +31,7 @@ namespace DMS.Infrastructure.Repositories
/// 受影响的行数。
public async Task DeleteAsync(AlarmHistory entity)
{
- return await base.DeleteAsync(new List { entity });
+ return await base.DeleteAsync( entity);
}
///
diff --git a/DMS.Infrastructure/Repositories/BaseRepository.cs b/DMS.Infrastructure/Repositories/BaseRepository.cs
index b5c986a..416843c 100644
--- a/DMS.Infrastructure/Repositories/BaseRepository.cs
+++ b/DMS.Infrastructure/Repositories/BaseRepository.cs
@@ -83,6 +83,16 @@ public abstract class BaseRepository
_logger.LogInformation($"DeleteAsync Batch {typeof(TEntity).Name}, Count: {entities.Count}, 耗时:{stopwatch.ElapsedMilliseconds}ms");
return result;
}
+ ///
+ /// 异步批量删除实体。
+ ///
+ /// 要删除的实体列表。
+ /// 返回受影响的行数。
+ public virtual async Task DeleteAsync(TEntity entity)
+ {
+ return await _dbContext.GetInstance().Deleteable(entity)
+ .ExecuteCommandAsync(); ;
+ }
///
@@ -171,18 +181,12 @@ public abstract class BaseRepository
public async Task> AddAsync(List entities)
{
- var stopwatch = new Stopwatch();
- stopwatch.Start();
var retrunEntities = new List();
foreach (var entity in entities)
{
var result = await _dbContext.GetInstance().Insertable(entity).ExecuteReturnEntityAsync();
retrunEntities.Add(result);
}
-
- stopwatch.Stop();
- _logger.LogInformation($"AddBatchAsync {typeof(TEntity).Name}耗时:{stopwatch.ElapsedMilliseconds}ms");
-
return retrunEntities;
}
diff --git a/DMS.Infrastructure/Repositories/DeviceRepository.cs b/DMS.Infrastructure/Repositories/DeviceRepository.cs
index 9b81af3..9c04e4a 100644
--- a/DMS.Infrastructure/Repositories/DeviceRepository.cs
+++ b/DMS.Infrastructure/Repositories/DeviceRepository.cs
@@ -73,7 +73,7 @@ public class DeviceRepository : BaseRepository, IDeviceRepository
///
/// 要删除的设备实体。
/// 受影响的行数。
- public async Task DeleteAsync(Device model) => await base.DeleteAsync(new List { _mapper.Map(model) });
+ public async Task DeleteAsync(Device model) => await base.DeleteAsync(_mapper.Map(model));
public async Task> AddAsync(List entities)
diff --git a/DMS.Infrastructure/Repositories/MenuRepository.cs b/DMS.Infrastructure/Repositories/MenuRepository.cs
index 1a303cb..5e417ac 100644
--- a/DMS.Infrastructure/Repositories/MenuRepository.cs
+++ b/DMS.Infrastructure/Repositories/MenuRepository.cs
@@ -29,20 +29,6 @@ public class MenuRepository : BaseRepository, IMenuRepository
_mapper = mapper;
}
- ///
- /// 异步获取所有菜单树结构。
- ///
- /// 包含所有菜单树结构的列表。
- public async Task> GetMenuTreesAsync()
- {
- var stopwatch = new Stopwatch();
- stopwatch.Start();
- var dbMenuTree = await _dbContext.GetInstance().Queryable()
- .ToTreeAsync(dm => dm.Childrens, dm => dm.ParentId, 0);
- stopwatch.Stop();
- _logger.LogInformation($"获取菜单树耗时:{stopwatch.ElapsedMilliseconds}ms");
- return _mapper.Map>(dbMenuTree);
- }
///
/// 异步根据ID获取单个菜单。
@@ -88,64 +74,21 @@ public class MenuRepository : BaseRepository, IMenuRepository
///
/// 要删除的菜单实体。
/// 受影响的行数。
- public async Task DeleteAsync(MenuBean entity) => await base.DeleteAsync(new List { _mapper.Map(entity) });
-
-
-
- ///
- /// 异步根据菜单ID删除菜单树(包括子菜单)。
- ///
- /// 要删除菜单树的根菜单ID。
- /// 受影响的行数。
- public async Task DeleteMenuTreeByIdAsync(int id)
+ public async Task DeleteAsync(MenuBean entity)
{
- var stopwatch = new Stopwatch();
- stopwatch.Start();
- int delConut = 0;
- var childList = await _dbContext.GetInstance().Queryable()
- .ToChildListAsync(c => c.ParentId, id);
- delConut = await _dbContext.GetInstance().Deleteable(childList)
- .ExecuteCommandAsync();
- delConut += await _dbContext.GetInstance().Deleteable()
- .Where(m => m.Id == id)
- .ExecuteCommandAsync();
- stopwatch.Stop();
- _logger.LogInformation($"Delete {typeof(DbMenu)},ID={id},耗时:{stopwatch.ElapsedMilliseconds}ms");
- return delConut;
+ var menuToDeleteList =new List();
+ foreach (var item in entity.Children)
+ {
+ menuToDeleteList.Add(item);
+ foreach (var menu in item.Children)
+ {
+ menuToDeleteList.Add(menu);
+ }
+ }
+ menuToDeleteList.Add(entity);
+ return await base.DeleteAsync( _mapper.Map>(menuToDeleteList) );
}
- ///
- /// 异步根据菜单类型和目标ID删除菜单树。
- ///
- /// 菜单类型。
- /// 目标ID。
- /// 受影响的行数。
- public async Task DeleteMenuTreeByTargetIdAsync(MenuType menuType, int targetId)
- {
- var stopwatch = new Stopwatch();
- stopwatch.Start();
- var menu = await _dbContext.GetInstance().Queryable().FirstAsync(m => m.MenuType == menuType && m.TargetId == targetId);
- if (menu == null) return 0;
- var childList = await _dbContext.GetInstance().Queryable()
- .ToChildListAsync(c => c.ParentId, menu.Id);
- var delConut = await _dbContext.GetInstance().Deleteable(childList)
- .ExecuteCommandAsync();
- stopwatch.Stop();
- _logger.LogInformation($"Delete {typeof(DbMenu)},TargetId={targetId},耗时:{stopwatch.ElapsedMilliseconds}ms");
- return delConut;
- }
-
- ///
- /// 异步根据菜单类型和目标ID获取菜单。
- ///
- /// 菜单类型。
- /// 目标ID。
- /// 对应的菜单实体,如果不存在则为null。
- public async Task GetMenuByTargetIdAsync(MenuType menuType, int targetId)
- {
- var dbMenu = await _dbContext.GetInstance().Queryable().FirstAsync(m => m.MenuType == menuType && m.TargetId == targetId);
- return _mapper.Map(dbMenu);
- }
public async Task> AddAsync(List entities)
@@ -165,7 +108,7 @@ public class MenuRepository : BaseRepository, IMenuRepository
var dbEntities = _mapper.Map>(entities);
return await base.UpdateAsync(dbEntities);
}
-
+
///
/// 异步根据实体列表批量删除菜单。
@@ -174,6 +117,8 @@ public class MenuRepository : BaseRepository, IMenuRepository
/// 受影响的行数。
public async Task DeleteAsync(List entities)
{
+ var deleteList = entities.SelectMany(c => c.Children).ToList();
+ deleteList.AddRange(entities);
var dbEntities = _mapper.Map>(entities);
return await base.DeleteAsync(dbEntities);
}
diff --git a/DMS.Infrastructure/Repositories/MqttAliasRepository.cs b/DMS.Infrastructure/Repositories/MqttAliasRepository.cs
index 3d035fd..b8d3af4 100644
--- a/DMS.Infrastructure/Repositories/MqttAliasRepository.cs
+++ b/DMS.Infrastructure/Repositories/MqttAliasRepository.cs
@@ -75,7 +75,7 @@ public class MqttAliasRepository : BaseRepository, IMqttAliasReposi
///
/// 要删除的变量与MQTT别名关联实体。
/// 受影响的行数。
- public async Task DeleteAsync(MqttAlias entity) => await base.DeleteAsync(new List { _mapper.Map(entity) });
+ public async Task DeleteAsync(MqttAlias entity) => await base.DeleteAsync(_mapper.Map(entity));
diff --git a/DMS.Infrastructure/Repositories/MqttServerRepository.cs b/DMS.Infrastructure/Repositories/MqttServerRepository.cs
index 7022fb6..e9ac703 100644
--- a/DMS.Infrastructure/Repositories/MqttServerRepository.cs
+++ b/DMS.Infrastructure/Repositories/MqttServerRepository.cs
@@ -72,7 +72,7 @@ public class MqttServerRepository : BaseRepository, IMqttServerRep
///
/// 要删除的MQTT服务器实体。
/// 受影响的行数。
- public async Task DeleteAsync(MqttServer entity) => await base.DeleteAsync(new List { _mapper.Map(entity) });
+ public async Task DeleteAsync(MqttServer entity) => await base.DeleteAsync(_mapper.Map(entity));
diff --git a/DMS.Infrastructure/Repositories/NlogRepository.cs b/DMS.Infrastructure/Repositories/NlogRepository.cs
index 350e50e..139570e 100644
--- a/DMS.Infrastructure/Repositories/NlogRepository.cs
+++ b/DMS.Infrastructure/Repositories/NlogRepository.cs
@@ -97,7 +97,7 @@ public class NlogRepository : BaseRepository, INlogRepository
public new async Task DeleteAsync(Core.Models.Nlog entity)
{
var dbEntity = _mapper.Map(entity);
- return await base.DeleteAsync(new List { dbEntity });
+ return await base.DeleteAsync(dbEntity);
}
diff --git a/DMS.Infrastructure/Repositories/TriggerRepository.cs b/DMS.Infrastructure/Repositories/TriggerRepository.cs
index 0373c33..c111d54 100644
--- a/DMS.Infrastructure/Repositories/TriggerRepository.cs
+++ b/DMS.Infrastructure/Repositories/TriggerRepository.cs
@@ -82,7 +82,7 @@ namespace DMS.Infrastructure.Repositories
/// 受影响的行数。
public async Task DeleteAsync(Trigger entity)
{
- return await base.DeleteAsync(new List { _mapper.Map(entity) });
+ return await base.DeleteAsync(_mapper.Map(entity));
}
diff --git a/DMS.Infrastructure/Repositories/TriggerVariableRepository.cs b/DMS.Infrastructure/Repositories/TriggerVariableRepository.cs
index 8aa870a..0f2bf5a 100644
--- a/DMS.Infrastructure/Repositories/TriggerVariableRepository.cs
+++ b/DMS.Infrastructure/Repositories/TriggerVariableRepository.cs
@@ -75,7 +75,7 @@ public class TriggerVariableRepository : BaseRepository, ITri
///
/// 要删除的触发器与变量关联实体。
/// 受影响的行数。
- public async Task DeleteAsync(TriggerVariable entity) => await base.DeleteAsync(new List { _mapper.Map(entity) });
+ public async Task DeleteAsync(TriggerVariable entity) => await base.DeleteAsync(_mapper.Map(entity));
diff --git a/DMS.Infrastructure/Repositories/UserRepository.cs b/DMS.Infrastructure/Repositories/UserRepository.cs
index c5abf7f..47cf5af 100644
--- a/DMS.Infrastructure/Repositories/UserRepository.cs
+++ b/DMS.Infrastructure/Repositories/UserRepository.cs
@@ -75,7 +75,7 @@ public class UserRepository : BaseRepository, IUserRepository
///
/// 要删除的用户实体。
/// 受影响的行数。
- public async Task DeleteAsync(User entity) => await base.DeleteAsync(new List { _mapper.Map(entity) });
+ public async Task DeleteAsync(User entity) => await base.DeleteAsync(_mapper.Map(entity));
public async Task UpdateAsync(List entities)
{
diff --git a/DMS.Infrastructure/Repositories/VariableHistoryRepository.cs b/DMS.Infrastructure/Repositories/VariableHistoryRepository.cs
index 52f3c0b..ef64d66 100644
--- a/DMS.Infrastructure/Repositories/VariableHistoryRepository.cs
+++ b/DMS.Infrastructure/Repositories/VariableHistoryRepository.cs
@@ -74,7 +74,7 @@ public class VariableHistoryRepository : BaseRepository, IVar
///
/// 要删除的变量历史实体。
/// 受影响的行数。
- public async Task DeleteAsync(VariableHistory entity) => await base.DeleteAsync(new List { _mapper.Map(entity) });
+ public async Task DeleteAsync(VariableHistory entity) => await base.DeleteAsync(_mapper.Map(entity));
public async Task UpdateAsync(List entities)
{
diff --git a/DMS.Infrastructure/Repositories/VariableRepository.cs b/DMS.Infrastructure/Repositories/VariableRepository.cs
index e536b1b..fec34a0 100644
--- a/DMS.Infrastructure/Repositories/VariableRepository.cs
+++ b/DMS.Infrastructure/Repositories/VariableRepository.cs
@@ -73,7 +73,7 @@ public class VariableRepository : BaseRepository, IVariableRepositor
///
/// 要删除的变量实体。
/// 受影响的行数。
- public async Task DeleteAsync(Variable entity) => await base.DeleteAsync(new List { _mapper.Map(entity) });
+ public async Task DeleteAsync(Variable entity) => await base.DeleteAsync(_mapper.Map(entity));
///
diff --git a/DMS.Infrastructure/Repositories/VariableTableRepository.cs b/DMS.Infrastructure/Repositories/VariableTableRepository.cs
index 5a51603..85b7167 100644
--- a/DMS.Infrastructure/Repositories/VariableTableRepository.cs
+++ b/DMS.Infrastructure/Repositories/VariableTableRepository.cs
@@ -93,13 +93,12 @@ public class VariableTableRepository : BaseRepository, IVariabl
public async Task DeleteAsync(VariableTable entity)
{
//删除变量表中的所有变量
- await _variableRepository.DeleteByVariableTableIdAsync(entity.Id);
+ await _variableRepository.DeleteAsync(entity.Variables);
//删除变量表
- return await base.DeleteAsync(new List { _mapper.Map(entity) });
+ return await base.DeleteAsync( _mapper.Map(entity));
}
-
public async Task> AddAsync(List entities)
{
var dbEntities = _mapper.Map>(entities);
@@ -127,6 +126,18 @@ public class VariableTableRepository : BaseRepository, IVariabl
/// 受影响的行数。
public async Task DeleteAsync(List entities)
{
+ //删除所有变量
+ List deleteVariableList = new List();
+ foreach (var table in entities)
+ {
+ foreach (var variable in table.Variables)
+ {
+ deleteVariableList.Add(variable);
+ }
+
+ }
+ await _variableRepository.DeleteAsync(deleteVariableList);
+
var dbEntities = _mapper.Map>(entities);
return await base.DeleteAsync(dbEntities);
}
diff --git a/DMS.Infrastructure/Services/Mqtt/MqttBackgroundService.cs b/DMS.Infrastructure/Services/Mqtt/MqttBackgroundService.cs
index efea6cd..0395f00 100644
--- a/DMS.Infrastructure/Services/Mqtt/MqttBackgroundService.cs
+++ b/DMS.Infrastructure/Services/Mqtt/MqttBackgroundService.cs
@@ -17,7 +17,7 @@ namespace DMS.Infrastructure.Services.Mqtt
private readonly ILogger _logger;
private readonly IMqttServiceManager _mqttServiceManager;
private readonly IEventService _eventService;
- private readonly IAppStorageService _appStorageService;
+ private readonly IAppDataService _appDataService;
private readonly IAppCenterService _appCenterService;
private readonly ConcurrentDictionary _mqttServers;
private readonly SemaphoreSlim _reloadSemaphore = new(0);
@@ -26,13 +26,13 @@ namespace DMS.Infrastructure.Services.Mqtt
ILogger logger,
IMqttServiceManager mqttServiceManager,
IEventService eventService,
- IAppStorageService appStorageService,
+ IAppDataService appStorageService,
IAppCenterService appCenterService)
{
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
_mqttServiceManager = mqttServiceManager ?? throw new ArgumentNullException(nameof(mqttServiceManager));
_eventService = eventService;
- _appStorageService = appStorageService;
+ _appDataService = appStorageService;
_appCenterService = appCenterService ?? throw new ArgumentNullException(nameof(appCenterService));
_mqttServers = new ConcurrentDictionary();
@@ -186,7 +186,7 @@ namespace DMS.Infrastructure.Services.Mqtt
_mqttServers.Clear();
// 从数据服务中心获取所有激活的MQTT服务器
- var mqttServers = _appStorageService.MqttServers.Values.ToList();
+ var mqttServers = _appDataService.MqttServers.Values.ToList();
foreach (var mqttServer in mqttServers)
{
diff --git a/DMS.Infrastructure/Services/OpcUa/OptimizedOpcUaBackgroundService.cs b/DMS.Infrastructure/Services/OpcUa/OptimizedOpcUaBackgroundService.cs
index b478696..46d77f4 100644
--- a/DMS.Infrastructure/Services/OpcUa/OptimizedOpcUaBackgroundService.cs
+++ b/DMS.Infrastructure/Services/OpcUa/OptimizedOpcUaBackgroundService.cs
@@ -15,7 +15,7 @@ namespace DMS.Infrastructure.Services.OpcUa
public class OptimizedOpcUaBackgroundService : BackgroundService
{
private readonly IAppCenterService _appCenterService;
- private readonly IAppStorageService _appStorageService;
+ private readonly IAppDataService _appDataService;
private readonly IEventService _eventService;
private readonly IOpcUaServiceManager _opcUaServiceManager;
private readonly ILogger _logger;
@@ -23,13 +23,13 @@ namespace DMS.Infrastructure.Services.OpcUa
public OptimizedOpcUaBackgroundService(
IAppCenterService appCenterService,
- IAppStorageService appStorageService,
+ IAppDataService appStorageService,
IEventService eventService,
IOpcUaServiceManager opcUaServiceManager,
ILogger logger)
{
_appCenterService = appCenterService ?? throw new ArgumentNullException(nameof(appCenterService));
- _appStorageService = appStorageService;
+ _appDataService = appStorageService;
_opcUaServiceManager = opcUaServiceManager ?? throw new ArgumentNullException(nameof(opcUaServiceManager));
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
_eventService = eventService;
@@ -60,7 +60,7 @@ namespace DMS.Infrastructure.Services.OpcUa
if (stoppingToken.IsCancellationRequested)
break;
- if (_appStorageService.Devices.IsEmpty)
+ if (_appDataService.Devices.IsEmpty)
{
_logger.LogInformation("没有可用的OPC UA设备,等待设备列表更新...");
continue;
@@ -96,7 +96,7 @@ namespace DMS.Infrastructure.Services.OpcUa
try
{
// 获取所有活动的OPC UA设备
- var opcUaDevices = _appStorageService.Devices.Values
+ var opcUaDevices = _appDataService.Devices.Values
.Where(d => d.Protocol == ProtocolType.OpcUa )
.ToList();
diff --git a/DMS.Infrastructure/Services/S7/OptimizedS7BackgroundService.cs b/DMS.Infrastructure/Services/S7/OptimizedS7BackgroundService.cs
index 84150a3..011a04e 100644
--- a/DMS.Infrastructure/Services/S7/OptimizedS7BackgroundService.cs
+++ b/DMS.Infrastructure/Services/S7/OptimizedS7BackgroundService.cs
@@ -20,7 +20,7 @@ namespace DMS.Infrastructure.Services.S7;
public class OptimizedS7BackgroundService : BackgroundService
{
private readonly IAppCenterService _appCenterService;
- private readonly IAppStorageService _appStorageService;
+ private readonly IAppDataService _appDataService;
private readonly IEventService _eventService;
private readonly IDataProcessingService _dataProcessingService;
private readonly IS7ServiceManager _s7ServiceManager;
@@ -39,14 +39,14 @@ public class OptimizedS7BackgroundService : BackgroundService
///
public OptimizedS7BackgroundService(
IAppCenterService appCenterService,
- IAppStorageService appStorageService,
+ IAppDataService appStorageService,
IEventService eventService,
IDataProcessingService dataProcessingService,
IS7ServiceManager s7ServiceManager,
ILogger logger)
{
_appCenterService = appCenterService;
- _appStorageService = appStorageService;
+ _appDataService = appStorageService;
_eventService = eventService;
_dataProcessingService = dataProcessingService;
_s7ServiceManager = s7ServiceManager;
@@ -76,7 +76,7 @@ public class OptimizedS7BackgroundService : BackgroundService
break;
}
- if (_appStorageService.Devices.IsEmpty)
+ if (_appDataService.Devices.IsEmpty)
{
_logger.LogInformation("没有可用的S7设备,等待设备列表更新...");
continue;
@@ -124,7 +124,7 @@ public class OptimizedS7BackgroundService : BackgroundService
_variablesByPollingInterval.Clear();
_logger.LogInformation("开始加载S7变量....");
- var s7Devices = _appStorageService
+ var s7Devices = _appDataService
.Devices.Values.Where(d => d.Protocol == ProtocolType.S7 && d.IsActive == true)
.ToList();
@@ -161,7 +161,7 @@ public class OptimizedS7BackgroundService : BackgroundService
///
private async Task ConnectS7ServiceAsync(CancellationToken stoppingToken)
{
- var s7Devices = _appStorageService
+ var s7Devices = _appDataService
.Devices.Values.Where(d => d.Protocol == ProtocolType.S7 && d.IsActive == true)
.ToList();
@@ -207,7 +207,7 @@ public class OptimizedS7BackgroundService : BackgroundService
private async Task PollVariablesForDeviceAsync(S7DeviceContext context, List variables,
CancellationToken stoppingToken)
{
- if (!_appStorageService.Devices.TryGetValue(context.Device.Id, out var device))
+ if (!_appDataService.Devices.TryGetValue(context.Device.Id, out var device))
{
_logger.LogWarning($"轮询时没有找到设备ID:{context.Device.Id}");
return;
diff --git a/DMS.Infrastructure/Services/S7/S7ServiceManager.cs b/DMS.Infrastructure/Services/S7/S7ServiceManager.cs
index 7380f81..2b16bf3 100644
--- a/DMS.Infrastructure/Services/S7/S7ServiceManager.cs
+++ b/DMS.Infrastructure/Services/S7/S7ServiceManager.cs
@@ -20,7 +20,7 @@ namespace DMS.Infrastructure.Services.S7
private readonly IEventService _eventService;
private readonly IDataProcessingService _dataProcessingService;
private readonly IAppCenterService _appCenterService;
- private readonly IAppStorageService _appStorageService;
+ private readonly IAppDataService _appDataService;
private readonly IS7ServiceFactory _s7ServiceFactory;
private readonly ConcurrentDictionary _deviceContexts;
private readonly SemaphoreSlim _semaphore;
@@ -31,7 +31,7 @@ namespace DMS.Infrastructure.Services.S7
IEventService eventService,
IDataProcessingService dataProcessingService,
IAppCenterService appCenterService,
- IAppStorageService appStorageService,
+ IAppDataService appStorageService,
IS7ServiceFactory s7ServiceFactory)
{
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
@@ -40,7 +40,7 @@ namespace DMS.Infrastructure.Services.S7
= dataProcessingService ?? throw new ArgumentNullException(nameof(dataProcessingService));
_appCenterService
= appCenterService ?? throw new ArgumentNullException(nameof(appCenterService));
- _appStorageService = appStorageService;
+ _appDataService = appStorageService;
_s7ServiceFactory = s7ServiceFactory ?? throw new ArgumentNullException(nameof(s7ServiceFactory));
_deviceContexts = new ConcurrentDictionary();
_semaphore = new SemaphoreSlim(10, 10); // 默认最大并发连接数为10
@@ -54,7 +54,7 @@ namespace DMS.Infrastructure.Services.S7
// if (_deviceContexts.TryGetValue(e.DeviceId, out var s7DeviceContext))
// {
- // var variables = _appStorageService.Variables.Values.Where(v => e.VariableIds.Contains(v.Id))
+ // var variables = _appDataService.Variables.Values.Where(v => e.VariableIds.Contains(v.Id))
// .ToList();
// foreach (var variable in variables)
// {
diff --git a/DMS.WPF/App.xaml b/DMS.WPF/App.xaml
index cba873f..26e2b74 100644
--- a/DMS.WPF/App.xaml
+++ b/DMS.WPF/App.xaml
@@ -2,11 +2,10 @@
x:Class="DMS.WPF.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ xmlns:converters="clr-namespace:DMS.WPF.Converters"
+ xmlns:localConverters="clr-namespace:DMS.WPF.Converters"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:triggers="clr-namespace:DMS.Core.Models.Triggers;assembly=DMS.Core"
- xmlns:converters="clr-namespace:DMS.WPF.Converters"
- xmlns:localConverters="clr-namespace:DMS.WPF.Converters"
-
xmlns:ui="http://schemas.inkore.net/lib/ui/wpf/modern">
@@ -19,31 +18,35 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
/Assets/Fonts/materialdesignicons-webfont.ttf#Material Design Icons
-
-
-
+
+
+
-
+
-
+
diff --git a/DMS.WPF/App.xaml.cs b/DMS.WPF/App.xaml.cs
index 7596cd7..b36d55e 100644
--- a/DMS.WPF/App.xaml.cs
+++ b/DMS.WPF/App.xaml.cs
@@ -45,6 +45,7 @@ using SkiaSharp;
using SqlSugar;
using ILogger = Microsoft.Extensions.Logging.ILogger;
using LogLevel = Microsoft.Extensions.Logging.LogLevel;
+using DMS.WPF.Services.ViewService;
namespace DMS.WPF;
@@ -259,7 +260,7 @@ public partial class App : System.Windows.Application
services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
- services.AddSingleton();
+ services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
@@ -303,19 +304,19 @@ 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();
+ services.AddSingleton();
services.AddSingleton();
services.AddSingleton();
diff --git a/DMS.WPF/DMS.WPF.csproj b/DMS.WPF/DMS.WPF.csproj
index 514f9f2..9cabeb9 100644
--- a/DMS.WPF/DMS.WPF.csproj
+++ b/DMS.WPF/DMS.WPF.csproj
@@ -187,10 +187,4 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/DMS.WPF/Interfaces/IDeviceDataService.cs b/DMS.WPF/Interfaces/IDeviceDataService.cs
index f102be5..5a050d9 100644
--- a/DMS.WPF/Interfaces/IDeviceDataService.cs
+++ b/DMS.WPF/Interfaces/IDeviceDataService.cs
@@ -27,7 +27,7 @@ public interface IDeviceDataService
///
/// 删除设备。
///
- Task DeleteDevice(DeviceItem device);
+ Task DeleteAsync(DeviceItem device);
///
/// 更新设备。
diff --git a/DMS.WPF/Interfaces/IMenuViewService.cs b/DMS.WPF/Interfaces/IMenuViewService.cs
index 07e9a76..873931d 100644
--- a/DMS.WPF/Interfaces/IMenuViewService.cs
+++ b/DMS.WPF/Interfaces/IMenuViewService.cs
@@ -18,7 +18,7 @@ public interface IMenuViewService
///
/// 删除菜单项。
///
- Task DeleteMenuItem(MenuItem? MenuItem);
+ void DeleteMenuToView(MenuItem? MenuItem);
void LoadAllMenus();
Task UpdateMenuItem(MenuItem MenuItem);
diff --git a/DMS.WPF/Interfaces/IVariableTableDataService.cs b/DMS.WPF/Interfaces/IVariableTableViewService.cs
similarity index 91%
rename from DMS.WPF/Interfaces/IVariableTableDataService.cs
rename to DMS.WPF/Interfaces/IVariableTableViewService.cs
index 4d1ebb3..49ba50c 100644
--- a/DMS.WPF/Interfaces/IVariableTableDataService.cs
+++ b/DMS.WPF/Interfaces/IVariableTableViewService.cs
@@ -5,7 +5,7 @@ using DMS.WPF.ItemViewModel;
namespace DMS.WPF.Interfaces;
-public interface IVariableTableDataService
+public interface IVariableTableViewService
{
void LoadAllVariableTables();
diff --git a/DMS.WPF/Interfaces/IVariableDataService.cs b/DMS.WPF/Interfaces/IVariableViewService.cs
similarity index 76%
rename from DMS.WPF/Interfaces/IVariableDataService.cs
rename to DMS.WPF/Interfaces/IVariableViewService.cs
index 6d20a33..6738835 100644
--- a/DMS.WPF/Interfaces/IVariableDataService.cs
+++ b/DMS.WPF/Interfaces/IVariableViewService.cs
@@ -8,7 +8,7 @@ namespace DMS.WPF.Interfaces;
///
/// 变量数据服务接口。
///
-public interface IVariableDataService
+public interface IVariableViewService
{
///
@@ -40,4 +40,10 @@ public interface IVariableDataService
/// 删除变量。
///
void DeleteVariable(int id);
+
+ Task DeleteAsync(List deleteList);
+
+
+ List CheckExistingVariables(List importedVariables, DeviceItem device);
+ Task AddAsync(List variableItems,VariableTableItem variableTable);
}
\ No newline at end of file
diff --git a/DMS.WPF/Interfaces/IWPFDataService.cs b/DMS.WPF/Interfaces/IViewCenterService.cs
similarity index 86%
rename from DMS.WPF/Interfaces/IWPFDataService.cs
rename to DMS.WPF/Interfaces/IViewCenterService.cs
index a0b3efa..5929314 100644
--- a/DMS.WPF/Interfaces/IWPFDataService.cs
+++ b/DMS.WPF/Interfaces/IViewCenterService.cs
@@ -5,7 +5,7 @@ namespace DMS.WPF.Interfaces;
///
/// 主数据服务接口。
///
-public interface IWPFDataService
+public interface IViewCenterService
{
///
/// 设备数据服务。
@@ -15,11 +15,11 @@ public interface IWPFDataService
///
/// 变量数据服务。
///
- IVariableDataService VariableDataService { get; }
+ IVariableViewService VariableDataService { get; }
///
/// 变量表数据服务。
///
- public IVariableTableDataService VariableTableDataService { get; }
+ public IVariableTableViewService VariableTableDataService { get; }
///
/// 菜单数据服务。
diff --git a/DMS.WPF/Interfaces/IWpfDataService_1.cs b/DMS.WPF/Interfaces/IViewDataService.cs
similarity index 97%
rename from DMS.WPF/Interfaces/IWpfDataService_1.cs
rename to DMS.WPF/Interfaces/IViewDataService.cs
index f0ae24b..fdd5730 100644
--- a/DMS.WPF/Interfaces/IWpfDataService_1.cs
+++ b/DMS.WPF/Interfaces/IViewDataService.cs
@@ -5,7 +5,7 @@ using ObservableCollections;
namespace DMS.WPF.Interfaces;
-public interface IWpfDataService
+public interface IViewDataService
{
///
/// 设备列表。
diff --git a/DMS.WPF/Resources/DevicesItemTemplateDictionary.xaml b/DMS.WPF/Resources/DevicesItemTemplateDictionary.xaml
index 63b9319..b43065e 100644
--- a/DMS.WPF/Resources/DevicesItemTemplateDictionary.xaml
+++ b/DMS.WPF/Resources/DevicesItemTemplateDictionary.xaml
@@ -1,5 +1 @@
-
-
-
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/DMS.WPF/Services/DataEventService.cs b/DMS.WPF/Services/DataEventService.cs
index 1b16a76..041bcaf 100644
--- a/DMS.WPF/Services/DataEventService.cs
+++ b/DMS.WPF/Services/DataEventService.cs
@@ -21,26 +21,26 @@ namespace DMS.WPF.Services;
public class DataEventService : IDataEventService
{
private readonly IMapper _mapper;
- private readonly IWpfDataService _dataStorageService;
+ private readonly IViewDataService _viewDataService;
private readonly IEventService _eventService;
private readonly INotificationService _notificationService;
private readonly IAppCenterService _appCenterService;
- private readonly IWPFDataService _wpfDataService;
+ private readonly IViewCenterService _wpfDataService;
private readonly ILogger _logger;
///
/// DataEventService类的构造函数。
///
public DataEventService(IMapper mapper,
- IWpfDataService dataStorageService,
+ IViewDataService dataStorageService,
IEventService eventService,
INotificationService notificationService,
IAppCenterService appCenterService,
- IWPFDataService wpfDataService,
+ IViewCenterService wpfDataService,
ILogger logger)
{
_mapper = mapper;
- _dataStorageService = dataStorageService;
+ _viewDataService = dataStorageService;
_eventService = eventService;
_notificationService = notificationService;
_appCenterService = appCenterService;
@@ -68,7 +68,7 @@ public class DataEventService : IDataEventService
App.Current.Dispatcher.BeginInvoke(new Action(() =>
{
//// 查找并更新对应的变量
- if (_dataStorageService.MqttServers.TryGetValue(e.MqttServer.Id, out var mqttServerItem))
+ if (_viewDataService.MqttServers.TryGetValue(e.MqttServer.Id, out var mqttServerItem))
{
if (e.ChangeType == ActionChangeType.Updated)
{
@@ -170,7 +170,7 @@ public class DataEventService : IDataEventService
App.Current.Dispatcher.BeginInvoke(new Action(() =>
{
// 查找并更新对应的变量
- if (_dataStorageService.Variables.TryGetValue(e.Variable.Id,out var variableToUpdate))
+ if (_viewDataService.Variables.TryGetValue(e.Variable.Id,out var variableToUpdate))
{
variableToUpdate.DataValue = e.Variable.DataValue;
variableToUpdate.DisplayValue = e.Variable.DisplayValue;
diff --git a/DMS.WPF/Services/LogDataService.cs b/DMS.WPF/Services/LogDataService.cs
index cb1655f..5dc832d 100644
--- a/DMS.WPF/Services/LogDataService.cs
+++ b/DMS.WPF/Services/LogDataService.cs
@@ -16,8 +16,8 @@ namespace DMS.WPF.Services;
public class LogDataService : ILogDataService
{
private readonly IMapper _mapper;
- private readonly IWpfDataService _dataStorageService;
- private readonly IAppStorageService _appStorageService;
+ private readonly IViewDataService _viewDataService;
+ private readonly IAppDataService _appDataService;
@@ -26,17 +26,17 @@ public class LogDataService : ILogDataService
///
/// AutoMapper 实例。
/// 数据服务中心实例。
- public LogDataService(IMapper mapper,IWpfDataService dataStorageService, IAppStorageService appStorageService)
+ public LogDataService(IMapper mapper,IViewDataService dataStorageService, IAppDataService appStorageService)
{
_mapper = mapper;
- _dataStorageService = dataStorageService;
- _appStorageService = appStorageService;
+ _viewDataService = dataStorageService;
+ _appDataService = appStorageService;
}
public void LoadAllLog()
{
// 加载日志数据
- _dataStorageService.Nlogs = _mapper.Map>(_appStorageService.Nlogs.Values);
+ _viewDataService.Nlogs = _mapper.Map>(_appDataService.Nlogs.Values);
}
///
@@ -50,20 +50,20 @@ public class LogDataService : ILogDataService
switch (e.ChangeType)
{
case DataChangeType.Added:
- _dataStorageService.Nlogs.Add(_mapper.Map(e.Nlog));
+ _viewDataService.Nlogs.Add(_mapper.Map(e.Nlog));
break;
case DataChangeType.Updated:
- var existingLog = _dataStorageService.Nlogs.FirstOrDefault(l => l.Id == e.Nlog.Id);
+ var existingLog = _viewDataService.Nlogs.FirstOrDefault(l => l.Id == e.Nlog.Id);
if (existingLog != null)
{
_mapper.Map(e.Nlog, existingLog);
}
break;
case DataChangeType.Deleted:
- var logToRemove = _dataStorageService.Nlogs.FirstOrDefault(l => l.Id == e.Nlog.Id);
+ var logToRemove = _viewDataService.Nlogs.FirstOrDefault(l => l.Id == e.Nlog.Id);
if (logToRemove != null)
{
- _dataStorageService.Nlogs.Remove(logToRemove);
+ _viewDataService.Nlogs.Remove(logToRemove);
}
break;
}
diff --git a/DMS.WPF/Services/MenuViewService.cs b/DMS.WPF/Services/MenuViewService.cs
index 020f9d3..9339179 100644
--- a/DMS.WPF/Services/MenuViewService.cs
+++ b/DMS.WPF/Services/MenuViewService.cs
@@ -16,8 +16,8 @@ namespace DMS.WPF.Services;
public class MenuViewService : IMenuViewService
{
private readonly IMapper _mapper;
- private readonly IWpfDataService _wpfDataService;
- private readonly IAppStorageService _appStorageService;
+ private readonly IViewDataService _wpfDataService;
+ private readonly IAppDataService _appDataService;
private readonly IMenuManagementService _menuManagementService;
@@ -27,17 +27,17 @@ public class MenuViewService : IMenuViewService
///
/// AutoMapper 实例。
/// 数据服务中心实例。
- public MenuViewService(IMapper mapper, IWpfDataService dataStorageService, IAppStorageService appStorageService, IMenuManagementService menuManagementService)
+ public MenuViewService(IMapper mapper, IViewDataService dataStorageService, IAppDataService appStorageService, IMenuManagementService menuManagementService)
{
_mapper = mapper;
_wpfDataService = dataStorageService;
- _appStorageService = appStorageService;
+ _appDataService = appStorageService;
_menuManagementService = menuManagementService;
}
public void LoadAllMenus()
{
- _wpfDataService.Menus = _mapper.Map>(_appStorageService.Menus.Values);
+ _wpfDataService.Menus = _mapper.Map>(_appDataService.Menus.Values);
BuildMenuTrees();
}
@@ -102,6 +102,11 @@ public class MenuViewService : IMenuViewService
{
parentMenu.Children.Add(MenuItem);
}
+ //将子菜单也添加到列表中
+ foreach (var item in MenuItem.Children)
+ {
+ _wpfDataService.Menus.Add(item);
+ }
}
}
@@ -116,7 +121,7 @@ public class MenuViewService : IMenuViewService
if (menu is not null)
{
- var res = await _menuManagementService.UpdateMenuAsync(_mapper.Map(MenuItem));
+ var res = await _menuManagementService.UpdateAsync(_mapper.Map(MenuItem));
if (res > 0)
{
menu.Header = MenuItem.Header;
@@ -129,13 +134,16 @@ public class MenuViewService : IMenuViewService
///
/// 删除菜单项。
///
- public async Task DeleteMenuItem(MenuItem? MenuItem)
+ public void DeleteMenuToView(MenuItem? MenuItem)
{
if (MenuItem is null) return;
- await _menuManagementService.DeleteMenuAsync(MenuItem.Id);
-
- // 从扁平菜单列表中移除
+ foreach (var children in MenuItem.Children)
+ {
+ _wpfDataService.Menus.Remove(children);
+ }
+ MenuItem.Children.Clear();
+ // 从菜单列表中移除
_wpfDataService.Menus.Remove(MenuItem);
// 从树形结构中移除
@@ -151,7 +159,5 @@ public class MenuViewService : IMenuViewService
_wpfDataService.MenuTrees.Remove(MenuItem);
}
- // 重新构建整个菜单树以确保一致性
- BuildMenuTrees();
}
}
\ No newline at end of file
diff --git a/DMS.WPF/Services/MqttAliasDataService.cs b/DMS.WPF/Services/MqttAliasDataService.cs
index eb5478a..30de8f6 100644
--- a/DMS.WPF/Services/MqttAliasDataService.cs
+++ b/DMS.WPF/Services/MqttAliasDataService.cs
@@ -13,9 +13,9 @@ namespace DMS.WPF.Services;
public class MqttAliasDataService : IMqttAliasDataService
{
private readonly IMapper _mapper;
- private readonly IAppStorageService _appStorageService;
+ private readonly IAppDataService _appDataService;
private readonly IMqttAliasManagementService _mqttAliasManagementService;
- private readonly IWpfDataService _dataStorageService;
+ private readonly IViewDataService _viewDataService;
///
/// MqttAliasDataService类的构造函数。
@@ -25,14 +25,14 @@ public class MqttAliasDataService : IMqttAliasDataService
/// MQTT别名管理服务实例。
/// 数据存储服务实例。
public MqttAliasDataService(IMapper mapper,
- IAppStorageService appStorageService,
+ IAppDataService appStorageService,
IMqttAliasManagementService mqttAliasManagementService,
- IWpfDataService dataStorageService)
+ IViewDataService dataStorageService)
{
_mapper = mapper;
- _appStorageService = appStorageService;
+ _appDataService = appStorageService;
_mqttAliasManagementService = mqttAliasManagementService;
- _dataStorageService = dataStorageService;
+ _viewDataService = dataStorageService;
}
///
@@ -43,22 +43,22 @@ public class MqttAliasDataService : IMqttAliasDataService
try
{
// 清空现有数据
- _dataStorageService.MqttAliases.Clear();
+ _viewDataService.MqttAliases.Clear();
// 加载MQTT别名数据
- foreach (var mqttAlias in _appStorageService.MqttAliases.Values)
+ foreach (var mqttAlias in _appDataService.MqttAliases.Values)
{
MqttAliasItem mqttAliasItem = _mapper.Map(mqttAlias);
- if(_dataStorageService.MqttAliases.TryAdd(mqttAlias.Id, mqttAliasItem))
+ if(_viewDataService.MqttAliases.TryAdd(mqttAlias.Id, mqttAliasItem))
{
- if (_dataStorageService.MqttServers.TryGetValue(mqttAlias.MqttServerId,out var mqttServerItem))
+ if (_viewDataService.MqttServers.TryGetValue(mqttAlias.MqttServerId,out var mqttServerItem))
{
mqttServerItem.VariableAliases.Add(mqttAliasItem);
mqttAliasItem.MqttServer = mqttServerItem;
}
- if (_dataStorageService.Variables.TryGetValue(mqttAlias.VariableId,out var variableItem))
+ if (_viewDataService.Variables.TryGetValue(mqttAlias.VariableId,out var variableItem))
{
variableItem.MqttAliases.Add(mqttAliasItem);
mqttAliasItem.Variable = variableItem;
@@ -83,19 +83,19 @@ public class MqttAliasDataService : IMqttAliasDataService
var addMqttAlias = await _mqttAliasManagementService.AssignAliasAsync(_mapper.Map(mqttAlias));
- if (_dataStorageService.MqttAliases.ContainsKey(addMqttAlias.Id))
+ if (_viewDataService.MqttAliases.ContainsKey(addMqttAlias.Id))
{
return null;
}
mqttAlias.Id = addMqttAlias.Id;
- _dataStorageService.MqttAliases.Add(mqttAlias.Id, mqttAlias);
- if (_dataStorageService.MqttServers.TryGetValue(mqttAlias.MqttServerId, out var mqttServerItem))
+ _viewDataService.MqttAliases.Add(mqttAlias.Id, mqttAlias);
+ if (_viewDataService.MqttServers.TryGetValue(mqttAlias.MqttServerId, out var mqttServerItem))
{
mqttAlias.MqttServer = mqttServerItem;
mqttServerItem.VariableAliases.Add(mqttAlias);
}
- if (_dataStorageService.Variables.TryGetValue(mqttAlias.VariableId, out var variableItem))
+ if (_viewDataService.Variables.TryGetValue(mqttAlias.VariableId, out var variableItem))
{
mqttAlias.Variable = variableItem;
variableItem.MqttAliases.Add(mqttAlias);
@@ -114,7 +114,7 @@ public class MqttAliasDataService : IMqttAliasDataService
if (result > 0)
{
// 更新界面数据
- if (_dataStorageService.MqttAliases.TryGetValue(mqttAlias.Id, out var existingAlias))
+ if (_viewDataService.MqttAliases.TryGetValue(mqttAlias.Id, out var existingAlias))
{
// 更新现有别名的属性
existingAlias.VariableId = mqttAlias.VariableId;
@@ -138,15 +138,15 @@ public class MqttAliasDataService : IMqttAliasDataService
if (result )
{
- if (_dataStorageService.MqttServers.TryGetValue(mqttAlias.MqttServerId, out var mqttServerItem))
+ if (_viewDataService.MqttServers.TryGetValue(mqttAlias.MqttServerId, out var mqttServerItem))
{
mqttServerItem.VariableAliases.Remove(mqttAlias);
}
- if (_dataStorageService.Variables.TryGetValue(mqttAlias.VariableId, out var variableItem))
+ if (_viewDataService.Variables.TryGetValue(mqttAlias.VariableId, out var variableItem))
{
variableItem.MqttAliases.Remove(mqttAlias);
}
- _dataStorageService.MqttAliases.Remove(mqttAlias.Id, out _);
+ _viewDataService.MqttAliases.Remove(mqttAlias.Id, out _);
}
return result;
@@ -157,7 +157,7 @@ public class MqttAliasDataService : IMqttAliasDataService
///
public async Task GetMqttAliasById(int id)
{
- if (_dataStorageService.MqttAliases.TryGetValue(id, out var mqttAliasItem))
+ if (_viewDataService.MqttAliases.TryGetValue(id, out var mqttAliasItem))
{
return mqttAliasItem;
}
@@ -167,7 +167,7 @@ public class MqttAliasDataService : IMqttAliasDataService
if (mqttAlias != null)
{
var mappedItem = _mapper.Map(mqttAlias);
- _dataStorageService.MqttAliases.TryAdd(mappedItem.Id, mappedItem);
+ _viewDataService.MqttAliases.TryAdd(mappedItem.Id, mappedItem);
return mappedItem;
}
diff --git a/DMS.WPF/Services/MqttDataService.cs b/DMS.WPF/Services/MqttDataService.cs
index ffe1a07..4873fbd 100644
--- a/DMS.WPF/Services/MqttDataService.cs
+++ b/DMS.WPF/Services/MqttDataService.cs
@@ -17,11 +17,11 @@ namespace DMS.WPF.Services;
public class MqttDataService : IMqttDataService
{
private readonly IMapper _mapper;
- private readonly IAppStorageService _appStorageService;
+ private readonly IAppDataService _appDataService;
private readonly IMqttManagementService _mqttManagementService;
private readonly IMenuViewService _menuDataService;
private readonly IMenuManagementService _menuManagementServiceImpl;
- private readonly IWpfDataService _dataStorageService;
+ private readonly IViewDataService _viewDataService;
///
@@ -29,14 +29,14 @@ public class MqttDataService : IMqttDataService
///
/// AutoMapper 实例。
/// MQTT应用服务实例。
- public MqttDataService(IMapper mapper, IAppStorageService appStorageService, IMqttManagementService mqttManagementService, IMenuViewService menuDataService, IMenuManagementService menuManagementServiceImpl, IWpfDataService dataStorageService)
+ public MqttDataService(IMapper mapper, IAppDataService appStorageService, IMqttManagementService mqttManagementService, IMenuViewService menuDataService, IMenuManagementService menuManagementServiceImpl, IViewDataService dataStorageService)
{
_mapper = mapper;
- _appStorageService = appStorageService;
+ _appDataService = appStorageService;
_mqttManagementService = mqttManagementService;
_menuDataService = menuDataService;
_menuManagementServiceImpl = menuManagementServiceImpl;
- _dataStorageService = dataStorageService;
+ _viewDataService = dataStorageService;
}
///
@@ -47,9 +47,9 @@ public class MqttDataService : IMqttDataService
try
{
// 加载MQTT服务器数据
- foreach (var mqttServer in _appStorageService.MqttServers.Values)
+ foreach (var mqttServer in _appDataService.MqttServers.Values)
{
- _dataStorageService.MqttServers.TryAdd(mqttServer.Id, _mapper.Map(mqttServer));
+ _viewDataService.MqttServers.TryAdd(mqttServer.Id, _mapper.Map(mqttServer));
}
}
@@ -71,10 +71,10 @@ public class MqttDataService : IMqttDataService
MqttServerItem mqttServerItem = _mapper.Map(addMqttServer);
- _dataStorageService.MqttServers.Add(mqttServerItem.Id, mqttServerItem);
+ _viewDataService.MqttServers.Add(mqttServerItem.Id, mqttServerItem);
- var mqttRootMenu = _dataStorageService.Menus.FirstOrDefault(m => m.Header == "Mqtt服务器");
+ var mqttRootMenu = _viewDataService.Menus.FirstOrDefault(m => m.Header == "Mqtt服务器");
if (mqttRootMenu is not null)
{
@@ -104,7 +104,7 @@ public class MqttDataService : IMqttDataService
if (result > 0)
{
// 更新菜单项
- var menu = _dataStorageService.Menus.FirstOrDefault(m => m.MenuType == MenuType.MqttServerMenu && m.TargetId == mqttServer.Id);
+ var menu = _viewDataService.Menus.FirstOrDefault(m => m.MenuType == MenuType.MqttServerMenu && m.TargetId == mqttServer.Id);
if (menu != null)
{
// 更新菜单标题
@@ -112,7 +112,7 @@ public class MqttDataService : IMqttDataService
// 使用菜单管理服务更新菜单
var menuDto = _mapper.Map(menu);
- await _menuManagementServiceImpl.UpdateMenuAsync(menuDto);
+ await _menuManagementServiceImpl.UpdateAsync(menuDto);
}
}
@@ -130,15 +130,15 @@ public class MqttDataService : IMqttDataService
if (result)
{
// 从界面删除MQTT服务器菜单
- var mqttServerMenu = _dataStorageService.Menus.FirstOrDefault(m => m.MenuType == MenuType.MqttServerMenu && m.TargetId == mqttServer.Id);
+ var mqttServerMenu = _viewDataService.Menus.FirstOrDefault(m => m.MenuType == MenuType.MqttServerMenu && m.TargetId == mqttServer.Id);
if (mqttServerMenu != null)
{
- await _menuDataService.DeleteMenuItem(mqttServerMenu);
+ _menuDataService.DeleteMenuToView(mqttServerMenu);
}
// 从界面删除MQTT服务器
- _dataStorageService.MqttServers.Remove(mqttServer.Id);
+ _viewDataService.MqttServers.Remove(mqttServer.Id);
}
return result;
diff --git a/DMS.WPF/Services/TriggerDataService.cs b/DMS.WPF/Services/TriggerDataService.cs
index a93b57f..bda26fa 100644
--- a/DMS.WPF/Services/TriggerDataService.cs
+++ b/DMS.WPF/Services/TriggerDataService.cs
@@ -25,8 +25,8 @@ public class TriggerDataService : ITriggerDataService
private readonly IMapper _mapper;
private readonly IAppCenterService _appCenterService;
private readonly IMenuViewService _menuDataService;
- private readonly IAppStorageService _appStorageService;
- private readonly IWpfDataService _dataStorageService;
+ private readonly IAppDataService _appDataService;
+ private readonly IViewDataService _viewDataService;
private readonly IEventService _eventService;
private readonly INotificationService _notificationService;
private readonly Dispatcher _uiDispatcher;
@@ -42,14 +42,14 @@ public class TriggerDataService : ITriggerDataService
/// 通知服务实例。
public TriggerDataService(IMapper mapper, IAppCenterService appCenterService,
IMenuViewService menuDataService,
- IAppStorageService appStorageService, IWpfDataService dataStorageService,
+ IAppDataService appStorageService, IViewDataService dataStorageService,
IEventService eventService, INotificationService notificationService)
{
_mapper = mapper;
_appCenterService = appCenterService;
_menuDataService = menuDataService;
- _appStorageService = appStorageService;
- _dataStorageService = dataStorageService;
+ _appDataService = appStorageService;
+ _viewDataService = dataStorageService;
_eventService = eventService;
_notificationService = notificationService;
_uiDispatcher = Dispatcher.CurrentDispatcher;
@@ -60,20 +60,20 @@ public class TriggerDataService : ITriggerDataService
///
public void LoadAllTriggers()
{
- _dataStorageService.Triggers.Clear();
- foreach (var trigger in _appStorageService.Triggers.Values)
+ _viewDataService.Triggers.Clear();
+ foreach (var trigger in _appDataService.Triggers.Values)
{
TriggerItem triggerItem = _mapper.Map(trigger);
foreach (var variable in trigger.Variables)
{
- if (_dataStorageService.Variables.TryGetValue(variable.Id,out var variableItem))
+ if (_viewDataService.Variables.TryGetValue(variable.Id,out var variableItem))
{
variableItem.Triggers.Add(triggerItem);
triggerItem.Variables.Add(variableItem);
}
}
- _dataStorageService.Triggers.Add(trigger.Id, triggerItem);
+ _viewDataService.Triggers.Add(trigger.Id, triggerItem);
}
}
@@ -95,11 +95,11 @@ public class TriggerDataService : ITriggerDataService
// 给界面添加触发器
var addItem = _mapper.Map(addDto, triggerItem);
- _dataStorageService.Triggers.Add(triggerItem.Id, triggerItem);
+ _viewDataService.Triggers.Add(triggerItem.Id, triggerItem);
//添加菜单
- var parentMenu=_dataStorageService.Menus.FirstOrDefault(m => m.TargetViewKey == nameof(TriggersViewModel) && m.TargetId == 0);
+ var parentMenu=_viewDataService.Menus.FirstOrDefault(m => m.TargetViewKey == nameof(TriggersViewModel) && m.TargetId == 0);
if (parentMenu is not null)
{
var menuItem = new ItemViewModel.MenuItem()
@@ -129,14 +129,14 @@ public class TriggerDataService : ITriggerDataService
if (await _appCenterService.TriggerManagementService.DeleteTriggerAsync(trigger.Id))
{
//删除菜单
- var menu=_dataStorageService.Menus.FirstOrDefault(m => m.MenuType == MenuType.TriggerMenu && m.TargetId == trigger.Id);
+ var menu=_viewDataService.Menus.FirstOrDefault(m => m.MenuType == MenuType.TriggerMenu && m.TargetId == trigger.Id);
if (menu is not null)
{
- await _menuDataService.DeleteMenuItem(menu);
+ _menuDataService.DeleteMenuToView(menu);
}
// 从界面删除触发器
- _dataStorageService.Triggers.Remove(trigger.Id);
+ _viewDataService.Triggers.Remove(trigger.Id);
return true;
}
@@ -162,7 +162,7 @@ public class TriggerDataService : ITriggerDataService
// 添加到UI数据存储
var addItem = _mapper.Map(createdTrigger.Trigger);
- _dataStorageService.Triggers.Add(addItem.Id, addItem);
+ _viewDataService.Triggers.Add(addItem.Id, addItem);
@@ -180,17 +180,17 @@ public class TriggerDataService : ITriggerDataService
///
public async Task UpdateTrigger(TriggerItem triggerItem)
{
- if (_appStorageService.Triggers.TryGetValue(triggerItem.Id, out var triggerDto))
+ if (_appDataService.Triggers.TryGetValue(triggerItem.Id, out var triggerDto))
{
_mapper.Map(triggerItem, triggerDto);
if (await _appCenterService.TriggerManagementService.UpdateTriggerAsync(triggerDto) > 0)
{
- if (_dataStorageService.Triggers.TryGetValue(triggerItem.Id,out var mTrigger))
+ if (_viewDataService.Triggers.TryGetValue(triggerItem.Id,out var mTrigger))
{
_mapper.Map(triggerItem,mTrigger);
//菜单
- var menuItem = _dataStorageService.Menus.FirstOrDefault(m => m.MenuType == MenuType.TriggerMenu && m.TargetId == triggerItem.Id);
+ var menuItem = _viewDataService.Menus.FirstOrDefault(m => m.MenuType == MenuType.TriggerMenu && m.TargetId == triggerItem.Id);
if (menuItem is not null)
{
menuItem.Header = triggerItem.Name;
diff --git a/DMS.WPF/Services/VariableDataService.cs b/DMS.WPF/Services/VariableDataService.cs
deleted file mode 100644
index d5b7017..0000000
--- a/DMS.WPF/Services/VariableDataService.cs
+++ /dev/null
@@ -1,156 +0,0 @@
-using AutoMapper;
-using CommunityToolkit.Mvvm.ComponentModel;
-using DMS.Application.DTOs;
-using DMS.Application.Interfaces;
-using DMS.Core.Models;
-using DMS.WPF.Interfaces;
-using DMS.WPF.ItemViewModel;
-using System.Collections.ObjectModel;
-using DMS.Application.Services.Management;
-
-namespace DMS.WPF.Services;
-
-///
-/// 变量数据服务类,负责管理变量表和变量相关的数据和操作。
-///
-public class VariableDataService : IVariableDataService
-{
- private readonly IMapper _mapper;
- private readonly IWpfDataService _dataStorageService;
- private readonly IAppCenterService _appCenterService;
-
-
-
- ///
- /// VariableDataService类的构造函数。
- ///
- /// AutoMapper 实例。
- /// 数据服务中心实例。
- public VariableDataService(IMapper mapper, IWpfDataService dataStorageService, IAppCenterService appCenterService)
- {
- _mapper = mapper;
- _dataStorageService = dataStorageService;
- _appCenterService = appCenterService;
-
- // 订阅批量导入变量事件
- if (_appCenterService.VariableManagementService is VariableManagementService variableManagementService)
- {
- // 如果需要直接订阅事件,这将需要EventService实例
- }
- }
-
- ///
- /// 加载所有变量
- ///
- public void LoadAllVariables()
- {
- foreach (var variableTable in _dataStorageService.VariableTables)
- {
- foreach (var variable in variableTable.Value.Variables)
- {
- _dataStorageService.Variables.Add(variable.Id, variable);
- }
- }
- }
-
- ///
- /// 添加变量表。
- ///
- public async Task AddVariableTableToView(VariableTable tableDto)
- {
- // 添加null检查
- if (tableDto == null || tableDto.DeviceId==0)
- return false;
-
- if (_dataStorageService.Devices.TryGetValue(tableDto.DeviceId, out var device))
- {
- var variableTableItem = _mapper.Map(tableDto);
- device.VariableTables.Add(variableTableItem);
- _dataStorageService.VariableTables.TryAdd(variableTableItem.Id,variableTableItem);
- }
-
-
- return true;
- }
-
- ///
- /// 更新变量表。
- ///
- public async Task UpdateVariableTable(VariableTableItem variableTableItem)
- {
- if (variableTableItem is null)
- {
- return false;
- }
-
- var variableTable = _mapper.Map(variableTableItem);
- if (await _appCenterService.VariableTableManagementService.UpdateVariableTableAsync(variableTable) > 0)
- {
- // 更新数据库后会自动更新内存,无需额外操作
- return true;
- }
-
- return false;
- }
-
- ///
- /// 删除变量表。
- ///
- public async Task DeleteVariableTable(VariableTableItem variableTable, bool isDeleteDb = false)
- {
- if (variableTable == null)
- {
- return false;
- }
-
- if (isDeleteDb)
- {
- if (!await _appCenterService.VariableTableManagementService.DeleteVariableTableAsync(variableTable.Id))
- {
- return false;
- }
- }
-
- // 删除与当前变量表关联的所有变量
- foreach (var variable in variableTable.Variables)
- {
- _dataStorageService.Variables.Remove(variable.Id);
- }
-
- // 删除变量表
- _dataStorageService.VariableTables.Remove(variableTable.Id);
- variableTable.Device.VariableTables.Remove(variableTable);
- return true;
- }
-
- ///
- /// 添加变量。
- ///
- public void AddVariable(VariableItem variableItem)
- {
- if (variableItem == null)
- {
- return;
- }
-
- _dataStorageService.Variables.Add(variableItem.Id, variableItem);
- }
-
- ///
- /// 删除变量。
- ///
- public void DeleteVariable(int id)
- {
- if (!_dataStorageService.Variables.TryGetValue(id, out var variableItem))
- {
- return;
- }
-
- if (_dataStorageService.VariableTables.TryGetValue(variableItem.VariableTableId, out var variableTable))
- {
- variableTable.Variables.Remove(variableItem);
- }
-
- _dataStorageService.Variables.Remove(variableItem.Id);
- }
-}
\ No newline at end of file
diff --git a/DMS.WPF/Services/WPFDataService.cs b/DMS.WPF/Services/ViewCenterService.cs
similarity index 85%
rename from DMS.WPF/Services/WPFDataService.cs
rename to DMS.WPF/Services/ViewCenterService.cs
index 9e0966d..928f566 100644
--- a/DMS.WPF/Services/WPFDataService.cs
+++ b/DMS.WPF/Services/ViewCenterService.cs
@@ -9,7 +9,7 @@ namespace DMS.WPF.Services;
///
/// 主数据服务,用于管理所有子数据服务。
///
-public class WPFDataService : IWPFDataService
+public class ViewCenterService : IViewCenterService
{
private readonly IMapper _mapper;
private readonly IAppCenterService _appCenterService;
@@ -22,12 +22,12 @@ public class WPFDataService : IWPFDataService
///
/// 变量表数据服务。
///
- public IVariableTableDataService VariableTableDataService { get; }
+ public IVariableTableViewService VariableTableDataService { get; }
///
/// 变量数据服务。
///
- public IVariableDataService VariableDataService { get; }
+ public IVariableViewService VariableDataService { get; }
///
/// 菜单数据服务。
@@ -55,17 +55,17 @@ public class WPFDataService : IWPFDataService
public ITriggerDataService TriggerDataService { get; }
///
- /// WPFDataService 构造函数。
+ /// ViewCenterService 构造函数。
///
- public WPFDataService(
+ public ViewCenterService(
IMapper mapper,
IAppCenterService appCenterService,
IDeviceDataService deviceDataService,
- IVariableDataService variableDataService,
+ IVariableViewService variableDataService,
IMenuViewService menuDataService,
IMqttDataService mqttDataService,
ILogDataService logDataService,
- IVariableTableDataService variableTableDataService,
+ IVariableTableViewService variableTableDataService,
ITriggerDataService triggerDataService,
IMqttAliasDataService mqttAliasDataService)
{
diff --git a/DMS.WPF/Services/WpfDataService_1.cs b/DMS.WPF/Services/ViewDataService.cs
similarity index 95%
rename from DMS.WPF/Services/WpfDataService_1.cs
rename to DMS.WPF/Services/ViewDataService.cs
index 8232092..5b5e008 100644
--- a/DMS.WPF/Services/WpfDataService_1.cs
+++ b/DMS.WPF/Services/ViewDataService.cs
@@ -1,12 +1,11 @@
-using System.Collections.ObjectModel;
using DMS.WPF.Interfaces;
using DMS.WPF.ItemViewModel;
-using DMS.WPF.ItemViewModel;
using ObservableCollections;
+using System.Collections.ObjectModel;
namespace DMS.WPF.Services;
-public class WpfDataService : IWpfDataService
+public class ViewDataService : IViewDataService
{
@@ -56,7 +55,7 @@ public class WpfDataService : IWpfDataService
///
public ObservableDictionary Triggers { get; set; }
- public WpfDataService()
+ public ViewDataService()
{
Devices=new ObservableDictionary();
VariableTables = new ObservableDictionary();
diff --git a/DMS.WPF/Services/DeviceViewService.cs b/DMS.WPF/Services/ViewService/DeviceViewService.cs
similarity index 60%
rename from DMS.WPF/Services/DeviceViewService.cs
rename to DMS.WPF/Services/ViewService/DeviceViewService.cs
index dfd0e1f..afe76cc 100644
--- a/DMS.WPF/Services/DeviceViewService.cs
+++ b/DMS.WPF/Services/ViewService/DeviceViewService.cs
@@ -1,5 +1,3 @@
-using System.Collections.ObjectModel;
-using System.Windows.Threading;
using AutoMapper;
using CommunityToolkit.Mvvm.ComponentModel;
using DMS.Application.DTOs;
@@ -10,8 +8,11 @@ using DMS.Core.Events;
using DMS.WPF.Interfaces;
using DMS.WPF.ItemViewModel;
using DMS.WPF.ViewModels;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Windows.Threading;
-namespace DMS.WPF.Services;
+namespace DMS.WPF.Services.ViewService;
///
/// 设备数据服务类,负责管理设备相关的数据和操作。
@@ -20,13 +21,13 @@ public class DeviceViewService : IDeviceDataService
{
private readonly IMapper _mapper;
private readonly IAppCenterService _appCenterService;
- private readonly IAppStorageService _appStorageService;
- private readonly IWpfDataService _dataStorageService;
- private readonly IVariableTableDataService _variableTableDataService;
+ private readonly IAppDataService _appDataService;
+ private readonly IViewDataService _viewDataService;
+ private readonly IVariableTableViewService _variableTableDataService;
private readonly IEventService _eventService;
private readonly INotificationService _notificationService;
private readonly IMenuViewService _menuDataService;
- private readonly IVariableDataService _variableDataService;
+ private readonly IVariableViewService _variableDataService;
private readonly Dispatcher _uiDispatcher;
///
@@ -35,15 +36,15 @@ public class DeviceViewService : IDeviceDataService
/// AutoMapper 实例。
/// 数据服务中心实例。
public DeviceViewService(IMapper mapper, IAppCenterService appCenterService,
- IAppStorageService appStorageService, IWpfDataService dataStorageService,
- IVariableTableDataService variableTableDataService,
+ IAppDataService appStorageService, IViewDataService dataStorageService,
+ IVariableTableViewService variableTableDataService,
IEventService eventService, INotificationService notificationService,
- IMenuViewService menuDataService, IVariableDataService variableDataService)
+ IMenuViewService menuDataService, IVariableViewService variableDataService)
{
_mapper = mapper;
_appCenterService = appCenterService;
- _appStorageService = appStorageService;
- _dataStorageService = dataStorageService;
+ _appDataService = appStorageService;
+ _viewDataService = dataStorageService;
_variableTableDataService = variableTableDataService;
_eventService = eventService;
_notificationService = notificationService;
@@ -57,11 +58,11 @@ public class DeviceViewService : IDeviceDataService
private void OnDeviceStateChanged(object? sender, DeviceStateChangedEventArgs e)
{
// 只处理连接状态变化
- if (e.StateType == Core.Enums.DeviceStateType.Connection)
+ if (e.StateType == DeviceStateType.Connection)
{
_uiDispatcher.Invoke(() =>
{
- if (_dataStorageService.Devices.TryGetValue(e.DeviceId, out DeviceItem device))
+ if (_viewDataService.Devices.TryGetValue(e.DeviceId, out DeviceItem device))
{
device.IsRunning = e.StateValue;
if (device.IsRunning)
@@ -82,9 +83,9 @@ public class DeviceViewService : IDeviceDataService
///
public void LoadAllDevices()
{
- foreach (var device in _appStorageService.Devices.Values)
+ foreach (var device in _appDataService.Devices.Values)
{
- _dataStorageService.Devices.Add(device.Id, _mapper.Map(device));
+ _viewDataService.Devices.Add(device.Id, _mapper.Map(device));
}
}
@@ -95,17 +96,17 @@ public class DeviceViewService : IDeviceDataService
{
// 添加null检查
if (dto is null) return null;
-
+
if (dto.VariableTable is not null)
{
dto.VariableTable.Protocol = dto.Device.Protocol;
dto.VariableTableMenu.MenuType = MenuType.VariableTableMenu;
}
-
+
//查找到设备的根菜单
var parentMenu
- = _appStorageService.Menus.Values.FirstOrDefault(m => m.TargetViewKey == nameof(DevicesViewModel) &&
+ = _appDataService.Menus.Values.FirstOrDefault(m => m.TargetViewKey == nameof(DevicesViewModel) &&
m.TargetId == 0);
if (parentMenu is not null)
{
@@ -119,25 +120,20 @@ public class DeviceViewService : IDeviceDataService
if (addDto is null) return null;
//给界面添加设备
- _dataStorageService.Devices.Add(addDto.Device.Id, _mapper.Map(addDto.Device));
+ DeviceItem deviceItem = _mapper.Map(addDto.Device);
+ _viewDataService.Devices.Add(addDto.Device.Id, deviceItem);
+ foreach (var variableTable in deviceItem.VariableTables)
+ {
+ _viewDataService.VariableTables.Add(variableTable.Id,variableTable);
+ }
// 给界面添加设备菜单
if (addDto.DeviceMenu != null)
{
- _menuDataService.AddMenuToView(_mapper.Map
public async Task UpdateDevice(DeviceItem device)
{
- if (!_appStorageService.Devices.TryGetValue(device.Id, out var existingDevice))
+ if (!_appDataService.Devices.TryGetValue(device.Id, out var deviceInMen))
{
return false;
}
+ //更新内存中的设备数据
+ _mapper.Map(device, deviceInMen);
- _mapper.Map(device, existingDevice);
- if (await _appCenterService.DeviceManagementService.UpdateDeviceAsync(existingDevice) > 0)
+ if (await _appCenterService.DeviceManagementService.UpdateDeviceAsync(deviceInMen) > 0)
{
- // 更新数据库后会自动更新内存,无需额外操作
- return true;
+ //更新界面中的设备数据
+ if (_viewDataService.Devices.TryGetValue(device.Id, out var deviceInView))
+ {
+ _mapper.Map(device, deviceInView);
+ }
+ //更新设备菜单名称
+ var deviceMenuItem = _viewDataService.Menus
+ .FirstOrDefault(m => m.MenuType == MenuType.DeviceMenu && m.TargetId == device.Id);
+ if (deviceMenuItem is not null && deviceMenuItem.Header != device.Name)
+ {
+ deviceMenuItem.Header = device.Name;
+ }
+
+
+ return true;
}
return false;
diff --git a/DMS.WPF/Services/VariableTableDataService.cs b/DMS.WPF/Services/ViewService/VariableTableViewService.cs
similarity index 78%
rename from DMS.WPF/Services/VariableTableDataService.cs
rename to DMS.WPF/Services/ViewService/VariableTableViewService.cs
index efaf7aa..8e7bfad 100644
--- a/DMS.WPF/Services/VariableTableDataService.cs
+++ b/DMS.WPF/Services/ViewService/VariableTableViewService.cs
@@ -7,22 +7,22 @@ using DMS.Core.Models;
using DMS.WPF.Interfaces;
using DMS.WPF.ItemViewModel;
-namespace DMS.WPF.Services;
+namespace DMS.WPF.Services.ViewService;
-public class VariableTableDataService : IVariableTableDataService
+public class VariableTableViewService : IVariableTableViewService
{
private readonly IMapper _mapper;
- private readonly IWpfDataService _dataStorageService;
+ private readonly IViewDataService _viewDataService;
private readonly IAppCenterService _appCenterService;
private readonly IMenuViewService _menuDataService;
- public VariableTableDataService(IMapper mapper, IWpfDataService dataStorageService, IAppCenterService appCenterService,
+ public VariableTableViewService(IMapper mapper, IViewDataService dataStorageService, IAppCenterService appCenterService,
IMenuViewService menuDataService)
{
_mapper = mapper;
- _dataStorageService = dataStorageService;
+ _viewDataService = dataStorageService;
_appCenterService = appCenterService;
_menuDataService = menuDataService;
}
@@ -30,11 +30,11 @@ public class VariableTableDataService : IVariableTableDataService
public void LoadAllVariableTables()
{
- foreach (var device in _dataStorageService.Devices)
+ foreach (var device in _viewDataService.Devices)
{
foreach (var variableTable in device.Value.VariableTables)
{
- _dataStorageService.VariableTables.Add(variableTable.Id,variableTable);
+ _viewDataService.VariableTables.Add(variableTable.Id,variableTable);
}
}
}
@@ -75,7 +75,7 @@ public class VariableTableDataService : IVariableTableDataService
{
// 更新数据库后会自动更新内存,无需额外操作
- var menu = _dataStorageService.Menus.FirstOrDefault(m =>
+ var menu = _viewDataService.Menus.FirstOrDefault(m =>
m.MenuType == MenuType.VariableTableMenu &&
m.TargetId == variableTable.Id);
if (menu != null)
@@ -107,16 +107,16 @@ public class VariableTableDataService : IVariableTableDataService
// 删除与当前变量表关联的所有变量
foreach (var variable in variableTable.Variables)
{
- _dataStorageService.Variables.Remove(variable.Id);
+ _viewDataService.Variables.Remove(variable.Id);
}
// 删除变量表界面相关的菜单
var variableTableMenu
- =_dataStorageService.Menus.FirstOrDefault(m => m.MenuType == MenuType.VariableTableMenu && m.TargetId == variableTable.Id);
- await _menuDataService.DeleteMenuItem(variableTableMenu);
+ =_viewDataService.Menus.FirstOrDefault(m => m.MenuType == MenuType.VariableTableMenu && m.TargetId == variableTable.Id);
+ _menuDataService.DeleteMenuToView(variableTableMenu);
// 删除变量表
- _dataStorageService.VariableTables.Remove(variableTable.Id);
+ _viewDataService.VariableTables.Remove(variableTable.Id);
variableTable.Device.VariableTables.Remove(variableTable);
return true;
}
diff --git a/DMS.WPF/Services/ViewService/VariableViewService.cs b/DMS.WPF/Services/ViewService/VariableViewService.cs
new file mode 100644
index 0000000..2883b35
--- /dev/null
+++ b/DMS.WPF/Services/ViewService/VariableViewService.cs
@@ -0,0 +1,221 @@
+using AutoMapper;
+using CommunityToolkit.Mvvm.ComponentModel;
+using DMS.Application.DTOs;
+using DMS.Application.Interfaces;
+using DMS.Core.Models;
+using DMS.WPF.Interfaces;
+using DMS.WPF.ItemViewModel;
+using System.Collections.ObjectModel;
+using DMS.Application.Interfaces.Management;
+using DMS.Application.Services.Management;
+
+namespace DMS.WPF.Services.ViewService;
+
+///
+/// 变量数据服务类,负责管理变量表和变量相关的数据和操作。
+///
+public class VariableViewService : IVariableViewService
+{
+ private readonly IMapper _mapper;
+ private readonly IAppDataService _appDataService;
+ private readonly IVariableManagementService _variableManagementService;
+ private readonly IViewDataService _viewDataService;
+ private readonly IAppCenterService _appCenterService;
+
+
+ ///
+ /// VariableDataService类的构造函数。
+ ///
+ /// AutoMapper 实例。
+ /// 数据服务中心实例。
+ public VariableViewService(IMapper mapper, IAppDataService appStorageService,
+ IVariableManagementService variableManagementService, IViewDataService dataStorageService,
+ IAppCenterService appCenterService)
+ {
+ _mapper = mapper;
+ _appDataService = appStorageService;
+ _variableManagementService = variableManagementService;
+ _viewDataService = dataStorageService;
+ _appCenterService = appCenterService;
+ }
+
+ ///
+ /// 加载所有变量
+ ///
+ public void LoadAllVariables()
+ {
+ foreach (var variableTable in _viewDataService.VariableTables)
+ {
+ foreach (var variable in variableTable.Value.Variables)
+ {
+ _viewDataService.Variables.Add(variable.Id, variable);
+ }
+ }
+ }
+
+ ///
+ /// 添加变量表。
+ ///
+ public async Task AddVariableTableToView(VariableTable tableDto)
+ {
+ // 添加null检查
+ if (tableDto == null || tableDto.DeviceId == 0)
+ return false;
+
+ if (_viewDataService.Devices.TryGetValue(tableDto.DeviceId, out var device))
+ {
+ var variableTableItem = _mapper.Map(tableDto);
+ device.VariableTables.Add(variableTableItem);
+ _viewDataService.VariableTables.TryAdd(variableTableItem.Id, variableTableItem);
+ }
+
+
+ return true;
+ }
+
+ ///
+ /// 更新变量表。
+ ///
+ public async Task UpdateVariableTable(VariableTableItem variableTableItem)
+ {
+ if (variableTableItem is null)
+ {
+ return false;
+ }
+
+ var variableTable = _mapper.Map(variableTableItem);
+ if (await _appCenterService.VariableTableManagementService.UpdateVariableTableAsync(variableTable) > 0)
+ {
+ // 更新数据库后会自动更新内存,无需额外操作
+ return true;
+ }
+
+ return false;
+ }
+
+ ///
+ /// 删除变量表。
+ ///
+ public async Task DeleteVariableTable(VariableTableItem variableTable, bool isDeleteDb = false)
+ {
+ if (variableTable == null)
+ {
+ return false;
+ }
+
+ if (isDeleteDb)
+ {
+ if (!await _appCenterService.VariableTableManagementService.DeleteVariableTableAsync(variableTable.Id))
+ {
+ return false;
+ }
+ }
+
+ // 删除与当前变量表关联的所有变量
+ foreach (var variable in variableTable.Variables)
+ {
+ _viewDataService.Variables.Remove(variable.Id);
+ }
+
+ // 删除变量表
+ _viewDataService.VariableTables.Remove(variableTable.Id);
+ variableTable.Device.VariableTables.Remove(variableTable);
+ return true;
+ }
+
+ ///
+ /// 添加变量。
+ ///
+ public void AddVariable(VariableItem variableItem)
+ {
+ if (variableItem == null)
+ {
+ return;
+ }
+
+ _viewDataService.Variables.Add(variableItem.Id, variableItem);
+ }
+
+ ///
+ /// 添加变量。
+ ///
+ public async Task AddAsync(List variableItems, VariableTableItem variableTable)
+ {
+
+ foreach (var variableDto in variableItems)
+ {
+ variableDto.IsActive = true;
+ variableDto.CreatedAt = DateTime.Now;
+ variableDto.UpdatedAt = DateTime.Now;
+ variableDto.VariableTableId = variableTable.Id;
+ }
+
+ var resVariables = await _variableManagementService.AddAsync(_mapper.Map>(variableItems));
+
+
+
+ List resVariableItems = _mapper.Map>(resVariables);
+ foreach (var variableItem in resVariableItems)
+ {
+ _viewDataService.Variables.TryAdd(variableItem.Id, variableItem);
+ variableTable.Variables.Add(variableItem);
+ }
+
+ return true;
+ }
+
+ ///
+ /// 删除变量。
+ ///
+ public void DeleteVariable(int id)
+ {
+ if (!_viewDataService.Variables.TryGetValue(id, out var variableItem))
+ {
+ return;
+ }
+
+ if (_viewDataService.VariableTables.TryGetValue(variableItem.VariableTableId, out var variableTable))
+ {
+ variableTable.Variables.Remove(variableItem);
+ }
+
+ _viewDataService.Variables.Remove(variableItem.Id);
+ }
+
+ public async Task DeleteAsync(List variableItems)
+ {
+ List deleteList = new List();
+ foreach (var variable in variableItems)
+ {
+ if (_appDataService.Variables.TryGetValue(variable.Id, out var mVariable))
+ {
+ deleteList.Add(mVariable);
+ }
+ }
+
+ return await _variableManagementService.DeleteAsync(deleteList);
+ }
+
+
+
+
+
+ public List CheckExistingVariables(List importedVariables, DeviceItem device)
+ {
+ List? existList = new List();
+ var allVariable = device.VariableTables.SelectMany(vt => vt.Variables);
+ foreach (var variable in allVariable)
+ {
+ foreach (var item in importedVariables)
+ {
+ bool slelect = item.Name == variable.Name || item.S7Address == variable.S7Address || item.OpcUaNodeId == variable.OpcUaNodeId;
+ if (slelect)
+ {
+ existList.Add(item);
+ }
+ }
+ }
+
+ return existList;
+ }
+}
\ No newline at end of file
diff --git a/DMS.WPF/ViewModels/DeviceDetailViewModel.cs b/DMS.WPF/ViewModels/DeviceDetailViewModel.cs
index ee6abd3..ae0040e 100644
--- a/DMS.WPF/ViewModels/DeviceDetailViewModel.cs
+++ b/DMS.WPF/ViewModels/DeviceDetailViewModel.cs
@@ -20,9 +20,9 @@ public partial class DeviceDetailViewModel : ViewModelBase
{
private readonly IMapper _mapper;
private readonly IDialogService _dialogService;
- private readonly IWpfDataService _dataStorageService;
+ private readonly IViewDataService _viewDataService;
private readonly INavigationService _navigationService;
- private readonly IWPFDataService _wpfDataService;
+ private readonly IViewCenterService _wpfDataService;
[ObservableProperty]
private DeviceItem _currentDevice;
@@ -36,13 +36,13 @@ public partial class DeviceDetailViewModel : ViewModelBase
private readonly INotificationService _notificationService;
- public DeviceDetailViewModel(IMapper mapper, IDialogService dialogService, IWpfDataService dataStorageService,
+ public DeviceDetailViewModel(IMapper mapper, IDialogService dialogService, IViewDataService dataStorageService,
INavigationService navigationService,
- IWPFDataService wpfDataService, INotificationService notificationService)
+ IViewCenterService wpfDataService, INotificationService notificationService)
{
_mapper = mapper;
_dialogService = dialogService;
- _dataStorageService = dataStorageService;
+ _viewDataService = dataStorageService;
_navigationService = navigationService;
_notificationService = notificationService;
_wpfDataService = wpfDataService;
@@ -83,7 +83,7 @@ public partial class DeviceDetailViewModel : ViewModelBase
VariableTableItem.Id = addVarTableId;
VariableTableItem.Device = CurrentDevice;
CurrentDevice.VariableTables.Add(VariableTableItem);
- _dataStorageService.VariableTables.Add(VariableTableItem.Id, VariableTableItem);
+ _viewDataService.VariableTables.Add(VariableTableItem.Id, VariableTableItem);
_notificationService.ShowSuccess($"添加变量表成功:{VariableTableItem.Name}");
}
else
@@ -169,11 +169,11 @@ public partial class DeviceDetailViewModel : ViewModelBase
{
if (SelectedVariableTable.Device != null)
{
- if (_dataStorageService.Devices.TryGetValue(SelectedVariableTable.DeviceId ,out var device))
+ if (_viewDataService.Devices.TryGetValue(SelectedVariableTable.DeviceId ,out var device))
{
device.VariableTables.Remove(SelectedVariableTable);
}
- _dataStorageService.VariableTables.Remove(SelectedVariableTable.Id);
+ _viewDataService.VariableTables.Remove(SelectedVariableTable.Id);
SelectedVariableTable.Device.VariableTables.Remove(SelectedVariableTable);
}
_notificationService.ShowSuccess($"变量表:{tableName},删除成功。");
@@ -197,7 +197,7 @@ public partial class DeviceDetailViewModel : ViewModelBase
public override async Task OnNavigatedToAsync(NavigationParameter parameter)
{
- if (_dataStorageService.Devices.TryGetValue(parameter.TargetId, out var device))
+ if (_viewDataService.Devices.TryGetValue(parameter.TargetId, out var device))
{
CurrentDevice = device;
}
@@ -207,7 +207,7 @@ public partial class DeviceDetailViewModel : ViewModelBase
public void NavigateToVariableTable()
{
if (SelectedVariableTable == null) return;
- // var menu = _wpfDataService.Menus.FirstOrDefault(m => m.MenuType == MenuType.VariableTableMenu &&
+ // var menu = _viewCenterService.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 c4ea3a1..82145f4 100644
--- a/DMS.WPF/ViewModels/DevicesViewModel.cs
+++ b/DMS.WPF/ViewModels/DevicesViewModel.cs
@@ -21,10 +21,10 @@ namespace DMS.WPF.ViewModels;
///
public partial class DevicesViewModel : ViewModelBase, INavigatable
{
- private readonly IWPFDataService _wpfDataService;
+ private readonly IViewCenterService _wpfDataService;
private readonly IDeviceAppService _deviceAppService;
private readonly IMapper _mapper;
- private readonly IWpfDataService _dataStorageService;
+ private readonly IViewDataService _viewDataService;
private readonly IDialogService _dialogService;
private readonly INavigationService _navigationService;
@@ -54,19 +54,19 @@ public partial class DevicesViewModel : ViewModelBase, INavigatable
/// 主数据服务。
/// 设备应用服务。
/// 通知服务。
- public DevicesViewModel(IMapper mapper, IWpfDataService dataStorageService,
+ public DevicesViewModel(IMapper mapper, IViewDataService dataStorageService,
IDialogService dialogService, INavigationService navigationService,
- IWPFDataService wpfDataService, IDeviceAppService deviceAppService,
+ IViewCenterService wpfDataService, IDeviceAppService deviceAppService,
INotificationService notificationService)
{
_mapper = mapper;
- _dataStorageService = dataStorageService;
+ _viewDataService = dataStorageService;
_dialogService = dialogService;
_navigationService = navigationService;
_wpfDataService = wpfDataService;
_deviceAppService = deviceAppService;
_notificationService = notificationService;
- Devices = _dataStorageService.Devices.ToNotifyCollectionChanged(x => x.Value);
+ Devices = _viewDataService.Devices.ToNotifyCollectionChanged(x => x.Value);
}
@@ -183,7 +183,7 @@ public partial class DevicesViewModel : ViewModelBase, INavigatable
if (await _dialogService.ShowDialogAsync(viewModel))
{
var deviceName = SelectedDevice.Name;
- if (await _wpfDataService.DeviceDataService.DeleteDevice(SelectedDevice))
+ if (await _wpfDataService.DeviceDataService.DeleteAsync(SelectedDevice))
{
_notificationService.ShowSuccess($"删除设备成功,设备名:{deviceName}");
}
@@ -199,14 +199,10 @@ public partial class DevicesViewModel : ViewModelBase, INavigatable
/// 编辑设备命令。
///
[RelayCommand]
- private async Task EditDevice(DeviceItem parmDeviceItem)
+ private async Task EditDevice()
{
try
{
- if (parmDeviceItem != null)
- {
- SelectedDevice = parmDeviceItem;
- }
if (SelectedDevice == null)
{
@@ -279,11 +275,11 @@ public partial class DevicesViewModel : ViewModelBase, INavigatable
if (addVarTableId > 0)
{
VariableTableItem.Id = addVarTableId;
- if (_dataStorageService.Devices.TryGetValue(VariableTableItem.DeviceId, out var deviceModel))
+ if (_viewDataService.Devices.TryGetValue(VariableTableItem.DeviceId, out var deviceModel))
{
VariableTableItem.Device = deviceModel;
deviceModel.VariableTables.Add(VariableTableItem);
- _dataStorageService.VariableTables.Add(VariableTableItem.Id, VariableTableItem);
+ _viewDataService.VariableTables.Add(VariableTableItem.Id, VariableTableItem);
}
_notificationService.ShowSuccess($"添加变量表成功:{VariableTableItem.Name}");
}
@@ -364,11 +360,11 @@ public partial class DevicesViewModel : ViewModelBase, INavigatable
// Remove from parent device's collection
if (variableTable.Device != null)
{
- if (_dataStorageService.Devices.TryGetValue(variableTable.DeviceId ,out var device))
+ if (_viewDataService.Devices.TryGetValue(variableTable.DeviceId ,out var device))
{
device.VariableTables.Remove(variableTable);
}
- _dataStorageService.VariableTables.Remove(variableTable.Id);
+ _viewDataService.VariableTables.Remove(variableTable.Id);
variableTable.Device.VariableTables.Remove(variableTable);
}
diff --git a/DMS.WPF/ViewModels/Dialogs/ImportExcelDialogViewModel.cs b/DMS.WPF/ViewModels/Dialogs/ImportExcelDialogViewModel.cs
index c596f42..b6f0799 100644
--- a/DMS.WPF/ViewModels/Dialogs/ImportExcelDialogViewModel.cs
+++ b/DMS.WPF/ViewModels/Dialogs/ImportExcelDialogViewModel.cs
@@ -9,10 +9,11 @@ using DMS.Core.Models;
using DMS.WPF.Interfaces;
using DMS.WPF.Services;
using DMS.WPF.ItemViewModel;
+using System.Threading.Tasks;
namespace DMS.WPF.ViewModels.Dialogs;
-public partial class ImportExcelDialogViewModel : DialogViewModelBase>
+public partial class ImportExcelDialogViewModel : DialogViewModelBase>
{
private readonly IMapper _mapper;
private readonly IExcelService _excelService;
@@ -57,21 +58,21 @@ public partial class ImportExcelDialogViewModel : DialogViewModelBase().ToList();
- Close(_mapper.Map>(selected));
+ await Close(selected);
}
[RelayCommand]
- private void CancleButton()
+ private async Task CancleButton()
{
- Close(null);
+ await Close(null);
}
}
diff --git a/DMS.WPF/ViewModels/Dialogs/TriggerDialogViewModel.cs b/DMS.WPF/ViewModels/Dialogs/TriggerDialogViewModel.cs
index aed1ac9..04b524a 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 IWpfDataService _dataStorageService;
+ private readonly IViewDataService _viewDataService;
private readonly INotificationService _notificationService;
[ObservableProperty]
@@ -39,11 +39,11 @@ namespace DMS.WPF.ViewModels.Dialogs
public TriggerDialogViewModel(
IDialogService dialogService,
- IWpfDataService dataStorageService,
+ IViewDataService dataStorageService,
INotificationService notificationService)
{
_dialogService = dialogService ?? throw new ArgumentNullException(nameof(dialogService));
- _dataStorageService = dataStorageService;
+ _viewDataService = dataStorageService;
_notificationService = notificationService ?? throw new ArgumentNullException(nameof(notificationService));
}
diff --git a/DMS.WPF/ViewModels/Dialogs/VariableDialogViewModel.cs b/DMS.WPF/ViewModels/Dialogs/VariableDialogViewModel.cs
index f7c9e35..5c77ae6 100644
--- a/DMS.WPF/ViewModels/Dialogs/VariableDialogViewModel.cs
+++ b/DMS.WPF/ViewModels/Dialogs/VariableDialogViewModel.cs
@@ -25,18 +25,18 @@ public partial class VariableDialogViewModel : DialogViewModelBase
[ObservableProperty]
private bool _hasError;
- private readonly IWPFDataService _wpfDataService;
- private readonly IWpfDataService _dataStorageService;
+ private readonly IViewCenterService _wpfDataService;
+ private readonly IViewDataService _viewDataService;
private readonly IVariableAppService _variableAppService;
private readonly IMapper _mapper;
- public VariableDialogViewModel(IWPFDataService wpfDataService,IWpfDataService dataStorageService, IVariableAppService variableAppService, IMapper mapper)
+ public VariableDialogViewModel(IViewCenterService wpfDataService,IViewDataService dataStorageService, IVariableAppService variableAppService, IMapper mapper)
{
Variable = new VariableItem();
_wpfDataService = wpfDataService;
- _dataStorageService = dataStorageService;
+ _viewDataService = dataStorageService;
this._variableAppService = variableAppService;
this._mapper = mapper;
}
@@ -83,7 +83,7 @@ public partial class VariableDialogViewModel : DialogViewModelBase
return false;
}
//检查变量是否存在
- var existVariables = _dataStorageService.Variables.Where(v => v.Value.Name == Variable.Name || (v.Value.Protocol == ProtocolType.S7 && v.Value.S7Address == Variable.S7Address) || (v.Value.Protocol == ProtocolType.OpcUa && v.Value.OpcUaNodeId == Variable.OpcUaNodeId)).Select(v=>v.Value).ToList();
+ var existVariables = _viewDataService.Variables.Where(v => v.Value.Name == Variable.Name || (v.Value.Protocol == ProtocolType.S7 && v.Value.S7Address == Variable.S7Address) || (v.Value.Protocol == ProtocolType.OpcUa && v.Value.OpcUaNodeId == Variable.OpcUaNodeId)).Select(v=>v.Value).ToList();
VariableItem existVariable = null;
if (IsAddModel)
{
diff --git a/DMS.WPF/ViewModels/LogHistoryViewModel.cs b/DMS.WPF/ViewModels/LogHistoryViewModel.cs
index f042f47..80ad6ec 100644
--- a/DMS.WPF/ViewModels/LogHistoryViewModel.cs
+++ b/DMS.WPF/ViewModels/LogHistoryViewModel.cs
@@ -24,11 +24,11 @@ namespace DMS.WPF.ViewModels;
partial class LogHistoryViewModel : ViewModelBase,IDisposable
{
- private readonly IWPFDataService _wpfDataService ;
+ private readonly IViewCenterService _wpfDataService ;
private readonly IMapper _mapper;
private readonly INlogAppService _nlogAppService;
private readonly IDialogService _dialogService;
- private readonly IWpfDataService _dataStorageService;
+ private readonly IViewDataService _viewDataService;
private readonly INotificationService _notificationService;
private readonly IAppCenterService _appCenterService;
@@ -50,18 +50,18 @@ 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, IWpfDataService dataStorageService
- , INotificationService notificationService, IWPFDataService wpfDataService, IAppCenterService appCenterService)
+ public LogHistoryViewModel(IMapper mapper, INlogAppService nlogAppService, IDialogService dialogService, IViewDataService dataStorageService
+ , INotificationService notificationService, IViewCenterService wpfDataService, IAppCenterService appCenterService)
{
_mapper = mapper;
_nlogAppService = nlogAppService;
_dialogService = dialogService;
- _dataStorageService = dataStorageService;
+ _viewDataService = dataStorageService;
_notificationService = notificationService;
_wpfDataService = wpfDataService;
_appCenterService = appCenterService;
- _logItemList = new ObservableList(_dataStorageService.Nlogs);
+ _logItemList = new ObservableList(_viewDataService.Nlogs);
_synchronizedView = _logItemList.CreateView(v => v);
LogItemListView = _synchronizedView.ToNotifyCollectionChanged();
diff --git a/DMS.WPF/ViewModels/MainViewModel.cs b/DMS.WPF/ViewModels/MainViewModel.cs
index 38d998b..4d5a443 100644
--- a/DMS.WPF/ViewModels/MainViewModel.cs
+++ b/DMS.WPF/ViewModels/MainViewModel.cs
@@ -21,8 +21,8 @@ namespace DMS.WPF.ViewModels;
public partial class MainViewModel : ViewModelBase
{
private readonly IDialogService _dialogService;
- private readonly IWPFDataService _wpfDataService;
- private readonly IWpfDataService _dataStorageService;
+ private readonly IViewCenterService _wpfDataService;
+ private readonly IViewDataService _viewDataService;
private readonly INavigationService _navigationService;
private readonly ILogger _logger;
@@ -46,14 +46,14 @@ public partial class MainViewModel : ViewModelBase
/// 对话框服务。
/// 日志记录器。
///
- public MainViewModel(IWPFDataService wpfDataService ,IWpfDataService dataStorageService,INavigationService navigationService,
+ public MainViewModel(IViewCenterService wpfDataService ,IViewDataService dataStorageService,INavigationService navigationService,
ILogger logger)
{
_wpfDataService = wpfDataService;
- _dataStorageService = dataStorageService;
+ _viewDataService = dataStorageService;
_navigationService = navigationService;
_logger = logger;
- MenuTrees = _dataStorageService.MenuTrees;
+ MenuTrees = _viewDataService.MenuTrees;
CurrentViewModel = new HomeViewModel();
CurrentViewModel.OnLoaded();
diff --git a/DMS.WPF/ViewModels/MqttServerDetailViewModel.cs b/DMS.WPF/ViewModels/MqttServerDetailViewModel.cs
index cc66548..985e77c 100644
--- a/DMS.WPF/ViewModels/MqttServerDetailViewModel.cs
+++ b/DMS.WPF/ViewModels/MqttServerDetailViewModel.cs
@@ -25,8 +25,8 @@ namespace DMS.WPF.ViewModels
private readonly IEventService _eventService;
private readonly IMqttManagementService _mqttManagementService;
private readonly IMqttAliasDataService _mqttAliasDataService;
- private readonly IWPFDataService _wpfDataService;
- private readonly IWpfDataService _dataStorageService;
+ private readonly IViewCenterService _wpfDataService;
+ private readonly IViewDataService _viewDataService;
private readonly INavigationService _navigationService;
///
@@ -60,8 +60,8 @@ namespace DMS.WPF.ViewModels
IEventService eventService,
IMqttManagementService mqttManagementService,
IMqttAliasDataService mqttAliasDataService,
- IWPFDataService wpfDataService,
- IWpfDataService dataStorageService,
+ IViewCenterService wpfDataService,
+ IViewDataService dataStorageService,
INavigationService navigationService)
{
_logger = logger;
@@ -71,7 +71,7 @@ namespace DMS.WPF.ViewModels
_mqttManagementService = mqttManagementService;
this._mqttAliasDataService = mqttAliasDataService;
this._wpfDataService = wpfDataService;
- this._dataStorageService = dataStorageService;
+ this._viewDataService = dataStorageService;
_navigationService = navigationService;
}
@@ -179,7 +179,7 @@ namespace DMS.WPF.ViewModels
{
if (parameter == null) return Task.CompletedTask;
- if (_dataStorageService.MqttServers.TryGetValue(parameter.TargetId, out var mqttServerItem))
+ if (_viewDataService.MqttServers.TryGetValue(parameter.TargetId, out var mqttServerItem))
{
CurrentMqtt = mqttServerItem;
diff --git a/DMS.WPF/ViewModels/MqttsViewModel.cs b/DMS.WPF/ViewModels/MqttsViewModel.cs
index 0b29e45..b98d48e 100644
--- a/DMS.WPF/ViewModels/MqttsViewModel.cs
+++ b/DMS.WPF/ViewModels/MqttsViewModel.cs
@@ -21,9 +21,9 @@ namespace DMS.WPF.ViewModels;
///
public partial class MqttsViewModel : ViewModelBase
{
- private readonly IWPFDataService _wpfDataService;
+ private readonly IViewCenterService _wpfDataService;
private readonly IMqttAppService _mqttAppService;
- private readonly IWpfDataService _dataStorageService;
+ private readonly IViewDataService _viewDataService;
private readonly IMapper _mapper;
private readonly IDialogService _dialogService;
private readonly INavigationService _navigationService;
@@ -47,9 +47,9 @@ public partial class MqttsViewModel : ViewModelBase
public MqttsViewModel(
ILogger logger,
IDialogService dialogService,
- IWPFDataService wpfDataService,
+ IViewCenterService wpfDataService,
IMqttAppService mqttAppService,
- IWpfDataService dataStorageService,
+ IViewDataService dataStorageService,
IMapper mapper,
INavigationService navigationService,
INotificationService notificationService
@@ -59,13 +59,13 @@ public partial class MqttsViewModel : ViewModelBase
_dialogService = dialogService;
_wpfDataService = wpfDataService;
_mqttAppService = mqttAppService;
- _dataStorageService = dataStorageService;
+ _viewDataService = dataStorageService;
_mapper = mapper;
_navigationService = navigationService;
_notificationService = notificationService;
- _mqttServeise = _dataStorageService.MqttServers.ToNotifyCollectionChanged(x=>x.Value);
+ _mqttServeise = _viewDataService.MqttServers.ToNotifyCollectionChanged(x=>x.Value);
}
[RelayCommand]
diff --git a/DMS.WPF/ViewModels/TriggerDetailViewModel.cs b/DMS.WPF/ViewModels/TriggerDetailViewModel.cs
index 3746988..cfc3462 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 IWpfDataService _dataStorageService;
+ private readonly IViewDataService _viewDataService;
private readonly INavigationService _navigationService;
///
@@ -52,7 +52,7 @@ namespace DMS.WPF.ViewModels
INotificationService notificationService,
ITriggerManagementService triggerManagementService,
ITriggerDataService triggerDataService,
- IWpfDataService dataStorageService,
+ IViewDataService dataStorageService,
INavigationService navigationService)
{
_logger = logger;
@@ -60,7 +60,7 @@ namespace DMS.WPF.ViewModels
_notificationService = notificationService;
_triggerManagementService = triggerManagementService;
_triggerDataService = triggerDataService;
- _dataStorageService = dataStorageService;
+ _viewDataService = dataStorageService;
_navigationService = navigationService;
}
@@ -79,7 +79,7 @@ namespace DMS.WPF.ViewModels
}
// 创建编辑对话框的视图模型
- TriggerDialogViewModel triggerDialogViewModel = new TriggerDialogViewModel(_dialogService, _dataStorageService, _notificationService);
+ TriggerDialogViewModel triggerDialogViewModel = new TriggerDialogViewModel(_dialogService, _viewDataService, _notificationService);
await triggerDialogViewModel.OnInitializedAsync(CurrentTrigger);
// 显示对话框
@@ -157,7 +157,7 @@ namespace DMS.WPF.ViewModels
{
if (parameter == null) return Task.CompletedTask;
- if (_dataStorageService.Triggers.TryGetValue(parameter.TargetId, out var triggerItem))
+ if (_viewDataService.Triggers.TryGetValue(parameter.TargetId, out var triggerItem))
{
CurrentTrigger = triggerItem;
diff --git a/DMS.WPF/ViewModels/TriggersViewModel.cs b/DMS.WPF/ViewModels/TriggersViewModel.cs
index 3b6556b..bea29d3 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 IWpfDataService _dataStorageService;
+ private readonly IViewDataService _viewDataService;
private readonly IDialogService _dialogService;
private readonly INotificationService _notificationService;
private readonly INavigationService _navigationService;
@@ -38,20 +38,20 @@ namespace DMS.WPF.ViewModels
public TriggersViewModel(
IMapper mapper,
ITriggerDataService triggerDataService,
- IWpfDataService dataStorageService,
+ IViewDataService dataStorageService,
IDialogService dialogService,
INotificationService notificationService,
INavigationService navigationService)
{
_mapper = mapper;
_triggerDataService = triggerDataService ?? throw new ArgumentNullException(nameof(triggerDataService));
- _dataStorageService = dataStorageService ?? throw new ArgumentNullException(nameof(dataStorageService));
+ _viewDataService = dataStorageService ?? throw new ArgumentNullException(nameof(dataStorageService));
_dialogService = dialogService ?? throw new ArgumentNullException(nameof(dialogService));
_notificationService = notificationService ?? throw new ArgumentNullException(nameof(notificationService));
_navigationService = navigationService ?? throw new ArgumentNullException(nameof(navigationService));
// 初始化时加载触发器数据
- _synchronizedView = _dataStorageService.Triggers.CreateView(v => v.Value);
+ _synchronizedView = _viewDataService.Triggers.CreateView(v => v.Value);
TriggerItemListView = _synchronizedView.ToNotifyCollectionChanged();
diff --git a/DMS.WPF/ViewModels/VariableHistoryViewModel.cs b/DMS.WPF/ViewModels/VariableHistoryViewModel.cs
index 9781e2f..4b15c26 100644
--- a/DMS.WPF/ViewModels/VariableHistoryViewModel.cs
+++ b/DMS.WPF/ViewModels/VariableHistoryViewModel.cs
@@ -26,8 +26,8 @@ partial class VariableHistoryViewModel : ViewModelBase, INavigatable
private readonly IMapper _mapper;
private readonly IDialogService _dialogService;
private readonly IHistoryAppService _historyAppService;
- private readonly IWPFDataService _wpfDataService;
- private readonly IWpfDataService _dataStorageService;
+ private readonly IViewCenterService _wpfDataService;
+ private readonly IViewDataService _viewDataService;
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, IWpfDataService dataStorageService,
+ IViewCenterService wpfDataService, IViewDataService dataStorageService,
IEventService eventService, INotificationService notificationService,
INavigationService navigationService)
{
@@ -93,7 +93,7 @@ partial class VariableHistoryViewModel : ViewModelBase, INavigatable
_dialogService = dialogService;
_historyAppService = historyAppService;
_wpfDataService = wpfDataService;
- _dataStorageService = dataStorageService;
+ _viewDataService = dataStorageService;
_eventService = eventService;
_notificationService = notificationService;
_navigationService = navigationService;
@@ -179,7 +179,7 @@ partial class VariableHistoryViewModel : ViewModelBase, INavigatable
public override async Task OnNavigatedToAsync(NavigationParameter parameter)
{
- if (_dataStorageService.Variables.TryGetValue(parameter.TargetId, out VariableItem variableItem))
+ if (_viewDataService.Variables.TryGetValue(parameter.TargetId, out VariableItem variableItem))
{
CurrentVariable = variableItem;
// 加载所有变量的历史记录
diff --git a/DMS.WPF/ViewModels/VariableTableViewModel.cs b/DMS.WPF/ViewModels/VariableTableViewModel.cs
index f9fa306..ca98385 100644
--- a/DMS.WPF/ViewModels/VariableTableViewModel.cs
+++ b/DMS.WPF/ViewModels/VariableTableViewModel.cs
@@ -27,6 +27,8 @@ partial class VariableTableViewModel : ViewModelBase, INavigatable
private readonly IDialogService _dialogService;
private readonly IVariableManagementService _variableManagementService;
+ private readonly IAppDataService _appDataService;
+ private readonly IVariableViewService _variableViewService;
private readonly IEventService _eventService;
private readonly IMqttAliasAppService _mqttAliasAppService;
private readonly IMqttAppService _mqttAppService;
@@ -83,9 +85,9 @@ partial class VariableTableViewModel : ViewModelBase, INavigatable
/// 初始化服务、数据仓库和变量数据集合视图。
///
/// 对话服务接口的实例。
- private readonly IWPFDataService _wpfDataService;
+ private readonly IViewCenterService _viewCenterService;
- private readonly IWpfDataService _dataStorageService;
+ private readonly IViewDataService _viewDataService;
private readonly ObservableList _variableItemList;
private readonly ISynchronizedView _synchronizedView;
@@ -97,20 +99,24 @@ partial class VariableTableViewModel : ViewModelBase, INavigatable
private readonly ITriggerVariableAppService _triggerVariableAppService;
public VariableTableViewModel(IMapper mapper, IDialogService dialogService, IVariableManagementService variableManagementService,
+ IAppDataService appDataService,
+ IVariableViewService variableViewService,
IEventService eventService,
IMqttAliasAppService mqttAliasAppService, IMqttAppService mqttAppService,
- IWPFDataService wpfDataService, IWpfDataService dataStorageService,
+ IViewCenterService wpfDataService, IViewDataService dataStorageService,
INotificationService notificationService, ITriggerAppService triggerAppService,
ITriggerVariableAppService triggerVariableAppService)
{
_mapper = mapper;
_dialogService = dialogService;
_variableManagementService = variableManagementService;
+ _appDataService = appDataService;
+ _variableViewService = variableViewService;
_eventService = eventService;
_mqttAliasAppService = mqttAliasAppService;
_mqttAppService = mqttAppService;
- _wpfDataService = wpfDataService;
- _dataStorageService = dataStorageService;
+ _viewCenterService = wpfDataService;
+ _viewDataService = dataStorageService;
_notificationService = notificationService;
_triggerAppService = triggerAppService;
_triggerVariableAppService = triggerVariableAppService;
@@ -247,53 +253,38 @@ partial class VariableTableViewModel : ViewModelBase, INavigatable
{
ImportExcelDialogViewModel
viewModel = App.Current.Services.GetRequiredService();
- List improtVariable = await _dialogService.ShowDialogAsync(viewModel);
+ var improtVariableItems = await _dialogService.ShowDialogAsync(viewModel);
- if (improtVariable == null || improtVariable.Count == 0) return;
+ if (improtVariableItems == null || improtVariableItems.Count == 0) return;
- var improtVariableDtos = _mapper.Map>(improtVariable);
- foreach (var variableDto in improtVariableDtos)
- {
- variableDto.IsActive = true;
- variableDto.CreatedAt = DateTime.Now;
- variableDto.UpdatedAt = DateTime.Now;
- variableDto.VariableTableId = CurrentVariableTable.Id;
- }
- var existList = await _variableManagementService.FindExistingVariablesAsync(improtVariableDtos);
- if (existList.Count > 0)
- {
- // // 拼接要删除的变量名称,用于确认提示
- var existNames = string.Join("、", existList.Select(v => v.Name));
- var confrimDialogViewModel
- = new ConfirmDialogViewModel("存在已经添加的变量", $"变量名称:{existNames},已经存在,是否跳过继续添加其他的变量。取消则不添加任何变量", "继续");
- var res = await _dialogService.ShowDialogAsync(confrimDialogViewModel);
- if (!res) return;
- // 从导入列表中删除已经存在的变量
- improtVariableDtos.RemoveAll(variableDto => existList.Contains(variableDto));
- }
+ //bool flowControl = await CheckExist(improtVariableItems);
+ //if (!flowControl)
+ //{
+ // return;
+ //}
- if (improtVariableDtos.Count != 0)
- {
- var addVariableDtos = await _variableManagementService.BatchImportVariablesAsync(improtVariableDtos);
- if (addVariableDtos is { Count: > 0 })
- {
- List variableItemViewModels = _mapper.Map>(addVariableDtos);
+ //if (improtVariableDtos.Count != 0)
+ //{
+ // var addVariableDtos = await _variableManagementService.AddAsync(improtVariableDtos);
+ // if (addVariableDtos is { Count: > 0 })
+ // {
+ // List variableItemViewModels = _mapper.Map>(addVariableDtos);
- _variableItemList.AddRange(variableItemViewModels);
- //更新数据中心
- foreach (var variableItemViewModel in variableItemViewModels)
- {
- CurrentVariableTable.Variables.Add(variableItemViewModel);
- }
+ // _variableItemList.AddRange(variableItemViewModels);
+ // //更新数据中心
+ // foreach (var variableItemViewModel in variableItemViewModels)
+ // {
+ // CurrentVariableTable.Variables.Add(variableItemViewModel);
+ // }
- _notificationService.ShowSuccess($"从Excel导入变量成功,共导入变量:{improtVariableDtos.Count}个");
- }
- }
- else
- {
- _notificationService.ShowSuccess($"列表中没有要添加的变量了。 ");
- }
+ // _notificationService.ShowSuccess($"从Excel导入变量成功,共导入变量:{improtVariableDtos.Count}个");
+ // }
+ //}
+ //else
+ //{
+ // _notificationService.ShowSuccess($"列表中没有要添加的变量了。 ");
+ //}
}
catch (Exception e)
{
@@ -328,52 +319,24 @@ partial class VariableTableViewModel : ViewModelBase, INavigatable
ImportOpcUaDialogViewModel importOpcUaDialogViewModel
= App.Current.Services.GetRequiredService();
importOpcUaDialogViewModel.EndpointUrl = opcUaEndpointUrl; // 设置Endpoint URL
- var importedVariables = await _dialogService.ShowDialogAsync(importOpcUaDialogViewModel);
- if (importedVariables == null || !importedVariables.Any())
+ var importedVariableItems = await _dialogService.ShowDialogAsync(importOpcUaDialogViewModel);
+ if (importedVariableItems == null || !importedVariableItems.Any()) return; // 用户取消或没有选择任何变量
+
+ //检查重复变量并询问是否继续
+ bool flowControl = await CheckExist(importedVariableItems);
+ if (!flowControl)
{
- return; // 用户取消或没有选择任何变量
- }
-
-
-
- // 将导入的变量转换为DTO并设置必要的属性
- var importedVariableDtos = _mapper.Map>(importedVariables);
- foreach (var variableDto in importedVariableDtos)
- {
- variableDto.CreatedAt = DateTime.Now;
- variableDto.UpdatedAt = DateTime.Now;
- variableDto.VariableTableId = CurrentVariableTable.Id;
- }
-
- // 检查是否存在同名变量
- var existList = await _variableManagementService.FindExistingVariablesAsync(importedVariableDtos);
- if (existList.Count > 0)
- {
- // 拼接要删除的变量名称,用于确认提示
- var existNames = string.Join("、", existList.Select(v => v.Name));
- var confirmDialogViewModel
- = new ConfirmDialogViewModel("存在已经添加的变量", $"变量名称:{existNames},已经存在,是否跳过继续添加其他的变量。取消则不添加任何变量", "继续");
- var res = await _dialogService.ShowDialogAsync(confirmDialogViewModel);
- if (!res) return;
- // 从导入列表中删除已经存在的变量
- importedVariableDtos.RemoveAll(variableDto => existList.Contains(variableDto));
+ return;
}
// 如果还有变量需要导入,则执行导入操作
- if (importedVariableDtos.Count != 0)
+ if (importedVariableItems.Any())
{
- var addVariableDtos = await _variableManagementService.BatchImportVariablesAsync(importedVariableDtos);
- if (addVariableDtos is { Count: > 0 })
+ var res = await _variableViewService.AddAsync(importedVariableItems, CurrentVariableTable);
+
+ if (res)
{
- List variableItemViewModels = _mapper.Map>(addVariableDtos);
- _variableItemList.AddRange(variableItemViewModels);
-
- foreach (var variableItemViewModel in variableItemViewModels)
- {
- _dataStorageService.Variables.TryAdd(variableItemViewModel.Id, variableItemViewModel);
- CurrentVariableTable.Variables.Add(variableItemViewModel);
- }
- _notificationService.ShowSuccess($"从OPC UA服务器导入变量成功,共导入变量:{importedVariableDtos.Count}个");
+ _notificationService.ShowSuccess($"从OPC UA服务器导入变量成功,共导入变量:{importedVariableItems.Count}个");
}
else
{
@@ -391,6 +354,25 @@ partial class VariableTableViewModel : ViewModelBase, INavigatable
}
}
+ private async Task CheckExist(List importedVariableItems)
+ {
+ // 检查是否存在同名变量
+ List existList = _variableViewService.CheckExistingVariables(importedVariableItems, CurrentVariableTable.Device);
+ if (existList.Count > 0)
+ {
+ // 拼接要删除的变量名称,用于确认提示
+ var existNames = string.Join("、", existList.Select(v => v.Name));
+ var confirmDialogViewModel
+ = new ConfirmDialogViewModel("存在已经添加的变量", $"变量名称:{existNames},已经存在,是否跳过继续添加其他的变量。取消则不添加任何变量", "继续");
+ var res = await _dialogService.ShowDialogAsync(confirmDialogViewModel);
+ if (!res) return false;
+ // 从导入列表中删除已经存在的变量
+ importedVariableItems.RemoveAll(variableDto => existList.Contains(variableDto));
+ }
+
+ return true;
+ }
+
//
///
@@ -430,7 +412,7 @@ partial class VariableTableViewModel : ViewModelBase, INavigatable
_mapper.Map(addVariable, variableItemViewModel);
// // 更新当前页面显示的数据:将新变量添加到集合中
_variableItemList.Add(variableItemViewModel);
- _wpfDataService.VariableDataService.AddVariable(variableItemViewModel);
+ _viewCenterService.VariableDataService.AddVariable(variableItemViewModel);
//
// // 显示成功通知
_notificationService.ShowSuccess($"添加变量成功:{variableItemViewModel.Name}");
@@ -471,16 +453,17 @@ partial class VariableTableViewModel : ViewModelBase, INavigatable
if (!isDel)
return; // 如果用户取消删除,则返回
+
+
// 从数据库中删除变量数据
- var result = await _variableManagementService.DeleteVariablesAsync(variablesToDelete.Select(v => v.Id)
- .ToList());
+ var result = await _viewCenterService.VariableDataService.DeleteAsync(variablesToDelete);
if (result)
{
foreach (var variable in variablesToDelete)
{
_variableItemList.Remove(variable);
- _wpfDataService.VariableDataService.DeleteVariable(variable.Id);
+ _viewCenterService.VariableDataService.DeleteVariable(variable.Id);
}
// 显示成功通知
@@ -632,7 +615,7 @@ partial class VariableTableViewModel : ViewModelBase, INavigatable
// 为每个变量分配MQTT别名
foreach (var editedVariableMqtt in editedVariableMqtts)
{
- var mqttAliasItem = await _wpfDataService.MqttAliasDataService.AssignAliasAsync(editedVariableMqtt);
+ var mqttAliasItem = await _viewCenterService.MqttAliasDataService.AssignAliasAsync(editedVariableMqtt);
if (mqttAliasItem is not null)
{
totalAffectedCount++;
@@ -926,7 +909,7 @@ partial class VariableTableViewModel : ViewModelBase, INavigatable
public override async Task OnNavigatedToAsync(NavigationParameter parameter)
{
- if (_dataStorageService.VariableTables.TryGetValue(parameter.TargetId, out var varTable))
+ if (_viewDataService.VariableTables.TryGetValue(parameter.TargetId, out var varTable))
{
CurrentVariableTable = varTable;
// 根据变量表的协议类型设置对应的布尔属性