From e3730eccb4b7a806a6c97fed89ed40a06266ed45 Mon Sep 17 00:00:00 2001 From: "David P.G" Date: Tue, 15 Jul 2025 11:03:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=86=E4=B8=80=E4=BA=9B?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Data/Entities/DbMqtt.cs | 12 ++++++------ Models/Mqtt.cs | 2 +- Services/MqttBackgroundService.cs | 6 ++++-- Views/Dialogs/MqttDialog.xaml | 2 +- Views/MqttsView.xaml | 2 +- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/Data/Entities/DbMqtt.cs b/Data/Entities/DbMqtt.cs index d8ac213..c124d93 100644 --- a/Data/Entities/DbMqtt.cs +++ b/Data/Entities/DbMqtt.cs @@ -49,7 +49,7 @@ public class DbMqtt /// /// MQTT客户端登录密码。 /// - [SugarColumn(IsIgnore = true)] + [SugarColumn(IsNullable = true)] public string PassWord { get; set; } = String.Empty; /// @@ -66,25 +66,25 @@ public class DbMqtt /// /// MQTT发布主题。 /// - [SugarColumn(IsIgnore = true)] + [SugarColumn(IsNullable = true)] public string PublishTopic { get; set; } = String.Empty; /// /// MQTT备注。 /// - [SugarColumn(IsIgnore = true)] + [SugarColumn(IsNullable = true)] public string Remark { get; set; } = String.Empty; /// /// MQTT订阅主题。 /// - [SugarColumn(IsIgnore = true)] - public string SubTopics { get; set; } = String.Empty; + [SugarColumn(IsNullable = true)] + public string SubTopic { get; set; } = String.Empty; /// /// MQTT客户端登录用户名。 /// - [SugarColumn(IsIgnore = true)] + [SugarColumn(IsNullable = true)] public string UserName { get; set; } = String.Empty; /// diff --git a/Models/Mqtt.cs b/Models/Mqtt.cs index 2135e6d..61ecc0e 100644 --- a/Models/Mqtt.cs +++ b/Models/Mqtt.cs @@ -72,7 +72,7 @@ public partial class Mqtt : ObservableObject /// /// MQTT订阅主题。 /// - public string SubTopics { get; set; } + public string SubTopic { get; set; } /// /// MQTT客户端登录用户名。 diff --git a/Services/MqttBackgroundService.cs b/Services/MqttBackgroundService.cs index 7d28aed..c0efaaa 100644 --- a/Services/MqttBackgroundService.cs +++ b/Services/MqttBackgroundService.cs @@ -161,8 +161,8 @@ namespace PMSWPF.Services mqtt.IsConnected = true; // 订阅主题 - await client.SubscribeAsync(new MqttTopicFilterBuilder().WithTopic("test").Build()); - NlogHelper.Info($"MQTT客户端 {mqtt.Name} 已订阅主题: {mqtt.SubTopics}"); + await client.SubscribeAsync(new MqttTopicFilterBuilder().WithTopic(mqtt.SubTopic).Build()); + NlogHelper.Info($"MQTT客户端 {mqtt.Name} 已订阅主题: {mqtt.SubTopic}"); }); // 设置接收消息处理程序 @@ -183,6 +183,8 @@ namespace PMSWPF.Services // 服务停止 if (_stopEvent.WaitOne(0)) return; + if (!mqtt.IsActive) + return; NlogHelper.Info($"5秒后重新连接Mqtt服务器:{mqtt.Name}"); // 尝试重新连接。 diff --git a/Views/Dialogs/MqttDialog.xaml b/Views/Dialogs/MqttDialog.xaml index 7752a40..5191a43 100644 --- a/Views/Dialogs/MqttDialog.xaml +++ b/Views/Dialogs/MqttDialog.xaml @@ -68,7 +68,7 @@ - + - +