diff --git a/DMS.Application/DMS.Application.csproj b/DMS.Application/DMS.Application.csproj
index f3717bb..6e15a12 100644
--- a/DMS.Application/DMS.Application.csproj
+++ b/DMS.Application/DMS.Application.csproj
@@ -13,4 +13,8 @@
+
+
+
+
diff --git a/DMS.Core/Helper/NlogHelper.cs b/DMS.Core/Helper/NlogHelper.cs
index 1318335..1e4fe7a 100644
--- a/DMS.Core/Helper/NlogHelper.cs
+++ b/DMS.Core/Helper/NlogHelper.cs
@@ -5,7 +5,7 @@ using System.Runtime.CompilerServices;
using System.Threading;
using NLog;
-namespace DMS.Helper;
+namespace DMS.Core.Helper;
///
/// NLog 日志帮助类,提供简化的日志记录方法,并自动捕获调用者信息。
diff --git a/DMS.Core/Interfaces/IDatabaseService.cs b/DMS.Core/Interfaces/IDatabaseService.cs
new file mode 100644
index 0000000..477df1f
--- /dev/null
+++ b/DMS.Core/Interfaces/IDatabaseService.cs
@@ -0,0 +1,10 @@
+using System.Threading.Tasks;
+
+namespace DMS.Core.Interfaces
+{
+ public interface IDatabaseService
+ {
+ void InitializeDataBase();
+ Task InitializeMenu();
+ }
+}
\ No newline at end of file
diff --git a/DMS.Core/Interfaces/IDbContext.cs b/DMS.Core/Interfaces/IDbContext.cs
new file mode 100644
index 0000000..485e41f
--- /dev/null
+++ b/DMS.Core/Interfaces/IDbContext.cs
@@ -0,0 +1,18 @@
+using System.Threading.Tasks;
+
+namespace DMS.Core.Interfaces
+{
+ public interface IDbContext
+ {
+ // Define common database operations here, e.g.,
+ // Task GetByIdAsync(int id) where TEntity : class;
+ // Task AddAsync(TEntity entity) where TEntity : class;
+ // Task UpdateAsync(TEntity entity) where TEntity : class;
+ // Task DeleteAsync(TEntity entity) where TEntity : class;
+ // SqlSugarClient GetClient(); // This should NOT be here if you want to hide SqlSugar
+
+ // For now, we'll just keep it empty or add methods as needed.
+ // The primary goal is to abstract away SqlSugarClient.
+ // The IUnitOfWork already handles transactions.
+ }
+}
\ No newline at end of file
diff --git a/DMS.Core/Interfaces/IDeviceRepository.cs b/DMS.Core/Interfaces/IDeviceRepository.cs
new file mode 100644
index 0000000..c9fe099
--- /dev/null
+++ b/DMS.Core/Interfaces/IDeviceRepository.cs
@@ -0,0 +1,18 @@
+using DMS.Core.Models;
+using DMS.Core.Enums;
+using System.Collections.Generic;
+using System.Threading.Tasks;
+
+namespace DMS.Core.Interfaces
+{
+ public interface IDeviceRepository
+ {
+ Task UpdateAsync(Device device);
+
+ Task> GetAllAsync();
+ Task GetByIdAsync(int id);
+ Task DeleteAsync(Device device, List menus);
+
+ Task AddAsync(Device device);
+ }
+}
\ No newline at end of file
diff --git a/DMS.Core/Interfaces/IMenuRepository.cs b/DMS.Core/Interfaces/IMenuRepository.cs
new file mode 100644
index 0000000..26436c4
--- /dev/null
+++ b/DMS.Core/Interfaces/IMenuRepository.cs
@@ -0,0 +1,23 @@
+using DMS.Core.Models;
+using DMS.Core.Enums;
+using SqlSugar;
+using System.Collections.Generic;
+using System.Threading.Tasks;
+
+namespace DMS.Core.Interfaces
+{
+ public interface IMenuRepository
+ {
+ Task DeleteAsync(MenuBean menu);
+ Task DeleteAsync(MenuBean menu, SqlSugarClient db);
+ Task> GetMenuTreesAsync();
+ Task AddAsync(MenuBean menu);
+ Task AddAsync(MenuBean menu, SqlSugarClient db);
+ Task AddVarTableMenuAsync(Device dbDevice, int parentMenuId, SqlSugarClient db);
+ Task AddAsync(Device device, SqlSugarClient db);
+ Task UpdateAsync(MenuBean menu);
+
+ Task GetMenuByDataIdAsync(int dataId, MenuType menuType);
+ Task GetMainMenuByNameAsync(string name);
+ }
+}
\ No newline at end of file
diff --git a/DMS.Core/Interfaces/IMqttRepository.cs b/DMS.Core/Interfaces/IMqttRepository.cs
new file mode 100644
index 0000000..b7d3ed0
--- /dev/null
+++ b/DMS.Core/Interfaces/IMqttRepository.cs
@@ -0,0 +1,15 @@
+using DMS.Core.Models;
+using System.Collections.Generic;
+using System.Threading.Tasks;
+
+namespace DMS.Core.Interfaces
+{
+ public interface IMqttRepository
+ {
+ Task GetByIdAsync(int id);
+ Task> GetAllAsync();
+ Task AddAsync(Mqtt mqtt);
+ Task UpdateAsync(Mqtt mqtt);
+ Task DeleteAsync(Mqtt mqtt);
+ }
+}
\ No newline at end of file
diff --git a/DMS.Core/Interfaces/IUnitOfWork.cs b/DMS.Core/Interfaces/IUnitOfWork.cs
new file mode 100644
index 0000000..f05ebfb
--- /dev/null
+++ b/DMS.Core/Interfaces/IUnitOfWork.cs
@@ -0,0 +1,11 @@
+using System.Threading.Tasks;
+
+namespace DMS.Core.Interfaces
+{
+ public interface IUnitOfWork
+ {
+ Task BeginTranAsync();
+ Task CommitTranAsync();
+ Task RollbackTranAsync();
+ }
+}
\ No newline at end of file
diff --git a/DMS.Core/Interfaces/IUserRepository.cs b/DMS.Core/Interfaces/IUserRepository.cs
new file mode 100644
index 0000000..b3e5dea
--- /dev/null
+++ b/DMS.Core/Interfaces/IUserRepository.cs
@@ -0,0 +1,15 @@
+using DMS.Core.Models;
+using System.Collections.Generic;
+using System.Threading.Tasks;
+
+namespace DMS.Core.Interfaces
+{
+ public interface IUserRepository
+ {
+ Task GetByIdAsync(int id);
+ Task> GetAllAsync();
+ Task AddAsync(User user);
+ Task UpdateAsync(User user);
+ Task DeleteAsync(int id);
+ }
+}
\ No newline at end of file
diff --git a/DMS.Core/Interfaces/IVarDataRepository.cs b/DMS.Core/Interfaces/IVarDataRepository.cs
new file mode 100644
index 0000000..cae0eab
--- /dev/null
+++ b/DMS.Core/Interfaces/IVarDataRepository.cs
@@ -0,0 +1,30 @@
+using System.Collections.Generic;
+using System.Threading.Tasks;
+using DMS.Core.Models;
+using SqlSugar;
+
+namespace DMS.Core.Interfaces
+{
+ public interface IVarDataRepository
+ {
+ Task GetByIdAsync(int id);
+ Task GetByIdAsync(int id, SqlSugarClient db);
+ Task> GetAllAsync();
+ Task> GetAllAsync(SqlSugarClient db);
+ Task> GetByVariableTableIdAsync(int varTableId);
+ Task> GetByVariableTableIdAsync(int varTableId, SqlSugarClient db);
+ Task AddAsync(Variable variable);
+ Task AddAsync(Variable variable, SqlSugarClient db);
+ Task AddAsync(IEnumerable variableDatas);
+ Task AddAsync(IEnumerable variableDatas, SqlSugarClient db);
+ Task UpdateAsync(Variable variable);
+ Task UpdateAsync(Variable variable, SqlSugarClient db);
+ Task UpdateAsync(List variableDatas);
+ Task UpdateAsync(List variableDatas, SqlSugarClient db);
+ Task DeleteAsync(Variable variable);
+ Task DeleteAsync(Variable variable, SqlSugarClient db);
+ Task DeleteAsync(IEnumerable variableDatas);
+
+ Task AddMqttToVariablesAsync(IEnumerable variableMqttList);
+ }
+}
\ No newline at end of file
diff --git a/DMS.Core/Interfaces/IVarTableRepository.cs b/DMS.Core/Interfaces/IVarTableRepository.cs
new file mode 100644
index 0000000..063afe0
--- /dev/null
+++ b/DMS.Core/Interfaces/IVarTableRepository.cs
@@ -0,0 +1,17 @@
+using System.Collections.Generic;
+using System.Threading.Tasks;
+using DMS.Core.Models;
+
+namespace DMS.Core.Interfaces
+{
+ public interface IVarTableRepository
+ {
+ Task AddAsync(VariableTable varTable);
+ Task AddAsync(VariableTable variableTable, SqlSugarClient db);
+ Task UpdateAsync(VariableTable variableTable);
+ Task UpdateAsync(VariableTable variableTable, SqlSugarClient db);
+ Task DeleteAsync(VariableTable variableTable);
+ Task DeleteAsync(VariableTable varTable, SqlSugarClient db);
+
+ }
+}
\ No newline at end of file
diff --git a/DMS.Core/Interfaces/IVariableMqttAliasRepository.cs b/DMS.Core/Interfaces/IVariableMqttAliasRepository.cs
new file mode 100644
index 0000000..868ffcf
--- /dev/null
+++ b/DMS.Core/Interfaces/IVariableMqttAliasRepository.cs
@@ -0,0 +1,18 @@
+using DMS.Core.Models;
+using System.Collections.Generic;
+using System.Threading.Tasks;
+
+namespace DMS.Core.Interfaces
+{
+ public interface IVariableMqttAliasRepository
+ {
+ Task GetAliasByVariableAndMqtt(int variableDataId, int mqttId);
+ Task GetAliasByVariableAndMqtt(int variableDataId, int mqttId, SqlSugarClient db);
+ Task AddManyAsync(IEnumerable entities);
+ Task AddManyAsync(IEnumerable entities, SqlSugarClient db);
+ Task UpdateAliasAsync(int variableDataId, int mqttId, string newAlias);
+ Task UpdateAliasAsync(int variableDataId, int mqttId, string newAlias, SqlSugarClient db);
+ Task DeleteAsync(int variableDataId, int mqttId);
+
+ }
+}
\ No newline at end of file
diff --git a/DMS.Core/Models/Device.cs b/DMS.Core/Models/Device.cs
index f223c1e..aa2ee60 100644
--- a/DMS.Core/Models/Device.cs
+++ b/DMS.Core/Models/Device.cs
@@ -3,7 +3,7 @@ using System.Collections.ObjectModel;
using DMS.Core.Enums;
-namespace DMS.Models;
+namespace DMS.Core.Models;
///
/// 表示设备信息。
@@ -13,7 +13,7 @@ public partial class Device
///
/// 设备的描述信息。
///
- private string description;
+ public string Description { get; set; }
///
/// 设备的类型。
@@ -23,53 +23,53 @@ public partial class Device
///
/// 设备的唯一标识符。
///
- private int id;
+ public int Id { get; set; }
///
/// 设备的IP地址。
///
- private string ip;
+ public string Ip { get; set; }
///
/// 表示设备是否处于活动状态。
///
- private bool isActive = true;
+ public bool IsActive { get; set; } = true;
///
/// 表示是否添加默认变量表。
///
- private bool isAddDefVarTable = true;
+ public bool IsAddDefVarTable { get; set; } = true;
///
/// 表示设备是否正在运行。
///
- private bool isRuning;
+ public bool IsRuning { get; set; }
///
/// 设备的名称。
///
- private string name;
+ public string Name { get; set; }
///
/// 设备的端口号。
///
- private int prot;
+ public int Prot { get; set; }
///
/// PLC的CPU类型。
///
- //private CpuType cpuType;
+ //public CpuType cpuType;
///
/// PLC的机架号。
///
- private short rack;
+ public short Rack { get; set; }
///
/// PLC的槽号。
///
- private short slot;
+ public short Slot { get; set; }
///
/// 设备的通信协议类型。
@@ -79,7 +79,7 @@ public partial class Device
///
/// OPC UA Endpoint URL。
///
- private string? opcUaEndpointUrl;
+ public string OpcUaEndpointUrl { get; set; }=String.Empty;
///
/// 设备关联的变量表列表。
diff --git a/DMS.Core/Models/MenuBean.cs b/DMS.Core/Models/MenuBean.cs
index 71f4171..d1afedd 100644
--- a/DMS.Core/Models/MenuBean.cs
+++ b/DMS.Core/Models/MenuBean.cs
@@ -1,6 +1,6 @@
using DMS.Core.Enums;
-namespace DMS.Models;
+namespace DMS.Core.Models;
///
/// 表示菜单项。
diff --git a/DMS.Core/Models/Mqtt.cs b/DMS.Core/Models/Mqtt.cs
index 57e8de7..358f65a 100644
--- a/DMS.Core/Models/Mqtt.cs
+++ b/DMS.Core/Models/Mqtt.cs
@@ -1,6 +1,6 @@
using DMS.Core.Enums;
-namespace DMS.Models;
+namespace DMS.Core.Models;
///
/// 表示MQTT配置信息。
diff --git a/DMS.Core/Models/Notification.cs b/DMS.Core/Models/Notification.cs
index 4c8b7e3..2d825d5 100644
--- a/DMS.Core/Models/Notification.cs
+++ b/DMS.Core/Models/Notification.cs
@@ -1,6 +1,6 @@
using DMS.Core.Enums;
-namespace DMS.Models;
+namespace DMS.Core.Models;
///
/// 表示通知信息。
diff --git a/DMS.Core/Models/OpcUaNode.cs b/DMS.Core/Models/OpcUaNode.cs
index d3c604c..edca7c8 100644
--- a/DMS.Core/Models/OpcUaNode.cs
+++ b/DMS.Core/Models/OpcUaNode.cs
@@ -1,6 +1,6 @@
using System.Collections.ObjectModel;
-namespace DMS.Models;
+namespace DMS.Core.Models;
///
/// 表示OPC UA节点,用于构建节点树。
diff --git a/DMS.Core/Models/User.cs b/DMS.Core/Models/User.cs
index 2b26fe4..08d670a 100644
--- a/DMS.Core/Models/User.cs
+++ b/DMS.Core/Models/User.cs
@@ -1,4 +1,4 @@
-namespace DMS.Models;
+namespace DMS.Core.Models;
public class User
{
diff --git a/DMS.Core/Models/Variable.cs b/DMS.Core/Models/Variable.cs
index 41b87a2..2c58622 100644
--- a/DMS.Core/Models/Variable.cs
+++ b/DMS.Core/Models/Variable.cs
@@ -1,6 +1,6 @@
using DMS.Core.Enums;
-namespace DMS.Models;
+namespace DMS.Core.Models;
///
/// 表示变量数据信息。
@@ -15,7 +15,7 @@ public partial class Variable
///
/// 变量名称。
///
- private string name;
+ public string Name { get; set; }
///
/// 节点ID,用于标识变量在设备或系统中的唯一路径。
@@ -41,7 +41,7 @@ public partial class Variable
///
/// 变量描述。
///
- private string description = String.Empty;
+ public string Description { get; set; } = String.Empty;
///
/// 协议类型,例如Modbus、OPC UA等。
@@ -61,22 +61,22 @@ public partial class Variable
///
/// 变量当前原始数据值。
///
- private string dataValue = String.Empty;
+ public string DataValue { get; set; } = String.Empty;
///
/// 变量经过转换或格式化后的显示值。
///
- private string displayValue = String.Empty;
+ public string DisplayValue { get; set; } = String.Empty;
///
/// 指示变量是否处于激活状态。
///
- public bool isActive;
+ public bool IsActive { get; set; }
///
/// 指示变量是否被选中
///
- public bool isSelect;
+ public bool IsSelect { get; set; }
///
/// 指示是否需要保存变量数据。
@@ -91,12 +91,12 @@ public partial class Variable
///
/// 轮询级别,例如1秒、5秒等。
///
- private PollLevelType pollLevelType = PollLevelType.ThirtySeconds;
+ public PollLevelType PollLevelType { get; set; } = PollLevelType.ThirtySeconds;
///
/// OPC UA更新类型,例如轮询或订阅。
///
- private OpcUaUpdateType opcUaUpdateType = OpcUaUpdateType.OpcUaPoll;
+ public OpcUaUpdateType OpcUaUpdateType { get; set; } = OpcUaUpdateType.OpcUaPoll;
///
/// 最后一次轮询时间。
@@ -111,7 +111,7 @@ public partial class Variable
///
/// 指示变量是否已被修改了。
///
- private bool isModified;
+ public bool IsModified { get; set; }
///
/// 报警的最大值阈值。
@@ -126,7 +126,7 @@ public partial class Variable
///
/// 数据转换规则或表达式。
///
- private string converstion = String.Empty;
+ public string Converstion { get; set; } = String.Empty;
///
/// 数据保存的范围或阈值。
@@ -136,13 +136,13 @@ public partial class Variable
///
/// 变量数据创建时间。
///
- private DateTime createTime;
+ public DateTime CreateTime { get; set; }
///
/// 变量数据最后更新时间。
///
- private DateTime updateTime = DateTime.Now;
+ public DateTime UpdateTime { get; set; } = DateTime.Now;
///
/// 最后更新变量数据的用户。
diff --git a/DMS.Core/Models/VariableContext.cs b/DMS.Core/Models/VariableContext.cs
index f023cc5..4ffa76f 100644
--- a/DMS.Core/Models/VariableContext.cs
+++ b/DMS.Core/Models/VariableContext.cs
@@ -1,6 +1,6 @@
-using DMS.Models;
+using DMS.Core.Models;
-namespace DMS.Models
+namespace DMS.Core.Models
{
public class VariableContext
{
diff --git a/DMS.Core/Models/VariableMqtt.cs b/DMS.Core/Models/VariableMqtt.cs
index c2604c2..c9a523b 100644
--- a/DMS.Core/Models/VariableMqtt.cs
+++ b/DMS.Core/Models/VariableMqtt.cs
@@ -1,7 +1,7 @@
using System;
using DMS.Core.Enums;
-namespace DMS.Models;
+namespace DMS.Core.Models;
///
/// 表示变量数据与MQTT服务器之间的关联模型,包含MQTT别名。
diff --git a/DMS.Core/Models/VariableTable.cs b/DMS.Core/Models/VariableTable.cs
index dbcc3c5..04fc60a 100644
--- a/DMS.Core/Models/VariableTable.cs
+++ b/DMS.Core/Models/VariableTable.cs
@@ -2,7 +2,7 @@
using System.ComponentModel;
using DMS.Core.Enums;
-namespace DMS.Models;
+namespace DMS.Core.Models;
///
/// 表示变量表信息。
@@ -22,7 +22,7 @@ public partial class VariableTable
///
/// 变量表描述。
///
- private string description;
+ public string Description { get; set; }
///
/// 变量表中包含的数据变量列表。
@@ -37,12 +37,12 @@ public partial class VariableTable
///
/// 表示变量表是否处于活动状态。
///
- private bool isActive;
+ public bool IsActive { get; set; }
///
/// 变量表名称。
///
- private string name;
+ public string Name { get; set; }
///
/// 变量表使用的协议类型。
diff --git a/DMS.Infrastructure/DMS.Infrastructure.csproj b/DMS.Infrastructure/DMS.Infrastructure.csproj
index 2de6fef..d175684 100644
--- a/DMS.Infrastructure/DMS.Infrastructure.csproj
+++ b/DMS.Infrastructure/DMS.Infrastructure.csproj
@@ -21,7 +21,7 @@
-
+
diff --git a/DMS.Infrastructure/Data/SqlSugarDbContext.cs b/DMS.Infrastructure/Data/SqlSugarDbContext.cs
index c8ad1b7..25a0d68 100644
--- a/DMS.Infrastructure/Data/SqlSugarDbContext.cs
+++ b/DMS.Infrastructure/Data/SqlSugarDbContext.cs
@@ -1,25 +1,46 @@
-using DMS.Config;
+using DMS.Config;
+using DMS.Core.Interfaces;
using SqlSugar;
+using System;
+using System.Threading.Tasks;
-namespace DMS.Infrastructure;
+namespace DMS.Infrastructure.Data;
-public class DbContext
+public class SqlSugarDbContext : IUnitOfWork
{
- public static SqlSugarClient GetInstance()
+ private readonly SqlSugarClient _db;
+
+ public SqlSugarDbContext(ConnectionSettings settings)
{
- var settings = ConnectionSettings.Load();
var connectionString = settings.ToConnectionString();
var dbType = (SqlSugar.DbType)Enum.Parse(typeof(SqlSugar.DbType), settings.DbType);
- var _db = new SqlSugarClient(new ConnectionConfig
+ _db = new SqlSugarClient(new ConnectionConfig
{
ConnectionString = connectionString,
- DbType = dbType, // 根据实际数据库类型修改,如DbType.MySql等
+ DbType = dbType,
IsAutoCloseConnection = true,
InitKeyType = InitKeyType.Attribute
});
+ }
-
+ public SqlSugarClient GetSqlSugarClient()
+ {
return _db;
}
+
+ public async Task BeginTranAsync()
+ {
+ await _db.BeginTranAsync();
+ }
+
+ public async Task CommitTranAsync()
+ {
+ await _db.CommitTranAsync();
+ }
+
+ public async Task RollbackTranAsync()
+ {
+ await _db.RollbackTranAsync();
+ }
}
\ No newline at end of file
diff --git a/DMS.Infrastructure/Entities/DbDevice.cs b/DMS.Infrastructure/Entities/DbDevice.cs
index c1893b4..dd68756 100644
--- a/DMS.Infrastructure/Entities/DbDevice.cs
+++ b/DMS.Infrastructure/Entities/DbDevice.cs
@@ -2,8 +2,7 @@ using SqlSugar;
using SqlSugar.DbConvert;
using S7.Net;
using DMS.Core.Enums;
-
-namespace DMS.Infrastructure.Entities;
+using DMS.Infrastructure.Entities;
///
/// 表示数据库中的设备实体。
@@ -76,7 +75,7 @@ public class DbDevice
/// 设备的通信协议类型。
///
[SugarColumn(ColumnDataType = "varchar(20)", SqlParameterDbType = typeof(EnumToStringConvert))]
- public Enums_ProtocolType ProtocolType { get; set; }
+ public ProtocolType ProtocolType { get; set; }
///
/// OPC UA Endpoint URL。
diff --git a/DMS.Infrastructure/Profiles/MappingProfile.cs b/DMS.Infrastructure/Profiles/MappingProfile.cs
index 4affa9d..a30a38f 100644
--- a/DMS.Infrastructure/Profiles/MappingProfile.cs
+++ b/DMS.Infrastructure/Profiles/MappingProfile.cs
@@ -1,9 +1,9 @@
using System;
using AutoMapper;
using DMS.Infrastructure.Entities;
-using DMS.Models;
+using DMS.Core.Models;
-namespace DMS.Profiles;
+namespace DMS.Infrastructure.Profiles;
///
/// AutoMapper 的配置类,用于定义对象之间的映射规则。
diff --git a/DMS.Infrastructure/Repositories/DeviceRepository.cs b/DMS.Infrastructure/Repositories/DeviceRepository.cs
index 532f4c0..fe7a264 100644
--- a/DMS.Infrastructure/Repositories/DeviceRepository.cs
+++ b/DMS.Infrastructure/Repositories/DeviceRepository.cs
@@ -2,28 +2,30 @@ using System.Diagnostics;
using AutoMapper;
using DMS.Infrastructure.Entities;
using DMS.Core.Enums;
-using DMS.Helper;
-using DMS.Models;
-using iNKORE.UI.WPF.Modern.Common.IconKeys;
-using DMS.Extensions;
+using DMS.Core.Helper;
+using DMS.Core.Models;
+using DMS.Infrastructure.Data;
using SqlSugar;
namespace DMS.Infrastructure.Repositories;
-public class DeviceRepository
+public class DeviceRepository : IDeviceRepository
{
private readonly IMapper _mapper;
- private readonly MenuRepository _menuRepository;
- private readonly VarTableRepository _varTableRepository;
+ private readonly IMenuRepository _menuRepository;
+ private readonly IVarTableRepository _varTableRepository;
+ private readonly IUnitOfWork _unitOfWork;
- public DeviceRepository(IMapper mapper,MenuRepository menuRepository,VarTableRepository varTableRepository)
+ public DeviceRepository(IMapper mapper, IMenuRepository menuRepository, IVarTableRepository varTableRepository, IUnitOfWork unitOfWork)
{
_mapper = mapper;
_menuRepository = menuRepository;
_varTableRepository = varTableRepository;
+ _unitOfWork = unitOfWork;
}
+
///
/// 编辑设备信息。
///
@@ -33,25 +35,7 @@ public class DeviceRepository
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
- using (var db = DbContext.GetInstance())
- {
- var result = await UpdateAsync(device, db);
- stopwatch.Stop();
- NlogHelper.Info($"编辑设备 '{device.Name}' 耗时:{stopwatch.ElapsedMilliseconds}ms");
- return result;
- }
- }
-
- ///
- /// 编辑设备信息。支持事务
- ///
- /// 要编辑的设备对象。
- /// 受影响的行数。
- public async Task UpdateAsync(Device device, SqlSugarClient db)
- {
- Stopwatch stopwatch = new Stopwatch();
- stopwatch.Start();
-
+ var db = _unitOfWork.GetInstance();
var result = await db.Updateable(_mapper.Map(device))
.ExecuteCommandAsync();
stopwatch.Stop();
@@ -59,6 +43,8 @@ public class DeviceRepository
return result;
}
+
+
///
/// 获取设备列表
@@ -73,13 +59,13 @@ public class DeviceRepository
var dlist = await db.Queryable()
.Includes(d => d.VariableTables, dv => dv.Device)
.Includes(d => d.VariableTables, dvd => dvd.Variables, data => data.VariableTable)
- .Includes(d=>d.VariableTables,vt=>vt.Variables,v=>v.VariableMqtts )
+ .Includes(d => d.VariableTables, vt => vt.Variables, v => v.VariableMqtts)
.ToListAsync();
-
+
stopwatch.Stop();
NlogHelper.Info($"加载设备列表总耗时:{stopwatch.ElapsedMilliseconds}ms");
- var devices= _mapper.Map>(dlist);
+ var devices = _mapper.Map>(dlist);
return devices;
}
}
@@ -111,59 +97,23 @@ public class DeviceRepository
/// 受影响的行数。
public async Task DeleteAsync(Device device, List menus)
{
- using (var db = DbContext.GetInstance())
- {
- await db.BeginTranAsync();
- try
- {
- Stopwatch stopwatch = new Stopwatch();
- stopwatch.Start();
- var res = await DeleteAsync(device, menus, db);
-
- stopwatch.Stop();
- NlogHelper.Info($"删除设备:{device.Name},耗时:{stopwatch.ElapsedMilliseconds}ms");
- await db.CommitTranAsync();
- return res;
- }
- catch (Exception e)
- {
- await db.RollbackTranAsync();
- throw;
- }
-
- return 0;
- }
- }
-
-
- ///
- /// 删除设备。
- ///
- ///
- ///
- ///
- /// 要删除的设备ID。
- /// 受影响的行数。
- public async Task DeleteAsync(Device device, List menus, SqlSugarClient db)
- {
+ var db = _unitOfWork.GetInstance();
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
var result = await db.Deleteable(new DbDevice { Id = device.Id })
.ExecuteCommandAsync();
// 删除变量表
- await _varTableRepository.DeleteAsync(device.VariableTables, db);
+ await _varTableRepository.DeleteAsync(device.VariableTables);
- // 删除菜单
- var menu = DataServicesHelper.FindMenusForDevice(device, menus);
- if (menu == null)
- throw new NullReferenceException($"没有找到设备:{device.Name},的菜单对象。");
- await _menuRepository.DeleteAsync(menu, db);
stopwatch.Stop();
NlogHelper.Info($"删除设备:{device.Name},耗时:{stopwatch.ElapsedMilliseconds}ms");
return result;
}
+
+
+
///
/// 添加设备
///
@@ -172,86 +122,25 @@ public class DeviceRepository
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
- var db = DbContext.GetInstance();
- try
- {
- // 开启事务
- await db.BeginTranAsync();
- //查询设备的名字是否存在
+ var db = _unitOfWork.GetInstance();
- var exist = await db.Queryable()
- .Where(d => d.Name == device.Name)
- .FirstAsync();
- if (exist != null)
- throw new InvalidOperationException("设备名称已经存在。");
+ //查询设备的名字是否存在
+ var exist = await db.Queryable()
+ .Where(d => d.Name == device.Name)
+ .FirstAsync();
+ if (exist != null)
+ throw new InvalidOperationException("设备名称已经存在。");
- // 2. 将设备添加到数据库
- var addDevice = await AddAsync(device, db);
-
-
- await db.CommitTranAsync();
- // 菜单也添加成功,通知 UI 更新
- MessageHelper.SendLoadMessage(LoadTypes.Menu);
- MessageHelper.SendLoadMessage(LoadTypes.Devices);
- }
- catch (Exception e)
- {
- // 中间出错了 回滚
- await db.RollbackTranAsync();
- // 捕获并记录所有未预期的异常
- NotificationHelper.ShowError("添加设备的过程中发生了不可预期的错误:" + e.Message, e);
- }
- finally
- {
- stopwatch.Stop();
- NlogHelper.Info($"添加设备 '{device.Name}' 及相关菜单耗时:{stopwatch.ElapsedMilliseconds}ms");
- }
- }
-
- ///
- /// 单独添加设备,不包括菜单和变量表
- ///
- ///
- ///
- ///
- ///
- private async Task AddAsync(Device device, SqlSugarClient db)
- {
- ;
- // 添加设备
+ // 2. 将设备添加到数据库
var addDevice = await db.Insertable(_mapper.Map(device))
.ExecuteReturnEntityAsync();
// 4. 为新设备添加菜单
- var addDeviceMenuId = await _menuRepository.AddAsync(addDevice, db);
-
- if (device.IsAddDefVarTable)
- {
- // 添加默认变量表
- var varTable = new VariableTable();
- device.VariableTables = new ();
- varTable.IsActive = true;
- varTable.DeviceId = addDevice.Id;
- varTable.Name = "默认变量表";
- varTable.Description = "默认变量表";
- varTable.ProtocolType = device.ProtocolType;
- device.VariableTables.Add(varTable);
- var addVarTable = await _varTableRepository.AddAsync(varTable, db);
- // 添加添加变量表的菜单
- var varTableMenu = new MenuBean()
- {
- Name = "默认变量表",
- Icon = SegoeFluentIcons.Tablet.Glyph,
- Type = MenuType.VariableTableMenu,
- ParentId = addDeviceMenuId,
- DataId = addVarTable.Id
- };
- await _menuRepository.AddAsync(varTableMenu, db);
- }
+ var addDeviceMenuId = await _menuRepository.AddAsync(addDevice);
- await _menuRepository.AddVarTableMenuAsync(addDevice, addDeviceMenuId, db);
- return _mapper.Map(addDevice);
+ stopwatch.Stop();
+ NlogHelper.Info($"添加设备 '{device.Name}' 及相关菜单耗时:{stopwatch.ElapsedMilliseconds}ms");
}
-
+
}
\ No newline at end of file
diff --git a/DMS.Infrastructure/Repositories/MenuRepository.cs b/DMS.Infrastructure/Repositories/MenuRepository.cs
index 1488dc6..d53854d 100644
--- a/DMS.Infrastructure/Repositories/MenuRepository.cs
+++ b/DMS.Infrastructure/Repositories/MenuRepository.cs
@@ -1,16 +1,15 @@
using System.Diagnostics;
-using iNKORE.UI.WPF.Modern.Common.IconKeys;
-using DMS.Extensions;
using SqlSugar;
using AutoMapper;
using DMS.Infrastructure.Entities;
using DMS.Core.Enums;
-using DMS.Helper;
-using DMS.Models;
+using DMS.Core.Helper;
+using DMS.Core.Models;
+using DMS.Infrastructure.Data;
namespace DMS.Infrastructure.Repositories;
-public class MenuRepository
+public class MenuRepository : IMenuRepository
{
private readonly IMapper _mapper;
@@ -95,7 +94,7 @@ public class MenuRepository
var addVarTable = new MenuBean()
{
Name = "添加变量表",
- Icon = SegoeFluentIcons.Add.Glyph,
+ // Icon = SegoeFluentIcons.Add.Glyph,
Type = MenuType.AddVariableTableMenu,
ParentId = parentMenuId,
DataId = dbDevice.Id
@@ -130,7 +129,7 @@ public class MenuRepository
Name = device.Name,
Type = MenuType.DeviceMenu,
DataId = device.Id,
- Icon = SegoeFluentIcons.Devices4.Glyph,
+ // Icon = SegoeFluentIcons.Devices4.Glyph,
};
menu.ParentId = deviceMainMenu.Id;
var addDeviceMenuId = await db.Insertable(_mapper.Map(menu))
diff --git a/DMS.Infrastructure/Repositories/MqttRepository.cs b/DMS.Infrastructure/Repositories/MqttRepository.cs
index 3d8543a..eb4cf9e 100644
--- a/DMS.Infrastructure/Repositories/MqttRepository.cs
+++ b/DMS.Infrastructure/Repositories/MqttRepository.cs
@@ -2,16 +2,16 @@ using System.Diagnostics;
using AutoMapper;
using DMS.Infrastructure.Entities;
using DMS.Core.Enums;
-using DMS.Helper;
-using DMS.Models;
-using iNKORE.UI.WPF.Modern.Common.IconKeys;
+using DMS.Core.Helper;
+using DMS.Core.Models;
+using DMS.Infrastructure.Data;
namespace DMS.Infrastructure.Repositories;
///
/// Mqtt仓储类,用于操作DbMqtt实体
///
-public class MqttRepository
+public class MqttRepository : IMqttRepository
{
private readonly MenuRepository _menuRepository;
private readonly IMapper _mapper;
@@ -83,7 +83,7 @@ public class MqttRepository
var menu = new MenuBean()
{
Name = mqtt.Name,
- Icon = SegoeFluentIcons.Wifi.Glyph,
+ // Icon = SegoeFluentIcons.Wifi.Glyph,
Type = MenuType.MqttMenu,
DataId = result,
ParentId = mqttMenu.Id,
diff --git a/DMS.Infrastructure/Repositories/UserRepository.cs b/DMS.Infrastructure/Repositories/UserRepository.cs
index 830448f..3eb4faa 100644
--- a/DMS.Infrastructure/Repositories/UserRepository.cs
+++ b/DMS.Infrastructure/Repositories/UserRepository.cs
@@ -2,14 +2,15 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.Threading.Tasks;
using DMS.Infrastructure.Entities;
-using DMS.Helper;
+using DMS.Core.Helper;
+using DMS.Infrastructure.Data;
namespace DMS.Infrastructure.Repositories;
///
/// 用户仓储类,用于操作DbUser实体
///
-public class UserRepository
+public class UserRepository : IUserRepository
{
///
diff --git a/DMS.Infrastructure/Repositories/VarDataRepository.cs b/DMS.Infrastructure/Repositories/VarDataRepository.cs
index 7d007e7..ba8f8ed 100644
--- a/DMS.Infrastructure/Repositories/VarDataRepository.cs
+++ b/DMS.Infrastructure/Repositories/VarDataRepository.cs
@@ -1,20 +1,20 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading.Tasks;
-using DMS.Extensions;
using SqlSugar;
using AutoMapper;
using Dm.util;
using DMS.Infrastructure.Entities;
-using DMS.Helper;
-using DMS.Models;
+using DMS.Core.Helper;
+using DMS.Core.Models;
+using DMS.Infrastructure.Data;
namespace DMS.Infrastructure.Repositories;
///
/// VariableData仓储类,用于操作DbVariableData实体
///
-public class VarDataRepository
+public class VarDataRepository : IVarDataRepository
{
private readonly IMapper _mapper;
@@ -359,12 +359,12 @@ public class VarDataRepository
if (existingAliasesDict.TryGetValue(key, out var existingAlias))
{
// 如果存在但别名不同,则准备更新
- if (existingAlias.MqttAlias != variableMqtt.MqttAlias)
- {
- existingAlias.MqttAlias = variableMqtt.MqttAlias;
- existingAlias.UpdateTime = DateTime.Now;
- toUpdate.Add(existingAlias);
- }
+ // if (existingAlias.MqttAlias != variableMqtt.MqttAlias)
+ // {
+ // existingAlias.MqttAlias = variableMqtt.MqttAlias;
+ // existingAlias.UpdateTime = DateTime.Now;
+ // toUpdate.Add(existingAlias);
+ // }
}
else
{
@@ -373,7 +373,7 @@ public class VarDataRepository
{
VariableId = variableMqtt.Variable.Id,
MqttId = variableMqtt.Mqtt.Id,
- MqttAlias = variableMqtt.MqttAlias,
+ // MqttAlias = variableMqtt.MqttAlias,
CreateTime = DateTime.Now,
UpdateTime = DateTime.Now
});
diff --git a/DMS.Infrastructure/Repositories/VarTableRepository.cs b/DMS.Infrastructure/Repositories/VarTableRepository.cs
index 46e2b71..31eef8c 100644
--- a/DMS.Infrastructure/Repositories/VarTableRepository.cs
+++ b/DMS.Infrastructure/Repositories/VarTableRepository.cs
@@ -1,16 +1,14 @@
-using iNKORE.UI.WPF.Modern.Common.IconKeys;
-using DMS.Core.Enums;
-using DMS.Extensions;
using SqlSugar;
using System.Diagnostics;
using AutoMapper;
using DMS.Infrastructure.Entities;
-using DMS.Helper;
-using DMS.Models;
+using DMS.Core.Helper;
+using DMS.Core.Models;
+using DMS.Infrastructure.Data;
namespace DMS.Infrastructure.Repositories;
-public class VarTableRepository
+public class VarTableRepository : IVarTableRepository
{
private readonly IMapper _mapper;
diff --git a/DMS.Infrastructure/Repositories/VariableMqttAliasRepository.cs b/DMS.Infrastructure/Repositories/VariableMqttAliasRepository.cs
index 04edb51..004f235 100644
--- a/DMS.Infrastructure/Repositories/VariableMqttAliasRepository.cs
+++ b/DMS.Infrastructure/Repositories/VariableMqttAliasRepository.cs
@@ -1,6 +1,7 @@
using SqlSugar;
using System.Collections.Generic;
using System.Threading.Tasks;
+using DMS.Infrastructure.Data;
using DMS.Infrastructure.Entities;
namespace DMS.Infrastructure.Repositories;
@@ -8,7 +9,7 @@ namespace DMS.Infrastructure.Repositories;
///
/// 变量与MQTT服务器别名关联的数据仓库。
///
-public class VariableMqttAliasRepository
+public class VariableMqttAliasRepository : IVariableMqttAliasRepository
{
///
/// 根据变量ID和MQTT服务器ID获取别名。
diff --git a/DMS.Infrastructure/Services/DatabaseInitializerService.cs b/DMS.Infrastructure/Services/DatabaseInitializerService.cs
new file mode 100644
index 0000000..cc25179
--- /dev/null
+++ b/DMS.Infrastructure/Services/DatabaseInitializerService.cs
@@ -0,0 +1,82 @@
+using DMS.Config;
+using DMS.Core.Enums;
+using DMS.Infrastructure.Data;
+using DMS.Infrastructure.Entities;
+using SqlSugar;
+using System;
+using System.Threading.Tasks;
+
+namespace DMS.Infrastructure.Services
+{
+ public class DatabaseInitializerService : DMS.Core.Interfaces.IDatabaseService
+ {
+ private readonly SqlSugarClient _db;
+
+ public DatabaseInitializerService(SqlSugarDbContext dbContext)
+ {
+ _db = dbContext.GetSqlSugarClient();
+ }
+
+ public void InitializeDataBase()
+ {
+ _db.DbMaintenance.CreateDatabase();
+ _db.CodeFirst.InitTables();
+ _db.CodeFirst.InitTables();
+ _db.CodeFirst.InitTables();
+ _db.CodeFirst.InitTables();
+ _db.CodeFirst.InitTables();
+ _db.CodeFirst.InitTables();
+ _db.CodeFirst.InitTables();
+ _db.CodeFirst.InitTables();
+ _db.CodeFirst.InitTables();
+ }
+
+ public async Task InitializeMenu()
+ {
+ var homeMenu = new DbMenu()
+ { Name = "主页", Type = MenuType.MainMenu, Icon = "Home", ParentId = 0 }; // Icon needs to be adjusted if it's not a string
+
+ var deviceMenu = new DbMenu()
+ {
+ Name = "设备", Type = MenuType.MainMenu, Icon = "Devices3",
+ ParentId = 0
+ };
+ var dataTransfromMenu = new DbMenu()
+ {
+ Name = "数据转换", Type = MenuType.MainMenu,
+ Icon = "ChromeSwitch", ParentId = 0
+ };
+ var mqttMenu = new DbMenu()
+ {
+ Name = "Mqtt服务器", Type = MenuType.MainMenu, Icon = "Cloud",
+ ParentId = 0
+ };
+
+ var settingMenu = new DbMenu()
+ {
+ Name = "设置", Type = MenuType.MainMenu, Icon = "Settings",
+ ParentId = 0
+ };
+ var aboutMenu = new DbMenu()
+ { Name = "关于", Type = MenuType.MainMenu, Icon = "Info", ParentId = 0 };
+
+ await CheckMainMenuExist(homeMenu);
+ await CheckMainMenuExist(deviceMenu);
+ await CheckMainMenuExist(dataTransfromMenu);
+ await CheckMainMenuExist(mqttMenu);
+ await CheckMainMenuExist(settingMenu);
+ await CheckMainMenuExist(aboutMenu);
+ }
+
+ private async Task CheckMainMenuExist(DbMenu menu)
+ {
+ var homeMenuExist = await _db.Queryable()
+ .FirstAsync(dm => dm.Name == menu.Name);
+ if (homeMenuExist == null)
+ {
+ await _db.Insertable(menu)
+ .ExecuteCommandAsync();
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/DMS.WPF/App.xaml.cs b/DMS.WPF/App.xaml.cs
index 4936bc0..3363c11 100644
--- a/DMS.WPF/App.xaml.cs
+++ b/DMS.WPF/App.xaml.cs
@@ -1,8 +1,7 @@
using System.Windows;
-using DMS.Infrastructure;
using DMS.Infrastructure.Entities;
using DMS.Infrastructure.Repositories;
-using DMS.Enums;
+using DMS.Core.Enums;
using DMS.Helper;
using DMS.Services;
using DMS.Services.Processors;
@@ -16,6 +15,11 @@ using NLog.Extensions.Logging;
using DMS.Extensions;
using Microsoft.Extensions.Hosting;
using DMS.Config;
+using DMS.Infrastructure.Data;
+using DMS.WPF.Helper;
+using DMS.WPF.Services;
+using DMS.WPF.Services.Processors;
+using DMS.WPF.ViewModels.DMS.ViewModels;
using SqlSugar;
using LogLevel = Microsoft.Extensions.Logging.LogLevel;
@@ -24,7 +28,7 @@ namespace DMS;
///
/// Interaction logic for App.xaml
///
-public partial class App : Application
+public partial class App : System.Windows.Application
{
public IServiceProvider Services { get; }
@@ -43,7 +47,7 @@ public partial class App : Application
Services = Host.Services;
}
- public new static App Current => (App)Application.Current;
+ public new static App Current => (App)System.Windows.Application.Current;
public IHost Host { get; }
protected override async void OnStartup(StartupEventArgs e)
@@ -55,8 +59,9 @@ public partial class App : Application
try
{
- InitializeDataBase();
- InitializeMenu()
+ var databaseInitializer = Host.Services.GetRequiredService();
+ databaseInitializer.InitializeDataBase();
+ await databaseInitializer.InitializeMenu()
.Await((e) => { NotificationHelper.ShowError($"初始化主菜单失败:{e.Message}", e); },
() => { MessageHelper.SendLoadMessage(LoadTypes.Menu); });
Host.Services.GetRequiredService();
@@ -67,7 +72,7 @@ public partial class App : Application
dataProcessingService.AddProcessor(Host.Services.GetRequiredService());
dataProcessingService.AddProcessor(Host.Services.GetRequiredService());
dataProcessingService.AddProcessor(Host.Services.GetRequiredService());
- dataProcessingService.AddProcessor(Host.Services.GetRequiredService());
+ //dataProcessingService.AddProcessor(Host.Services.GetRequiredService());
}
catch (Exception exception)
{
@@ -100,9 +105,22 @@ public partial class App : Application
private void ConfigureServices(IServiceCollection services)
{
+ // Register ConnectionSettings
+ services.AddSingleton(ConnectionSettings.Load());
+
+ // Register SqlSugarDbContext (concrete type, used by DatabaseInitializerService)
+ // SqlSugarDbContext now internally creates SqlSugarClient using ConnectionSettings
+ services.AddScoped();
+
+ // Register IUnitOfWork (abstract interface for transaction management)
+ services.AddScoped();
+
+ // Register IDatabaseService (abstract interface for database initialization)
+ services.AddSingleton();
+
services.AddSingleton();
services.AddSingleton();
- services.AddSingleton();
+ //services.AddSingleton();
services.AddSingleton();
services.AddHostedService();
services.AddHostedService();
@@ -189,72 +207,5 @@ public partial class App : Application
};
}
- ///
- /// 初始化菜单
- ///
- private async Task InitializeMenu()
- {
- using (var db = DbContext.GetInstance())
- {
- var homeMenu = new DbMenu()
- { Name = "主页", Type = MenuType.MainMenu, Icon = SegoeFluentIcons.Home.Glyph, ParentId = 0 };
-
- var deviceMenu = new DbMenu()
- {
- Name = "设备", Type = MenuType.MainMenu, Icon = SegoeFluentIcons.Devices3.Glyph,
- ParentId = 0
- };
- var dataTransfromMenu = new DbMenu()
- {
- Name = "数据转换", Type = MenuType.MainMenu,
- Icon = SegoeFluentIcons.ChromeSwitch.Glyph, ParentId = 0
- };
- var mqttMenu = new DbMenu()
- {
- Name = "Mqtt服务器", Type = MenuType.MainMenu, Icon = SegoeFluentIcons.Cloud.Glyph,
- ParentId = 0
- };
-
- var settingMenu = new DbMenu()
- {
- Name = "设置", Type = MenuType.MainMenu, Icon = SegoeFluentIcons.Settings.Glyph,
- ParentId = 0
- };
- var aboutMenu = new DbMenu()
- { Name = "关于", Type = MenuType.MainMenu, Icon = SegoeFluentIcons.Info.Glyph, ParentId = 0 };
- await CheckMainMenuExist(db, homeMenu);
- await CheckMainMenuExist(db, deviceMenu);
- await CheckMainMenuExist(db, dataTransfromMenu);
- await CheckMainMenuExist(db, mqttMenu);
- await CheckMainMenuExist(db, settingMenu);
- await CheckMainMenuExist(db, aboutMenu);
- }
- }
-
- private static async Task CheckMainMenuExist(SqlSugarClient db, DbMenu menu)
- {
- var homeMenuExist = await db.Queryable()
- .FirstAsync(dm => dm.Name == menu.Name);
- if (homeMenuExist == null)
- {
- await db.Insertable(menu)
- .ExecuteCommandAsync();
- }
- }
-
- private void InitializeDataBase()
- {
- var _db = DbContext.GetInstance();
- _db.DbMaintenance.CreateDatabase();
- _db.CodeFirst.InitTables();
- _db.CodeFirst.InitTables();
- _db.CodeFirst.InitTables();
- _db.CodeFirst.InitTables();
- _db.CodeFirst.InitTables();
- _db.CodeFirst.InitTables();
- _db.CodeFirst.InitTables();
- _db.CodeFirst.InitTables();
- _db.CodeFirst.InitTables();
- _db.CodeFirst.InitTables();
- }
+
}
\ No newline at end of file
diff --git a/DMS.WPF/DMS.WPF.csproj b/DMS.WPF/DMS.WPF.csproj
index a6925d7..27a0b90 100644
--- a/DMS.WPF/DMS.WPF.csproj
+++ b/DMS.WPF/DMS.WPF.csproj
@@ -149,4 +149,9 @@
+
+
+
+
+
diff --git a/DMS.WPF/Extensions/ObjectExtensions.cs b/DMS.WPF/Extensions/ObjectExtensions.cs
index bd41f21..b5b6b5e 100644
--- a/DMS.WPF/Extensions/ObjectExtensions.cs
+++ b/DMS.WPF/Extensions/ObjectExtensions.cs
@@ -1,8 +1,7 @@
using System.Collections;
using System.Reflection;
-using DMS.Data.Entities;
-using DMS.Models;
-using DMS.Helper;
+using DMS.Infrastructure.Entities;
+using DMS.WPF.Models;
namespace DMS.Extensions;
diff --git a/DMS.WPF/Helper/DataServicesHelper.cs b/DMS.WPF/Helper/DataServicesHelper.cs
index 80966da..9eca085 100644
--- a/DMS.WPF/Helper/DataServicesHelper.cs
+++ b/DMS.WPF/Helper/DataServicesHelper.cs
@@ -1,9 +1,12 @@
+
using DMS.Core.Enums;
using DMS.Models;
using DMS.ViewModels;
+using DMS.WPF.Models;
+using DMS.WPF.ViewModels;
using Microsoft.Extensions.DependencyInjection;
-namespace DMS.Helper;
+namespace DMS.WPF.Helper;
public class DataServicesHelper
{
@@ -122,4 +125,4 @@ public class DataServicesHelper
return null;
}
-}
\ No newline at end of file
+}
diff --git a/DMS.WPF/Helper/MessageHelper.cs b/DMS.WPF/Helper/MessageHelper.cs
index f2a4a6b..1360df4 100644
--- a/DMS.WPF/Helper/MessageHelper.cs
+++ b/DMS.WPF/Helper/MessageHelper.cs
@@ -1,9 +1,9 @@
-using CommunityToolkit.Mvvm.Messaging;
+using CommunityToolkit.Mvvm.Messaging;
using DMS.Core.Enums;
-using DMS.Message;
-using DMS.ViewModels;
+using DMS.WPF.Message;
+using DMS.WPF.ViewModels;
-namespace DMS.Helper;
+namespace DMS.WPF.Helper;
public class MessageHelper
{
diff --git a/DMS.WPF/Helper/ThemeHelper.cs b/DMS.WPF/Helper/ThemeHelper.cs
index ba88712..30a3878 100644
--- a/DMS.WPF/Helper/ThemeHelper.cs
+++ b/DMS.WPF/Helper/ThemeHelper.cs
@@ -1,11 +1,12 @@
+
using System;
using System.Linq;
using System.Windows;
-using DMS.Config;
+using DMS.Infrastructure.Configurations;
using iNKORE.UI.WPF.Modern;
using Microsoft.Win32;
-namespace DMS.Helper;
+namespace DMS.WPF.Helper;
public static class ThemeHelper
{
@@ -93,4 +94,4 @@ public static class ThemeHelper
return false;
}
}
-}
\ No newline at end of file
+}
diff --git a/DMS.WPF/Models/Device.cs b/DMS.WPF/Models/Device.cs
index b70c156..d395e86 100644
--- a/DMS.WPF/Models/Device.cs
+++ b/DMS.WPF/Models/Device.cs
@@ -5,7 +5,7 @@ using SqlSugar;
using SqlSugar.DbConvert;
using S7.Net; // AddAsync this using directive
-namespace DMS.Models;
+namespace DMS.WPF.Models;
///
/// 表示设备信息。
diff --git a/DMS.WPF/Models/Mqtt.cs b/DMS.WPF/Models/Mqtt.cs
index 762c451..485d37b 100644
--- a/DMS.WPF/Models/Mqtt.cs
+++ b/DMS.WPF/Models/Mqtt.cs
@@ -1,7 +1,7 @@
using CommunityToolkit.Mvvm.ComponentModel;
using DMS.Core.Enums;
-namespace DMS.Models;
+namespace DMS.WPF.Models;
///
/// 表示MQTT配置信息。
diff --git a/DMS.WPF/Models/Variable.cs b/DMS.WPF/Models/Variable.cs
index fb097d5..6b91d46 100644
--- a/DMS.WPF/Models/Variable.cs
+++ b/DMS.WPF/Models/Variable.cs
@@ -1,7 +1,7 @@
using CommunityToolkit.Mvvm.ComponentModel;
using DMS.Core.Enums;
-namespace DMS.Models;
+namespace DMS.WPF.Models;
///
/// 表示变量数据信息。
diff --git a/DMS.WPF/Services/DataServices.cs b/DMS.WPF/Services/DataServices.cs
index 7d3d1e6..b6ffc6f 100644
--- a/DMS.WPF/Services/DataServices.cs
+++ b/DMS.WPF/Services/DataServices.cs
@@ -1,18 +1,18 @@
-using System.Collections.Concurrent;
+using System.Collections.Concurrent;
using AutoMapper;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Messaging;
-using DMS.Data.Repositories;
+using DMS.WPF.Models;
+using DMS.WPF.Message;
+using DMS.WPF.ViewModels;
+using DMS.Core.Helper;
+using DMS.Infrastructure.Repositories;
using DMS.Core.Enums;
-using DMS.Helper;
-using DMS.Message;
-using DMS.Models;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
-using DMS.ViewModels;
using SqlSugar;
-namespace DMS.Services;
+namespace DMS.WPF.Services;
///
/// 数据服务类,负责从数据库加载和管理各种数据,并提供数据变更通知。
diff --git a/DMS.WPF/Services/DialogService.cs b/DMS.WPF/Services/DialogService.cs
index a3facfb..1ad4060 100644
--- a/DMS.WPF/Services/DialogService.cs
+++ b/DMS.WPF/Services/DialogService.cs
@@ -1,13 +1,13 @@
-using DMS.Core.Enums;
-using DMS.Models;
-using DMS.ViewModels.Dialogs;
-using DMS.Views.Dialogs;
+using DMS.Core.Enums;
+using DMS.WPF.Models;
+using DMS.WPF.ViewModels.Dialogs;
+using DMS.WPF.Views.Dialogs;
using HandyControl.Tools.Extension;
using iNKORE.UI.WPF.Modern.Controls;
using NPOI.SS.Formula.Functions;
-using DMS.Data.Repositories;
+using DMS.Infrastructure.Repositories;
-namespace DMS.Services;
+namespace DMS.WPF.Services;
public class DialogService :IDialogService
{
diff --git a/DMS.WPF/Services/Processors/HistoryProcessor.cs b/DMS.WPF/Services/Processors/HistoryProcessor.cs
index 5d25133..b64a7c3 100644
--- a/DMS.WPF/Services/Processors/HistoryProcessor.cs
+++ b/DMS.WPF/Services/Processors/HistoryProcessor.cs
@@ -4,14 +4,13 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
-using DMS.Data;
-using DMS.Data.Entities;
-using DMS.Helper;
-using DMS.Models;
+using DMS.Infrastructure.Data;
+using DMS.Infrastructure.Entities;
+using DMS.Core.Helper;
+using DMS.WPF.Models;
using Microsoft.Extensions.Logging;
-using DMS.Services;
-namespace DMS.Services.Processors;
+namespace DMS.WPF.Services.Processors;
public class HistoryProcessor : IVariableProcessor, IDisposable
{
@@ -91,4 +90,4 @@ public class HistoryProcessor : IVariableProcessor, IDisposable
// 在 Dispose 时,尝试将剩余数据写入数据库
FlushQueueToDatabase().Wait();
}
-}
+}
\ No newline at end of file
diff --git a/DMS.WPF/ViewModels/DeviceDetailViewModel.cs b/DMS.WPF/ViewModels/DeviceDetailViewModel.cs
index e075d3e..03f57e5 100644
--- a/DMS.WPF/ViewModels/DeviceDetailViewModel.cs
+++ b/DMS.WPF/ViewModels/DeviceDetailViewModel.cs
@@ -1,12 +1,13 @@
using System.Collections.ObjectModel;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
-using DMS.Data;
-using DMS.Data.Repositories;
-using DMS.Core.Enums;
-using DMS.Helper;
-using DMS.Models;
-using DMS.Services;
+using DMS.WPF.Models;
+using DMS.WPF.Services;
+using DMS.Core.Helper;
+using DMS.Infrastructure.Data;
+using DMS.Infrastructure.Repositories;
+
+namespace DMS.WPF.ViewModels;
using Microsoft.Extensions.DependencyInjection;
namespace DMS.ViewModels;
diff --git a/DMS.WPF/ViewModels/Dialogs/DeviceDialogViewModel.cs b/DMS.WPF/ViewModels/Dialogs/DeviceDialogViewModel.cs
index c361cc5..a7ebebd 100644
--- a/DMS.WPF/ViewModels/Dialogs/DeviceDialogViewModel.cs
+++ b/DMS.WPF/ViewModels/Dialogs/DeviceDialogViewModel.cs
@@ -1,9 +1,9 @@
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
-using DMS.Models;
-using S7.Net; // AddAsync this using directive
+using DMS.WPF.Models;
+using S7.Net;
-namespace DMS.ViewModels.Dialogs;
+namespace DMS.WPF.ViewModels.Dialogs;
public partial class DeviceDialogViewModel : ObservableObject
{
diff --git a/DMS.WPF/ViewModels/MainViewModel.cs b/DMS.WPF/ViewModels/MainViewModel.cs
index 7ec56d0..3084612 100644
--- a/DMS.WPF/ViewModels/MainViewModel.cs
+++ b/DMS.WPF/ViewModels/MainViewModel.cs
@@ -2,13 +2,14 @@
using System.Windows;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
-using DMS.Data;
-using DMS.Data.Repositories;
-using DMS.Core.Enums;
-using DMS.Helper;
-using DMS.Models;
-using DMS.Services;
-using DMS.Views;
+using DMS.WPF.Models;
+using DMS.WPF.Services;
+using DMS.WPF.Views;
+using DMS.Core.Helper;
+using DMS.Infrastructure.Data;
+using DMS.Infrastructure.Repositories;
+
+namespace DMS.WPF.ViewModels;
using iNKORE.UI.WPF.Modern.Common.IconKeys;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
diff --git a/DMS.WPF/Views/DeviceDetailView.xaml.cs b/DMS.WPF/Views/DeviceDetailView.xaml.cs
index d2fd6e7..36b9a03 100644
--- a/DMS.WPF/Views/DeviceDetailView.xaml.cs
+++ b/DMS.WPF/Views/DeviceDetailView.xaml.cs
@@ -1,8 +1,8 @@
-using System.Windows.Controls;
-using DMS.ViewModels;
+using System.Windows.Controls;
+using DMS.WPF.ViewModels;
using Microsoft.Extensions.DependencyInjection;
-namespace DMS.Views;
+namespace DMS.WPF.Views;
public partial class DeviceDetailView : UserControl
{
diff --git a/DMS.WPF/Views/Dialogs/DeviceDialog.xaml.cs b/DMS.WPF/Views/Dialogs/DeviceDialog.xaml.cs
index 7413df2..53d4c8f 100644
--- a/DMS.WPF/Views/Dialogs/DeviceDialog.xaml.cs
+++ b/DMS.WPF/Views/Dialogs/DeviceDialog.xaml.cs
@@ -1,10 +1,10 @@
-using System.Windows;
-using DMS.Helper;
-using DMS.ViewModels.Dialogs;
+using System.Windows;
+using DMS.Core.Helper;
+using DMS.WPF.ViewModels.Dialogs;
using iNKORE.UI.WPF.Modern.Controls;
-using DMS.Models;
+using DMS.WPF.Models;
-namespace DMS.Views.Dialogs;
+namespace DMS.WPF.Views.Dialogs;
public partial class DeviceDialog
{
diff --git a/DMS.WPF/Views/MainView.xaml.cs b/DMS.WPF/Views/MainView.xaml.cs
index 537f03d..ecdae43 100644
--- a/DMS.WPF/Views/MainView.xaml.cs
+++ b/DMS.WPF/Views/MainView.xaml.cs
@@ -1,13 +1,13 @@
-using System.Windows;
-using DMS.Helper;
-using DMS.Models;
-using DMS.Services;
-using DMS.ViewModels;
+using System.Windows;
+using DMS.Core.Helper;
+using DMS.WPF.Models;
+using DMS.WPF.Services;
+using DMS.WPF.ViewModels;
using iNKORE.UI.WPF.Modern.Controls;
using Microsoft.Extensions.DependencyInjection;
using DMS.Core.Enums;
-namespace DMS.Views;
+namespace DMS.WPF.Views;
///
/// MainView.xaml 的交互逻辑