重构项目,将项目拆分(临时提交)
This commit is contained in:
63
DMS.Core/Configurations/nlog.config
Normal file
63
DMS.Core/Configurations/nlog.config
Normal file
@@ -0,0 +1,63 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<nlog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
|
||||
autoReload="true"
|
||||
internalLogLevel="Info"
|
||||
internalLogFile="internal-nlog.txt">
|
||||
|
||||
<targets>
|
||||
<!-- 文件日志 -->
|
||||
<target name="logfile"
|
||||
xsi:type="File"
|
||||
fileName="logs/${shortdate}.log"
|
||||
layout="${longdate} ThreadID=${threadid} ${level:uppercase=true} ${logger} ${mdlc:CallerFilePath} ${mdlc:CallerLineNumber:whenEmpty=0} ${mdlc:CallerMember} ${message} ${exception:format=tostring}"
|
||||
archiveFileName="logs/archives/{#}.log"
|
||||
archiveEvery="Day"
|
||||
archiveNumbering="Rolling"
|
||||
maxArchiveFiles="30"/>
|
||||
|
||||
<!-- 控制台日志 -->
|
||||
<target name="logconsole"
|
||||
xsi:type="Console"
|
||||
layout="${date:format=HH\:mm\:ss} ${level} ${threadid} ${message}${exception:format=tostring}"/>
|
||||
<!-- SQL Server 目标 -->
|
||||
<!-- 异步写入日志到数据库 -->
|
||||
|
||||
<target name="database"
|
||||
xsi:type="Database"
|
||||
dbProvider="MySql.Data.MySqlClient.MySqlConnection, MySql.Data"
|
||||
connectionString="server=127.0.0.1;port=3306;user=root;password=Pgw15221236646; database=pmswpf; ">
|
||||
<commandText>
|
||||
INSERT INTO nlog (
|
||||
LogTime, Level, ThreadID,ThreadName,Callsite,CallsiteLineNumber,Message,
|
||||
Logger, Exception, CallerFilePath, CallerLineNumber,CallerMember
|
||||
) VALUES (
|
||||
@LogTime, @Level,@ThreadID,@ThreadName,@Callsite,@CallsiteLineNumber,@Message,
|
||||
@Logger, @Exception, @CallerFilePath, @CallerLineNumber,@CallerMember
|
||||
)
|
||||
</commandText>
|
||||
|
||||
<!-- 参数映射 -->
|
||||
<parameter name="@LogTime" layout="${date:format=yyyy-MM-dd HH\:mm\:ss}"/>
|
||||
<parameter name="@Level" layout="${level}"/>
|
||||
<parameter name="@ThreadID" layout="${threadid}" dbType="Int32"/>
|
||||
<parameter name="@ThreadName" layout="${threadname}"/>
|
||||
<parameter name="@Message" layout="${message}"/>
|
||||
<parameter name="@Callsite" layout="${callsite}"/>
|
||||
<parameter name="@Logger" layout="${logger}"/>
|
||||
<parameter name="@Exception" layout="${exception:format=ToString}"/>
|
||||
<parameter name="@CallsiteLineNumber" layout="${callsite-linenumber:whenEmpty=0}"/>
|
||||
<parameter name="@CallerFilePath" layout="${mdlc:CallerFilePath}"/>
|
||||
<parameter name="@CallerLineNumber" layout="${mdlc:CallerLineNumber:whenEmpty=0}"/>
|
||||
<parameter name="@CallerMember" layout="${mdlc:CallerMember}"/>
|
||||
|
||||
</target>
|
||||
</targets>
|
||||
|
||||
<rules>
|
||||
<logger name="*" minlevel="Trace" writeTo="logconsole"/>
|
||||
<logger name="*" minlevel="Info" writeTo="logfile"/>
|
||||
<!-- 路由日志到数据库 -->
|
||||
<logger name="*" minlevel="Info" writeTo="database"/>
|
||||
</rules>
|
||||
</nlog>
|
||||
34
DMS.Core/DMS.Core.csproj
Normal file
34
DMS.Core/DMS.Core.csproj
Normal file
@@ -0,0 +1,34 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Remove="Modles\**" />
|
||||
<EmbeddedResource Remove="Modles\**" />
|
||||
<None Remove="Modles\**" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Interfaces\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="Configurations\nlog.config">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="NLog" Version="6.0.0" />
|
||||
<PackageReference Include="NLog.Database" Version="6.0.0" />
|
||||
|
||||
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
17
DMS.Core/Enums/Brand.cs
Normal file
17
DMS.Core/Enums/Brand.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
namespace DMS.Core.Enums;
|
||||
|
||||
/// <summary>
|
||||
/// PLC品牌
|
||||
/// </summary>
|
||||
public enum PlcBrand
|
||||
{
|
||||
/// <summary>
|
||||
/// 西门子
|
||||
/// </summary>
|
||||
Siemens = 0,
|
||||
|
||||
/// <summary>
|
||||
/// 三菱
|
||||
/// </summary>
|
||||
Melsec = 1
|
||||
}
|
||||
9
DMS.Core/Enums/DeviceType.cs
Normal file
9
DMS.Core/Enums/DeviceType.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace DMS.Core.Enums;
|
||||
|
||||
public enum DeviceType
|
||||
{
|
||||
[Description("西门子PLC")] SiemensPLC,
|
||||
[Description("三菱PLC")] MelsecPLC
|
||||
}
|
||||
9
DMS.Core/Enums/LoadTypes.cs
Normal file
9
DMS.Core/Enums/LoadTypes.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace DMS.Core.Enums;
|
||||
|
||||
public enum LoadTypes
|
||||
{
|
||||
Devices,
|
||||
Menu,
|
||||
Mqtts,
|
||||
All
|
||||
}
|
||||
10
DMS.Core/Enums/MenuType.cs
Normal file
10
DMS.Core/Enums/MenuType.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace DMS.Core.Enums;
|
||||
|
||||
public enum MenuType
|
||||
{
|
||||
MainMenu,
|
||||
DeviceMenu,
|
||||
VariableTableMenu,
|
||||
AddVariableTableMenu,
|
||||
MqttMenu
|
||||
}
|
||||
11
DMS.Core/Enums/MqttPlatform.cs
Normal file
11
DMS.Core/Enums/MqttPlatform.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace DMS.Core.Enums;
|
||||
|
||||
public enum MqttPlatform
|
||||
{
|
||||
[Description("艾莫迅")]
|
||||
Amsamotion,
|
||||
[Description("有人云")]
|
||||
USR
|
||||
}
|
||||
12
DMS.Core/Enums/NotificationType.cs
Normal file
12
DMS.Core/Enums/NotificationType.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
namespace DMS.Core.Enums;
|
||||
|
||||
public enum NotificationType
|
||||
{
|
||||
Info,
|
||||
Warning,
|
||||
Error,
|
||||
Fatal,
|
||||
Success,
|
||||
Clear,
|
||||
Ask
|
||||
}
|
||||
11
DMS.Core/Enums/OpcUaUpdateType.cs
Normal file
11
DMS.Core/Enums/OpcUaUpdateType.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace DMS.Core.Enums;
|
||||
|
||||
public enum OpcUaUpdateType
|
||||
{
|
||||
[Description("OpcUa轮询")]
|
||||
OpcUaPoll,
|
||||
[Description("OpcUa订阅")]
|
||||
OpcUaSubscription
|
||||
}
|
||||
36
DMS.Core/Enums/PollLevelType.cs
Normal file
36
DMS.Core/Enums/PollLevelType.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace DMS.Core.Enums
|
||||
{
|
||||
public enum PollLevelType
|
||||
{
|
||||
[Description("10毫秒")]
|
||||
TenMilliseconds = 10,
|
||||
[Description("100毫秒")]
|
||||
HundredMilliseconds = 100,
|
||||
[Description("500毫秒")]
|
||||
FiveHundredMilliseconds = 500,
|
||||
[Description("1秒钟")]
|
||||
OneSecond = 1000,
|
||||
[Description("5秒钟")]
|
||||
FiveSeconds = 5000,
|
||||
[Description("10秒钟")]
|
||||
TenSeconds = 10000,
|
||||
[Description("20秒钟")]
|
||||
TwentySeconds = 20000,
|
||||
[Description("30秒钟")]
|
||||
ThirtySeconds = 30000,
|
||||
[Description("1分钟")]
|
||||
OneMinute = 60000,
|
||||
[Description("3分钟")]
|
||||
ThreeMinutes = 180000,
|
||||
[Description("5分钟")]
|
||||
FiveMinutes = 300000,
|
||||
[Description("10分钟")]
|
||||
TenMinutes = 600000,
|
||||
[Description("30分钟")]
|
||||
ThirtyMinutes = 1800000,
|
||||
[Description("1小时")]
|
||||
OneHour = 3600000
|
||||
}
|
||||
}
|
||||
11
DMS.Core/Enums/ProtocolType.cs
Normal file
11
DMS.Core/Enums/ProtocolType.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace DMS.Core.Enums;
|
||||
|
||||
public enum ProtocolType
|
||||
{
|
||||
[Description("S7协议")] S7,
|
||||
[Description("OpcUA协议")] OpcUA,
|
||||
[Description("ModbusRtu协议")] ModbusRtu,
|
||||
[Description("ModbusTcp协议")] ModbusTcp
|
||||
}
|
||||
17
DMS.Core/Enums/SignalType.cs
Normal file
17
DMS.Core/Enums/SignalType.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace DMS.Core.Enums;
|
||||
|
||||
public enum SignalType
|
||||
{
|
||||
[Description("启动信号")] StartSignal,
|
||||
[Description("停止信号")] StopSignal,
|
||||
[Description("报警信号")] AlarmSignal,
|
||||
[Description("准备信号")] ReadySignal,
|
||||
[Description("复位信号")] ResetSignal,
|
||||
[Description("运行信号")] RunSignal,
|
||||
[Description("设定频率")] SetHZSignal,
|
||||
[Description("当前频率")] GetHZSignal,
|
||||
[Description("当前电流")] CurrentASignal,
|
||||
[Description("其他信号")] OtherASignal
|
||||
}
|
||||
232
DMS.Core/Helper/NlogHelper.cs
Normal file
232
DMS.Core/Helper/NlogHelper.cs
Normal file
@@ -0,0 +1,232 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading;
|
||||
using NLog;
|
||||
|
||||
namespace DMS.Helper;
|
||||
|
||||
/// <summary>
|
||||
/// NLog 日志帮助类,提供简化的日志记录方法,并自动捕获调用者信息。
|
||||
/// 新增了日志节流功能,以防止在短时间内产生大量重复的日志(日志风暴)。
|
||||
/// </summary>
|
||||
public static class NlogHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取当前类的 NLog 日志实例。
|
||||
/// </summary>
|
||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
/// <summary>
|
||||
/// 内部类,用于存储节流日志的状态信息。
|
||||
/// </summary>
|
||||
private class ThrottledLogInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// 日志在节流时间窗口内的调用次数。
|
||||
/// 使用 int 类型,并通过 Interlocked.Increment 进行原子性递增,确保线程安全。
|
||||
/// </summary>
|
||||
public int Count;
|
||||
|
||||
/// <summary>
|
||||
/// 用于在节流时间结束后执行操作的计时器。
|
||||
/// </summary>
|
||||
public Timer Timer;
|
||||
|
||||
/// <summary>
|
||||
/// 调用日志方法的源文件完整路径。
|
||||
/// </summary>
|
||||
public string CallerFilePath;
|
||||
|
||||
/// <summary>
|
||||
/// 调用日志方法的成员或属性名称。
|
||||
/// </summary>
|
||||
public string CallerMember;
|
||||
|
||||
/// <summary>
|
||||
/// 调用日志方法的行号。
|
||||
/// </summary>
|
||||
public int CallerLineNumber;
|
||||
|
||||
/// <summary>
|
||||
/// 日志级别 (e.g., Info, Error)。
|
||||
/// </summary>
|
||||
public LogLevel Level;
|
||||
|
||||
/// <summary>
|
||||
/// 关联的异常对象(如果有)。
|
||||
/// </summary>
|
||||
public Exception Exception;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 线程安全的字典,用于存储正在被节流的日志。
|
||||
/// 键 (string) 是根据日志消息和调用位置生成的唯一标识。
|
||||
/// 值 (ThrottledLogInfo) 是该日志的节流状态信息。
|
||||
/// </summary>
|
||||
private static readonly ConcurrentDictionary<string, ThrottledLogInfo> ThrottledLogs = new ConcurrentDictionary<string, ThrottledLogInfo>();
|
||||
|
||||
/// <summary>
|
||||
/// 定义节流的时间窗口(单位:秒)。
|
||||
/// </summary>
|
||||
private const int ThrottleTimeSeconds = 30;
|
||||
|
||||
/// <summary>
|
||||
/// 内部核心日志记录方法,包含了节流逻辑。
|
||||
/// </summary>
|
||||
/// <param name="msg">日志消息内容。</param>
|
||||
/// <param name="level">NLog 的日志级别。</param>
|
||||
/// <param name="exception">可选的异常对象。</param>
|
||||
/// <param name="throttle">是否启用节流。</param>
|
||||
/// <param name="callerFilePath">调用此方法的源文件完整路径。</param>
|
||||
/// <param name="callerMember">调用此方法的成员或属性名称。</param>
|
||||
/// <param name="callerLineNumber">调用此方法的行号。</param>
|
||||
private static void LogInternal(string msg, LogLevel level, Exception exception, bool throttle, string callerFilePath, string callerMember, int callerLineNumber)
|
||||
{
|
||||
// 如果不启用节流,则直接记录日志并返回。
|
||||
if (!throttle)
|
||||
{
|
||||
LogWithContext(msg, level, exception, callerFilePath, callerMember, callerLineNumber);
|
||||
return;
|
||||
}
|
||||
|
||||
// 使用消息内容和调用位置生成唯一键,以区分不同的日志来源。
|
||||
var key = $"{callerFilePath}:{callerLineNumber}:{msg}";
|
||||
|
||||
// 使用 AddOrUpdate 实现原子操作,确保线程安全。
|
||||
// 它会尝试添加一个新的节流日志条目,如果键已存在,则更新现有条目。
|
||||
ThrottledLogs.AddOrUpdate(
|
||||
key,
|
||||
// --- 添加逻辑 (addValueFactory):当日志第一次被节流时执行 ---
|
||||
_ =>
|
||||
{
|
||||
// 1. 首次出现,立即记录一次原始日志。
|
||||
LogWithContext(msg, level, exception, callerFilePath, callerMember, callerLineNumber);
|
||||
|
||||
// 2. 创建一个新的节流信息对象。
|
||||
var newThrottledLog = new ThrottledLogInfo
|
||||
{
|
||||
Count = 1,
|
||||
CallerFilePath = callerFilePath,
|
||||
CallerMember = callerMember,
|
||||
CallerLineNumber = callerLineNumber,
|
||||
Level = level,
|
||||
Exception = exception
|
||||
};
|
||||
|
||||
// 3. 创建并启动一个一次性计时器。
|
||||
newThrottledLog.Timer = new Timer(s =>
|
||||
{
|
||||
// --- 计时器回调:在指定时间(例如30秒)后触发 ---
|
||||
// 尝试从字典中移除当前日志条目。
|
||||
if (ThrottledLogs.TryRemove(key, out var finishedLog))
|
||||
{
|
||||
// 释放计时器资源。
|
||||
finishedLog.Timer.Dispose();
|
||||
// 如果在节流期间有后续调用(Count > 1),则记录一条摘要日志。
|
||||
if (finishedLog.Count > 1)
|
||||
{
|
||||
var summaryMsg = $"日志 '{msg}' 在过去 {ThrottleTimeSeconds} 秒内被调用 {finishedLog.Count} 次。";
|
||||
LogWithContext(summaryMsg, finishedLog.Level, finishedLog.Exception, finishedLog.CallerFilePath, finishedLog.CallerMember, finishedLog.CallerLineNumber);
|
||||
}
|
||||
}
|
||||
}, null, ThrottleTimeSeconds * 1000, Timeout.Infinite); // 设置30秒后触发,且不重复。
|
||||
|
||||
return newThrottledLog;
|
||||
},
|
||||
// --- 更新逻辑 (updateValueFactory):当日志在节流窗口内再次被调用时执行 ---
|
||||
(_, existingLog) =>
|
||||
{
|
||||
// 只需将调用次数加一。使用 Interlocked.Increment 保证原子操作,避免多线程下的竞态条件。
|
||||
Interlocked.Increment(ref existingLog.Count);
|
||||
return existingLog;
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将日志信息包装在 NLog 的 MappedDiagnosticsLogicalContext 中进行记录。
|
||||
/// 这允许在 nlog.config 配置文件中使用 ${mdlc:item=...} 来获取调用者信息。
|
||||
/// </summary>
|
||||
private static void LogWithContext(string msg, LogLevel level, Exception exception, string callerFilePath, string callerMember, int callerLineNumber)
|
||||
{
|
||||
using (MappedDiagnosticsLogicalContext.SetScoped("CallerFilePath", callerFilePath))
|
||||
using (MappedDiagnosticsLogicalContext.SetScoped("CallerLineNumber", callerLineNumber))
|
||||
using (MappedDiagnosticsLogicalContext.SetScoped("CallerMember", callerMember))
|
||||
{
|
||||
if (exception != null)
|
||||
{
|
||||
Logger.Log(level, exception, msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.Log(level, msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 记录一个错误级别的日志,支持节流。
|
||||
/// </summary>
|
||||
/// <param name="msg">日志消息内容。</param>
|
||||
/// <param name="exception">可选:要记录的异常对象。</param>
|
||||
/// <param name="throttle">是否启用日志节流。如果为 true,则在30秒内对来自同一位置的相同日志消息进行节流处理。</param>
|
||||
/// <param name="callerFilePath">自动捕获:调用此方法的源文件完整路径。</param>
|
||||
/// <param name="callerMember">自动捕获:调用此方法的成员或属性名称。</param>
|
||||
/// <param name="callerLineNumber">自动捕获:调用此方法的行号。</param>
|
||||
public static void Error(string msg, Exception exception = null, bool throttle = true,
|
||||
[CallerFilePath] string callerFilePath = "",
|
||||
[CallerMemberName] string callerMember = "",
|
||||
[CallerLineNumber] int callerLineNumber = 0)
|
||||
{
|
||||
LogInternal(msg, LogLevel.Error, exception, throttle, callerFilePath, callerMember, callerLineNumber);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 记录一个信息级别的日志,支持节流。
|
||||
/// </summary>
|
||||
/// <param name="msg">日志消息内容。</param>
|
||||
/// <param name="throttle">是否启用日志节流。如果为 true,则在30秒内对来自同一位置的相同日志消息进行节流处理。</param>
|
||||
/// <param name="callerFilePath">自动捕获:调用此方法的源文件完整路径。</param>
|
||||
/// <param name="callerMember">自动捕获:调用此方法的成员或属性名称。</param>
|
||||
/// <param name="callerLineNumber">自动捕获:调用此方法的行号。</param>
|
||||
public static void Info(string msg, bool throttle = true,
|
||||
[CallerFilePath] string callerFilePath = "",
|
||||
[CallerMemberName] string callerMember = "",
|
||||
[CallerLineNumber] int callerLineNumber = 0)
|
||||
{
|
||||
LogInternal(msg, LogLevel.Info, null, throttle, callerFilePath, callerMember, callerLineNumber);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 记录一个警告级别的日志,支持节流。
|
||||
/// </summary>
|
||||
/// <param name="msg">日志消息内容。</param>
|
||||
/// <param name="throttle">是否启用日志节流。如果为 true,则在30秒内对来自同一位置的相同日志消息进行节流处理。</param>
|
||||
/// <param name="callerFilePath">自动捕获:调用此方法的源文件完整路径。</param>
|
||||
/// <param name="callerMember">自动捕获:调用此方法的成员或属性名称。</param>
|
||||
/// <param name="callerLineNumber">自动捕获:调用此方法的行号。</param>
|
||||
public static void Warn(string msg, bool throttle = true,
|
||||
[CallerFilePath] string callerFilePath = "",
|
||||
[CallerMemberName] string callerMember = "",
|
||||
[CallerLineNumber] int callerLineNumber = 0)
|
||||
{
|
||||
LogInternal(msg, LogLevel.Warn, null, throttle, callerFilePath, callerMember, callerLineNumber);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 记录一个跟踪级别的日志,支持节流。
|
||||
/// </summary>
|
||||
/// <param name="msg">日志消息内容。</param>
|
||||
/// <param name="throttle">是否启用日志节流。如果为 true,则在30秒内对来自同一位置的相同日志消息进行节流处理。</param>
|
||||
/// <param name="callerFilePath">自动捕获:调用此方法的源文件完整路径。</param>
|
||||
/// <param name="callerMember">自动捕获:调用此方法的成员或属性名称。</param>
|
||||
/// <param name="callerLineNumber">自动捕获:调用此方法的行号。</param>
|
||||
public static void Trace(string msg, bool throttle = true,
|
||||
[CallerFilePath] string callerFilePath = "",
|
||||
[CallerMemberName] string callerMember = "",
|
||||
[CallerLineNumber] int callerLineNumber = 0)
|
||||
{
|
||||
LogInternal(msg, LogLevel.Trace, null, throttle, callerFilePath, callerMember, callerLineNumber);
|
||||
}
|
||||
}
|
||||
88
DMS.Core/Models/Device.cs
Normal file
88
DMS.Core/Models/Device.cs
Normal file
@@ -0,0 +1,88 @@
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
using DMS.Core.Enums;
|
||||
|
||||
|
||||
namespace DMS.Models;
|
||||
|
||||
/// <summary>
|
||||
/// 表示设备信息。
|
||||
/// </summary>
|
||||
public partial class Device
|
||||
{
|
||||
/// <summary>
|
||||
/// 设备的描述信息。
|
||||
/// </summary>
|
||||
private string description;
|
||||
|
||||
/// <summary>
|
||||
/// 设备的类型。
|
||||
/// </summary>
|
||||
public DeviceType DeviceType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 设备的唯一标识符。
|
||||
/// </summary>
|
||||
private int id;
|
||||
|
||||
/// <summary>
|
||||
/// 设备的IP地址。
|
||||
/// </summary>
|
||||
private string ip;
|
||||
|
||||
/// <summary>
|
||||
/// 表示设备是否处于活动状态。
|
||||
/// </summary>
|
||||
private bool isActive = true;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 表示是否添加默认变量表。
|
||||
/// </summary>
|
||||
private bool isAddDefVarTable = true;
|
||||
|
||||
/// <summary>
|
||||
/// 表示设备是否正在运行。
|
||||
/// </summary>
|
||||
private bool isRuning;
|
||||
|
||||
/// <summary>
|
||||
/// 设备的名称。
|
||||
/// </summary>
|
||||
private string name;
|
||||
|
||||
/// <summary>
|
||||
/// 设备的端口号。
|
||||
/// </summary>
|
||||
private int prot;
|
||||
|
||||
/// <summary>
|
||||
/// PLC的CPU类型。
|
||||
/// </summary>
|
||||
//private CpuType cpuType;
|
||||
|
||||
/// <summary>
|
||||
/// PLC的机架号。
|
||||
/// </summary>
|
||||
private short rack;
|
||||
|
||||
/// <summary>
|
||||
/// PLC的槽号。
|
||||
/// </summary>
|
||||
private short slot;
|
||||
|
||||
/// <summary>
|
||||
/// 设备的通信协议类型。
|
||||
/// </summary>
|
||||
public ProtocolType ProtocolType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// OPC UA Endpoint URL。
|
||||
/// </summary>
|
||||
private string? opcUaEndpointUrl;
|
||||
|
||||
/// <summary>
|
||||
/// 设备关联的变量表列表。
|
||||
/// </summary>
|
||||
public ObservableCollection<VariableTable>? VariableTables { get; set; }
|
||||
}
|
||||
55
DMS.Core/Models/MenuBean.cs
Normal file
55
DMS.Core/Models/MenuBean.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
using DMS.Core.Enums;
|
||||
|
||||
namespace DMS.Models;
|
||||
|
||||
/// <summary>
|
||||
/// 表示菜单项。
|
||||
/// </summary>
|
||||
public class MenuBean
|
||||
{
|
||||
/// <summary>
|
||||
/// 菜单项关联的数据。
|
||||
/// </summary>
|
||||
public object? Data { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 菜单项关联的数据ID。
|
||||
/// </summary>
|
||||
public int DataId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 菜单项的图标。
|
||||
/// </summary>
|
||||
public string Icon { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 菜单项的唯一标识符。
|
||||
/// </summary>
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 子菜单项列表。
|
||||
/// </summary>
|
||||
public List<MenuBean> Items { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 菜单项的名称。
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 父菜单项。
|
||||
/// </summary>
|
||||
public MenuBean Parent { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 父菜单项的ID。
|
||||
/// </summary>
|
||||
public int ParentId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 菜单项的类型。
|
||||
/// </summary>
|
||||
public MenuType Type { get; set; }
|
||||
|
||||
}
|
||||
96
DMS.Core/Models/Mqtt.cs
Normal file
96
DMS.Core/Models/Mqtt.cs
Normal file
@@ -0,0 +1,96 @@
|
||||
using DMS.Core.Enums;
|
||||
|
||||
namespace DMS.Models;
|
||||
|
||||
/// <summary>
|
||||
/// 表示MQTT配置信息。
|
||||
/// </summary>
|
||||
public partial class Mqtt
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// MQTT客户端ID。
|
||||
/// </summary>
|
||||
public string ClientID { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 连接时间。
|
||||
/// </summary>
|
||||
public DateTime ConnTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// MQTT主机。
|
||||
/// </summary>
|
||||
public string Host { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// MQTT配置的唯一标识符。
|
||||
/// </summary>
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否启用此MQTT配置。
|
||||
/// </summary>
|
||||
private bool IsActive { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 显示连接的消息:
|
||||
/// </summary>
|
||||
private string ConnectMessage { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否设置为默认MQTT客户端。
|
||||
/// </summary>
|
||||
public int IsDefault { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// MQTT客户端名字。
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// MQTT客户端登录密码。
|
||||
/// </summary>
|
||||
public string PassWord { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Mqtt平台类型。
|
||||
/// </summary>
|
||||
public MqttPlatform Platform { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// MQTT主机端口。
|
||||
/// </summary>
|
||||
public int Port { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// MQTT发布主题。
|
||||
/// </summary>
|
||||
public string PublishTopic { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// MQTT备注。
|
||||
/// </summary>
|
||||
public string Remark { get; set; } = String.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// MQTT订阅主题。
|
||||
/// </summary>
|
||||
public string SubTopic { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// MQTT客户端登录用户名。
|
||||
/// </summary>
|
||||
public string UserName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 关联的变量数据列表。
|
||||
/// </summary>
|
||||
public List<VariableMqtt>? VariableMqtts { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否连接。
|
||||
/// </summary>
|
||||
private bool IsConnected { get; set; }
|
||||
}
|
||||
24
DMS.Core/Models/Notification.cs
Normal file
24
DMS.Core/Models/Notification.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using DMS.Core.Enums;
|
||||
|
||||
namespace DMS.Models;
|
||||
|
||||
/// <summary>
|
||||
/// 表示通知信息。
|
||||
/// </summary>
|
||||
public class Notification
|
||||
{
|
||||
/// <summary>
|
||||
/// 通知是否为全局通知。
|
||||
/// </summary>
|
||||
public bool IsGlobal { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 通知消息内容。
|
||||
/// </summary>
|
||||
public string Message { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 通知类型。
|
||||
/// </summary>
|
||||
public NotificationType Type { get; set; }
|
||||
}
|
||||
68
DMS.Core/Models/OpcUaNode.cs
Normal file
68
DMS.Core/Models/OpcUaNode.cs
Normal file
@@ -0,0 +1,68 @@
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace DMS.Models;
|
||||
|
||||
/// <summary>
|
||||
/// 表示OPC UA节点,用于构建节点树。
|
||||
/// </summary>
|
||||
public partial class OpcUaNode
|
||||
{
|
||||
/// <summary>
|
||||
/// 节点的显示名称。
|
||||
/// </summary>
|
||||
public string DisplayName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 节点的唯一标识符。
|
||||
/// </summary>
|
||||
public string NodeId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 节点的类型(例如,文件夹、变量)。
|
||||
/// </summary>
|
||||
public NodeType NodeType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 子节点集合。
|
||||
/// </summary>
|
||||
private ObservableCollection<OpcUaNode> _children;
|
||||
|
||||
/// <summary>
|
||||
/// 指示节点是否已加载子节点。
|
||||
/// </summary>
|
||||
private bool _isLoaded;
|
||||
|
||||
/// <summary>
|
||||
/// 指示节点是否正在加载子节点。
|
||||
/// </summary>
|
||||
private bool _isLoading;
|
||||
|
||||
/// <summary>
|
||||
/// 节点的完整路径(可选,用于调试或显示)。
|
||||
/// </summary>
|
||||
public string Path { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数。
|
||||
/// </summary>
|
||||
/// <param name="displayName">显示名称。</param>
|
||||
/// <param name="nodeId">节点ID。</param>
|
||||
/// <param name="nodeType">节点类型。</param>
|
||||
//public OpcUaNode(string displayName, NodeId nodeId, NodeType nodeType)
|
||||
//{
|
||||
// DisplayName = displayName;
|
||||
// NodeId = nodeId;
|
||||
// NodeType = nodeType;
|
||||
// Children = new ObservableCollection<OpcUaNode>();
|
||||
//}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// OPC UA节点类型枚举。
|
||||
/// </summary>
|
||||
public enum NodeType
|
||||
{
|
||||
Folder,
|
||||
Object,
|
||||
Variable
|
||||
}
|
||||
14
DMS.Core/Models/User.cs
Normal file
14
DMS.Core/Models/User.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
namespace DMS.Models;
|
||||
|
||||
public class User
|
||||
{
|
||||
|
||||
public int Id { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
|
||||
public string Password { get; set; }
|
||||
public string Email { get; set; }
|
||||
public string PhoneNumber { get; set; }
|
||||
public string Address { get; set; }
|
||||
}
|
||||
168
DMS.Core/Models/Variable.cs
Normal file
168
DMS.Core/Models/Variable.cs
Normal file
@@ -0,0 +1,168 @@
|
||||
using DMS.Core.Enums;
|
||||
|
||||
namespace DMS.Models;
|
||||
|
||||
/// <summary>
|
||||
/// 表示变量数据信息。
|
||||
/// </summary>
|
||||
public partial class Variable
|
||||
{
|
||||
/// <summary>
|
||||
/// 变量唯一标识符。
|
||||
/// </summary>
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 变量名称。
|
||||
/// </summary>
|
||||
private string name;
|
||||
|
||||
/// <summary>
|
||||
/// 节点ID,用于标识变量在设备或系统中的唯一路径。
|
||||
/// </summary>
|
||||
public string NodeId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 节点ID,用于标识变量在设备或系统中的唯一路径。
|
||||
/// </summary>
|
||||
public string S7Address { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// OPC UA Endpoint URL。
|
||||
/// </summary>
|
||||
public string? OpcUaEndpointUrl { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// OPC UA Node ID。
|
||||
/// </summary>
|
||||
public string? OpcUaNodeId { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 变量描述。
|
||||
/// </summary>
|
||||
private string description = String.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 协议类型,例如Modbus、OPC UA等。
|
||||
/// </summary>
|
||||
public ProtocolType ProtocolType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 信号类型,例如模拟量、数字量等。
|
||||
/// </summary>
|
||||
public SignalType SignalType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 数据类型,例如Int、Float、String等。
|
||||
/// </summary>
|
||||
public string DataType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 变量当前原始数据值。
|
||||
/// </summary>
|
||||
private string dataValue = String.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 变量经过转换或格式化后的显示值。
|
||||
/// </summary>
|
||||
private string displayValue = String.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 指示变量是否处于激活状态。
|
||||
/// </summary>
|
||||
public bool isActive;
|
||||
|
||||
/// <summary>
|
||||
/// 指示变量是否被选中
|
||||
/// </summary>
|
||||
public bool isSelect;
|
||||
|
||||
/// <summary>
|
||||
/// 指示是否需要保存变量数据。
|
||||
/// </summary>
|
||||
public bool IsSave { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 指示是否需要对变量进行报警监测。
|
||||
/// </summary>
|
||||
public bool IsAlarm { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 轮询级别,例如1秒、5秒等。
|
||||
/// </summary>
|
||||
private PollLevelType pollLevelType = PollLevelType.ThirtySeconds;
|
||||
|
||||
/// <summary>
|
||||
/// OPC UA更新类型,例如轮询或订阅。
|
||||
/// </summary>
|
||||
private OpcUaUpdateType opcUaUpdateType = OpcUaUpdateType.OpcUaPoll;
|
||||
|
||||
/// <summary>
|
||||
/// 最后一次轮询时间。
|
||||
/// </summary>
|
||||
public DateTime LastPollTime { get; set; } = DateTime.MinValue;
|
||||
|
||||
/// <summary>
|
||||
/// 指示变量是否已被逻辑删除。
|
||||
/// </summary>
|
||||
public bool IsDeleted { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 指示变量是否已被修改了。
|
||||
/// </summary>
|
||||
private bool isModified;
|
||||
|
||||
/// <summary>
|
||||
/// 报警的最大值阈值。
|
||||
/// </summary>
|
||||
public double AlarmMax { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 报警的最小值阈值。
|
||||
/// </summary>
|
||||
public double AlarmMin { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 数据转换规则或表达式。
|
||||
/// </summary>
|
||||
private string converstion = String.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 数据保存的范围或阈值。
|
||||
/// </summary>
|
||||
public double SaveRange { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 变量数据创建时间。
|
||||
/// </summary>
|
||||
private DateTime createTime;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 变量数据最后更新时间。
|
||||
/// </summary>
|
||||
private DateTime updateTime = DateTime.Now;
|
||||
|
||||
/// <summary>
|
||||
/// 最后更新变量数据的用户。
|
||||
/// </summary>
|
||||
public User UpdateUser { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 关联的变量表ID。
|
||||
/// </summary>
|
||||
public int VariableTableId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 关联的变量表实体。
|
||||
/// </summary>
|
||||
public VariableTable? VariableTable { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 关联的MQTT配置列表。
|
||||
/// </summary>
|
||||
public List<VariableMqtt>? VariableMqtts { get; set; }
|
||||
|
||||
|
||||
}
|
||||
16
DMS.Core/Models/VariableContext.cs
Normal file
16
DMS.Core/Models/VariableContext.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using DMS.Models;
|
||||
|
||||
namespace DMS.Models
|
||||
{
|
||||
public class VariableContext
|
||||
{
|
||||
public Variable Data { get; set; }
|
||||
public bool IsHandled { get; set; }
|
||||
|
||||
public VariableContext(Variable data)
|
||||
{
|
||||
Data = data;
|
||||
IsHandled = false; // 默认未处理
|
||||
}
|
||||
}
|
||||
}
|
||||
76
DMS.Core/Models/VariableMqtt.cs
Normal file
76
DMS.Core/Models/VariableMqtt.cs
Normal file
@@ -0,0 +1,76 @@
|
||||
using System;
|
||||
using DMS.Core.Enums;
|
||||
|
||||
namespace DMS.Models;
|
||||
|
||||
/// <summary>
|
||||
/// 表示变量数据与MQTT服务器之间的关联模型,包含MQTT别名。
|
||||
/// </summary>
|
||||
public partial class VariableMqtt
|
||||
{
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 关联的唯一标识符。
|
||||
/// </summary>
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 关联的变量数据ID。
|
||||
/// </summary>
|
||||
public int VariableId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 关联的MQTT服务器ID。
|
||||
/// </summary>
|
||||
public int MqttId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 变量在该MQTT服务器上的别名。
|
||||
/// </summary>
|
||||
private string _mqttAlias = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 变量的唯一标识符(S7地址或OPC UA NodeId)。
|
||||
/// </summary>
|
||||
public string Identifier
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Variable!=null)
|
||||
{
|
||||
|
||||
|
||||
if (Variable.ProtocolType == ProtocolType.S7)
|
||||
{
|
||||
return Variable.S7Address;
|
||||
}
|
||||
else if (Variable.ProtocolType == ProtocolType.OpcUA)
|
||||
{
|
||||
return Variable.OpcUaNodeId;
|
||||
}
|
||||
}
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建时间。
|
||||
/// </summary>
|
||||
public DateTime CreateTime { get; set; } = DateTime.Now;
|
||||
|
||||
/// <summary>
|
||||
/// 更新时间。
|
||||
/// </summary>
|
||||
public DateTime UpdateTime { get; set; } = DateTime.Now;
|
||||
|
||||
/// <summary>
|
||||
/// 导航属性:关联的变量数据。
|
||||
/// </summary>
|
||||
public Variable Variable { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 导航属性:关联的MQTT服务器。
|
||||
/// </summary>
|
||||
public Mqtt Mqtt { get; set; }
|
||||
}
|
||||
51
DMS.Core/Models/VariableTable.cs
Normal file
51
DMS.Core/Models/VariableTable.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using DMS.Core.Enums;
|
||||
|
||||
namespace DMS.Models;
|
||||
|
||||
/// <summary>
|
||||
/// 表示变量表信息。
|
||||
/// </summary>
|
||||
public partial class VariableTable
|
||||
{
|
||||
/// <summary>
|
||||
/// 变量表关联的设备。
|
||||
/// </summary>
|
||||
public Device? Device { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 变量表关联的设备ID。
|
||||
/// </summary>
|
||||
public int? DeviceId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 变量表描述。
|
||||
/// </summary>
|
||||
private string description;
|
||||
|
||||
/// <summary>
|
||||
/// 变量表中包含的数据变量列表。
|
||||
/// </summary>
|
||||
public ObservableCollection<Variable> variables;
|
||||
|
||||
/// <summary>
|
||||
/// 变量表的唯一标识符。
|
||||
/// </summary>
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 表示变量表是否处于活动状态。
|
||||
/// </summary>
|
||||
private bool isActive;
|
||||
|
||||
/// <summary>
|
||||
/// 变量表名称。
|
||||
/// </summary>
|
||||
private string name;
|
||||
|
||||
/// <summary>
|
||||
/// 变量表使用的协议类型。
|
||||
/// </summary>
|
||||
public ProtocolType ProtocolType { get; set; }
|
||||
}
|
||||
Reference in New Issue
Block a user