1 feat(mqtt): 实现MQTT服务器状态管理与事件系统

2
    3 1. 在MqttServer和MqttServerDto模型中添加IsConnect属性,用于跟踪连接状态
    4 2. 重构MqttManagementService服务,使用事件驱动方式管理服务器状态变化
    5 3. 实现MqttServerChangedEventArgs事件参数类,支持区分不同变更类型
    6 4. 在IEventService中添加OnMqttServerChanged事件,实现事件通知机制
    7 5. 优化数据存储结构,将MqttServers从ObservableCollection改为ObservableDictionary
    8 6. 更新MqttServiceManager以正确处理连接状态和事件触发
    9 7. 在WPF层更新UI以响应服务器状态变化
   10 8. 删除不再需要的Helper类(DataServicesHelper, MessageHelper, SiemensHelper)
   11 9. 在NLog配置中添加调试器输出目标以便调试
   12 10. 完善VariableHistoryViewModel防止空引用异常
This commit is contained in:
2025-10-05 00:28:25 +08:00
parent d4562e600e
commit a6fc543e4f
25 changed files with 497 additions and 537 deletions

View File

@@ -1,28 +1,28 @@
<ui:ContentDialog x:Class="DMS.WPF.Views.Dialogs.MqttDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ikw="http://schemas.inkore.net/lib/ui/wpf"
xmlns:hc="https://handyorg.github.io/handycontrol"
xmlns:ui="http://schemas.inkore.net/lib/ui/wpf/modern"
xmlns:vmd="clr-namespace:DMS.WPF.ViewModels.Dialogs"
xmlns:ex="clr-namespace:DMS.Extensions"
xmlns:enums="clr-namespace:DMS.Core.Enums;assembly=DMS.Core"
xmlns:valueConverts="clr-namespace:DMS.WPF.ValueConverts"
Title="{Binding Title}"
CloseButtonText="取消"
DefaultButton="Primary"
PrimaryButtonText="{Binding PrimaryButText}"
PrimaryButtonCommand="{Binding PrimaryButtonCommand}"
CloseButtonCommand="{Binding CancelButtonCommand}"
d:DataContext="{d:DesignInstance vmd:MqttDialogViewModel}"
mc:Ignorable="d">
<ui:ContentDialog
x:Class="DMS.WPF.Views.Dialogs.MqttDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:enums="clr-namespace:DMS.Core.Enums;assembly=DMS.Core"
xmlns:ex="clr-namespace:DMS.Extensions"
xmlns:hc="https://handyorg.github.io/handycontrol"
xmlns:ikw="http://schemas.inkore.net/lib/ui/wpf"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ui="http://schemas.inkore.net/lib/ui/wpf/modern"
xmlns:valueConverts="clr-namespace:DMS.WPF.ValueConverts"
xmlns:vmd="clr-namespace:DMS.WPF.ViewModels.Dialogs"
Title="{Binding Title}"
d:DataContext="{d:DesignInstance vmd:MqttDialogViewModel}"
CloseButtonCommand="{Binding CancelButtonCommand}"
CloseButtonText="取消"
DefaultButton="Primary"
PrimaryButtonCommand="{Binding PrimaryButtonCommand}"
PrimaryButtonText="{Binding PrimaryButText}"
mc:Ignorable="d">
<ui:ContentDialog.Resources>
<ex:EnumBindingSource x:Key="mqttPlatform"
EnumType="{x:Type enums:MqttPlatform}" />
<ex:EnumBindingSource x:Key="mqttPlatform" EnumType="{x:Type enums:MqttPlatform}" />
<valueConverts:EnumDescriptionConverter x:Key="EnumDescriptionConverter" />
<Style x:Key="LabelStyle" TargetType="TextBlock">
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="HorizontalAlignment" Value="Right" />
@@ -31,7 +31,7 @@
</ui:ContentDialog.Resources>
<StackPanel Margin="16">
<!-- 基本信息 -->
<!-- 基本信息 -->
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
@@ -49,7 +49,7 @@
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<!-- Row 0 -->
<!-- Row 0 -->
<hc:TextBox
Grid.Row="0"
Grid.Column="0"
@@ -76,7 +76,7 @@
hc:InfoElement.Title="端口:"
Text="{Binding MqttServer.Port, UpdateSourceTrigger=PropertyChanged}" />
<!-- Row 2 -->
<!-- Row 2 -->
<hc:TextBox
Grid.Row="2"
Grid.Column="0"
@@ -91,7 +91,7 @@
hc:InfoElement.Title="密码:"
Text="{Binding MqttServer.Password, UpdateSourceTrigger=PropertyChanged}" />
<!-- Row 3 -->
<!-- Row 3 -->
<hc:TextBox
Grid.Row="3"
Grid.Column="0"
@@ -105,44 +105,44 @@
Margin="0,15,0,0"
hc:InfoElement.Title="订阅主题:"
Text="{Binding MqttServer.SubscribeTopic, UpdateSourceTrigger=PropertyChanged}" />
<!-- Row 5 -->
<!-- Row 5 -->
<hc:TextBox
Grid.Row="4"
Grid.Column="0"
Grid.ColumnSpan="3"
Margin="0,15,0,0"
hc:InfoElement.Title="消息头:"
Text="{Binding MqttServer.MessageHeader, UpdateSourceTrigger=PropertyChanged}"
TextWrapping="Wrap"
VerticalContentAlignment="Top"
hc:InfoElement.Title="消息头:可以使用{timestamp}表示时间戳"
AcceptsReturn="True"
VerticalContentAlignment="Top" />
Text="{Binding MqttServer.MessageHeader, UpdateSourceTrigger=PropertyChanged}"
TextWrapping="Wrap" />
<hc:TextBox
Grid.Row="5"
Grid.Column="0"
Grid.ColumnSpan="3"
Margin="0,15,0,0"
hc:InfoElement.Title="消息内容:"
Text="{Binding MqttServer.MessageContent, UpdateSourceTrigger=PropertyChanged}"
TextWrapping="Wrap"
VerticalContentAlignment="Top"
hc:InfoElement.Title="消息内容:可以使用,{name}表示变量名,{value}表示变量值"
AcceptsReturn="True"
VerticalContentAlignment="Top" />
<!-- Row 6 -->
Text="{Binding MqttServer.MessageContent, UpdateSourceTrigger=PropertyChanged}"
TextWrapping="Wrap" />
<!-- Row 6 -->
<hc:TextBox
Grid.Row="6"
Grid.Column="0"
Grid.ColumnSpan="3"
Margin="0,15,0,0"
VerticalContentAlignment="Top"
hc:InfoElement.Title="消息尾:"
Text="{Binding MqttServer.MessageFooter, UpdateSourceTrigger=PropertyChanged}"
TextWrapping="Wrap"
AcceptsReturn="True"
VerticalContentAlignment="Top" />
<!-- Row 4 -->
Text="{Binding MqttServer.MessageFooter, UpdateSourceTrigger=PropertyChanged}"
TextWrapping="Wrap" />
<!-- Row 4 -->
<CheckBox
Grid.Row="7"
Grid.Column="0"