diff --git a/DMS.Application/DTOs/MqttServerDto.cs b/DMS.Application/DTOs/MqttServerDto.cs index 112b825..09f8036 100644 --- a/DMS.Application/DTOs/MqttServerDto.cs +++ b/DMS.Application/DTOs/MqttServerDto.cs @@ -10,7 +10,7 @@ public class MqttServerDto { public int Id { get; set; } public string ServerName { get; set; } - public string BrokerAddress { get; set; } + public string ServerUrl { get; set; } public int Port { get; set; } public string Username { get; set; } public string Password { get; set; } diff --git a/DMS.Core/Models/MqttServer.cs b/DMS.Core/Models/MqttServer.cs index 11f7c7f..2f15a09 100644 --- a/DMS.Core/Models/MqttServer.cs +++ b/DMS.Core/Models/MqttServer.cs @@ -7,7 +7,7 @@ public class MqttServer { public int Id { get; set; } public string ServerName { get; set; } - public string BrokerAddress { get; set; } // Broker地址 + public string ServerUrl { get; set; } // Broker地址 public int Port { get; set; } // 端口 public string Username { get; set; } // 用户名 public string Password { get; set; } // 密码 diff --git a/DMS.Infrastructure.UnitTests/FakerHelper.cs b/DMS.Infrastructure.UnitTests/FakerHelper.cs index a1b3f21..b7665f7 100644 --- a/DMS.Infrastructure.UnitTests/FakerHelper.cs +++ b/DMS.Infrastructure.UnitTests/FakerHelper.cs @@ -97,7 +97,7 @@ namespace DMS.Infrastructure.UnitTests { var dbMqttServer = new Faker() .RuleFor(d => d.ServerName, f => f.Company.CompanyName()) - .RuleFor(d => d.BrokerAddress, f => f.Internet.Ip()) + .RuleFor(d => d.ServerUrl, f => f.Internet.Ip()) .RuleFor(d => d.Username, f => f.Internet.UserName()) .RuleFor(d => d.Password, f => f.Internet.Password()) .RuleFor(d => d.SubscribeTopic, f => "/topic/sub") diff --git a/DMS.Infrastructure/Entities/DbMqttServer.cs b/DMS.Infrastructure/Entities/DbMqttServer.cs index 3b8f813..96c6764 100644 --- a/DMS.Infrastructure/Entities/DbMqttServer.cs +++ b/DMS.Infrastructure/Entities/DbMqttServer.cs @@ -19,9 +19,9 @@ public class DbMqttServer public string ServerName { get; set; } /// - /// MQTT代理地址 + /// MQTT服务器URL /// - public string BrokerAddress { get; set; } + public string ServerUrl { get; set; } /// /// 端口号 @@ -66,15 +66,18 @@ public class DbMqttServer /// /// 连接时间 /// + [SugarColumn(IsNullable = true)] public DateTime? ConnectedAt { get; set; } /// /// 连接持续时间(秒) /// + [SugarColumn(IsNullable = true)] public long ConnectionDuration { get; set; } /// /// 消息格式 /// + [SugarColumn(IsNullable = true)] public string MessageFormat { get; set; } } \ No newline at end of file diff --git a/DMS.Infrastructure/Services/MqttBackgroundService.cs b/DMS.Infrastructure/Services/MqttBackgroundService.cs index 1f78947..0249aa7 100644 --- a/DMS.Infrastructure/Services/MqttBackgroundService.cs +++ b/DMS.Infrastructure/Services/MqttBackgroundService.cs @@ -266,7 +266,7 @@ public class MqttBackgroundService : BackgroundService var options = new MqttClientOptionsBuilder() .WithClientId(mqtt.ClientId) - .WithTcpServer(mqtt.BrokerAddress, mqtt.Port) + .WithTcpServer(mqtt.ServerUrl, mqtt.Port) .WithCredentials(mqtt.Username, mqtt.Password) .WithCleanSession() .Build(); diff --git a/DMS.WPF/App.xaml.cs b/DMS.WPF/App.xaml.cs index e757d93..fe508c2 100644 --- a/DMS.WPF/App.xaml.cs +++ b/DMS.WPF/App.xaml.cs @@ -1,4 +1,5 @@ using System.Windows; +using AutoMapper; using AutoMapper.Internal; using DMS.Application.Interfaces; using DMS.Application.Services; @@ -167,7 +168,14 @@ public partial class App : System.Windows.Application services.AddSingleton(); // 注册WPF中的服务 - services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(provider => + new DataServices( + provider.GetRequiredService(), + provider.GetRequiredService(), + provider.GetRequiredService() + ) + ); @@ -182,7 +190,18 @@ public partial class App : System.Windows.Application services.AddSingleton(); services.AddTransient(); services.AddSingleton(); - services.AddSingleton(); + services.AddSingleton(provider => + new MqttsViewModel( + provider.GetRequiredService>(), + provider.GetRequiredService(), + provider.GetRequiredService(), + provider.GetRequiredService(), + provider.GetRequiredService(), + provider.GetRequiredService(), + provider.GetRequiredService() + ) + ); + services.AddScoped(); // 注册对话框模型 services.AddTransient(); diff --git a/DMS.WPF/Services/DataServices.cs b/DMS.WPF/Services/DataServices.cs index 57f54ce..5a62df1 100644 --- a/DMS.WPF/Services/DataServices.cs +++ b/DMS.WPF/Services/DataServices.cs @@ -2,11 +2,13 @@ using System.Collections.ObjectModel; using System.Windows; using AutoMapper; using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.Messaging; using DMS.Application.DTOs; using DMS.Core.Models; using DMS.Application.Interfaces; using DMS.Core.Enums; using DMS.Core.Models; +using DMS.Message; using DMS.WPF.ViewModels.Items; namespace DMS.WPF.Services; @@ -15,10 +17,11 @@ namespace DMS.WPF.Services; /// 数据服务类,负责从数据库加载和管理各种数据,并提供数据变更通知。 /// 继承自ObservableRecipient,可以接收消息;实现IRecipient,处理加载消息。 /// -public partial class DataServices : ObservableObject, IDisposable +public partial class DataServices : ObservableObject, IRecipient, IDisposable { private readonly IMapper _mapper; private readonly IDataCenterService _dataCenterService; + private readonly IMqttAppService _mqttAppService; // 设备列表,使用ObservableProperty特性,当值改变时会自动触发属性变更通知。 @@ -42,8 +45,8 @@ public partial class DataServices : ObservableObject, IDisposable private ObservableCollection _menuTrees; // MQTT配置列表。 - // [ObservableProperty] - // private List _mqtts; + [ObservableProperty] + private ObservableCollection _mqttServers; // 设备列表变更事件,当设备列表数据更新时触发。 @@ -53,7 +56,7 @@ public partial class DataServices : ObservableObject, IDisposable public event Action> OnMenuTreeListChanged; // MQTT列表变更事件,当MQTT配置数据更新时触发。 - // public event Action> OnMqttListChanged; + public event Action> OnMqttListChanged; /// /// 处理变量值变更事件 @@ -81,19 +84,24 @@ public partial class DataServices : ObservableObject, IDisposable /// /// AutoMapper 实例。 /// 数据服务中心实例。 - public DataServices(IMapper mapper, IDataCenterService dataCenterService) + /// MQTT应用服务实例。 + public DataServices(IMapper mapper, IDataCenterService dataCenterService, IMqttAppService mqttAppService) { _mapper = mapper; _dataCenterService = dataCenterService; + _mqttAppService = mqttAppService; Devices = new ObservableCollection(); VariableTables = new ObservableCollection(); Variables = new ObservableCollection(); Menus = new ObservableCollection(); MenuTrees = new ObservableCollection(); - // AllVariables = new ConcurrentDictionary(); + MqttServers = new ObservableCollection(); // 监听变量值变更事件 _dataCenterService.VariableValueChanged += OnVariableValueChanged; + + // 注册消息接收 + // WeakReferenceMessenger.Register(this, (r, m) => r.Receive(m)); } @@ -380,6 +388,84 @@ public partial class DataServices : ObservableObject, IDisposable Variables.Remove(variableItem); } + /// + /// 异步加载所有MQTT服务器数据 + /// + public async Task LoadMqttServers(IMqttAppService mqttAppService) + { + try + { + var mqttServerDtos = await mqttAppService.GetAllMqttServersAsync(); + MqttServers = _mapper.Map>(mqttServerDtos); + OnMqttListChanged?.Invoke(mqttServerDtos); + } + catch (Exception ex) + { + // 记录异常或处理错误 + Console.WriteLine($"加载MQTT服务器数据时发生错误: {ex.Message}"); + } + } + + /// + /// 添加MQTT服务器 + /// + public async Task AddMqttServer(IMqttAppService mqttAppService, MqttServerItemViewModel mqttServer) + { + var dto = _mapper.Map(mqttServer); + var id = await mqttAppService.CreateMqttServerAsync(dto); + dto.Id = id; + + var mqttServerItem = _mapper.Map(dto); + MqttServers.Add(mqttServerItem); + + return mqttServerItem; + } + + /// + /// 更新MQTT服务器 + /// + public async Task UpdateMqttServer(IMqttAppService mqttAppService, MqttServerItemViewModel mqttServer) + { + var dto = _mapper.Map(mqttServer); + await mqttAppService.UpdateMqttServerAsync(dto); + return true; + } + + /// + /// 删除MQTT服务器 + /// + public async Task DeleteMqttServer(IMqttAppService mqttAppService, MqttServerItemViewModel mqttServer) + { + await mqttAppService.DeleteMqttServerAsync(mqttServer.Id); + MqttServers.Remove(mqttServer); + return true; + } + + /// + /// 处理LoadMessage消息 + /// + /// 加载消息 + public void Receive(LoadMessage message) + { + switch (message.LoadType) + { + case LoadTypes.Devices: + // 设备数据已在IDataCenterService中处理 + break; + case LoadTypes.Menu: + // 菜单数据已在IDataCenterService中处理 + break; + case LoadTypes.Mqtts: + _ = Task.Run(async () => await LoadMqttServers(_mqttAppService)); + break; + case LoadTypes.All: + // 加载所有数据 + LoadAllDatas(); + _ = Task.Run(async () => await LoadMqttServers(_mqttAppService)); + break; + } + } + /// /// 释放资源 /// diff --git a/DMS.WPF/Services/DialogService.cs b/DMS.WPF/Services/DialogService.cs index 37f1222..1db379f 100644 --- a/DMS.WPF/Services/DialogService.cs +++ b/DMS.WPF/Services/DialogService.cs @@ -23,7 +23,7 @@ namespace DMS.WPF.Services { typeof(VariableDialogViewModel), typeof(VariableDialog) }, { typeof(PollLevelDialogViewModel), typeof(PollLevelDialog) }, { typeof(IsActiveDialogViewModel), typeof(IsActiveDialog) }, - // { typeof(MqttDialogViewModel), typeof(MqttDialog) }, // Add other mappings here + { typeof(MqttDialogViewModel), typeof(MqttDialog) }, // Add other mappings here // ... other dialogs }; diff --git a/DMS.WPF/Services/NavigationService.cs b/DMS.WPF/Services/NavigationService.cs index 42fc347..fc644f2 100644 --- a/DMS.WPF/Services/NavigationService.cs +++ b/DMS.WPF/Services/NavigationService.cs @@ -1,4 +1,3 @@ -using DMS.ViewModels; using DMS.WPF.Interfaces; using DMS.WPF.ViewModels; using DMS.WPF.ViewModels.Items; diff --git a/DMS.WPF/ViewModels/Dialogs/MqttAliasDialogViewModel.cs b/DMS.WPF/ViewModels/Dialogs/MqttAliasDialogViewModel.cs index e641367..c9e84e1 100644 --- a/DMS.WPF/ViewModels/Dialogs/MqttAliasDialogViewModel.cs +++ b/DMS.WPF/ViewModels/Dialogs/MqttAliasDialogViewModel.cs @@ -3,7 +3,7 @@ using CommunityToolkit.Mvvm.Input; namespace DMS.WPF.ViewModels.Dialogs; -public partial class MqttAliasDialogViewModel : ObservableObject +public partial class MqttAliasDialogViewModel : DialogViewModelBase { [ObservableProperty] private string _title = "设置MQTT别名"; @@ -31,4 +31,16 @@ public partial class MqttAliasDialogViewModel : ObservableObject { } + + [RelayCommand] + private void Confirm() + { + Close(MqttAlias); + } + + [RelayCommand] + private void Cancel() + { + Close(null); + } } \ No newline at end of file diff --git a/DMS.WPF/ViewModels/Dialogs/MqttDialogViewModel.cs b/DMS.WPF/ViewModels/Dialogs/MqttDialogViewModel.cs index c72488a..d01a9c7 100644 --- a/DMS.WPF/ViewModels/Dialogs/MqttDialogViewModel.cs +++ b/DMS.WPF/ViewModels/Dialogs/MqttDialogViewModel.cs @@ -1,25 +1,56 @@ using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; +using DMS.WPF.ViewModels.Items; namespace DMS.WPF.ViewModels.Dialogs; -public partial class MqttDialogViewModel : ObservableObject +public partial class MqttDialogViewModel : DialogViewModelBase { - // [ObservableProperty] - // private Mqtt _mqtt; - // - // [ObservableProperty] private string title ; - // [ObservableProperty] private string primaryButContent ; - // - // public MqttDialogViewModel(Mqtt mqtt) - // { - // _mqtt = mqtt; - // } - // - // - // [RelayCommand] - // public void AddMqtt() - // { - // - // } + [ObservableProperty] + private MqttServerItemViewModel _mqttServer; + + [ObservableProperty] + private string _title; + + [ObservableProperty] + private string _primaryButText; + + public MqttDialogViewModel() + { + MqttServer = new MqttServerItemViewModel(); + } + + public MqttDialogViewModel(MqttServerItemViewModel mqttServer) + { + MqttServer = new MqttServerItemViewModel + { + Id = mqttServer.Id, + ServerName = mqttServer.ServerName, + ServerUrl = mqttServer.ServerUrl, + Port = mqttServer.Port, + Username = mqttServer.Username, + Password = mqttServer.Password, + IsActive = mqttServer.IsActive, + SubscribeTopic = mqttServer.SubscribeTopic, + PublishTopic = mqttServer.PublishTopic, + ClientId = mqttServer.ClientId, + CreatedAt = mqttServer.CreatedAt, + ConnectedAt = mqttServer.ConnectedAt, + ConnectionDuration = mqttServer.ConnectionDuration, + MessageFormat = mqttServer.MessageFormat + }; + } + + [RelayCommand] + private void PrimaryButton() + { + + Close(MqttServer); + } + + [RelayCommand] + private void CancelButton() + { + Close(null); + } } \ No newline at end of file diff --git a/DMS.WPF/ViewModels/Items/MqttServerItemViewModel.cs b/DMS.WPF/ViewModels/Items/MqttServerItemViewModel.cs index 2920579..acbad3f 100644 --- a/DMS.WPF/ViewModels/Items/MqttServerItemViewModel.cs +++ b/DMS.WPF/ViewModels/Items/MqttServerItemViewModel.cs @@ -14,7 +14,7 @@ public partial class MqttServerItemViewModel : ObservableObject private string _serverName; [ObservableProperty] - private string _brokerAddress; + private string _serverUrl; [ObservableProperty] private int _port; diff --git a/DMS.WPF/ViewModels/MqttServerDetailViewModel.cs b/DMS.WPF/ViewModels/MqttServerDetailViewModel.cs index ad7217e..98898b0 100644 --- a/DMS.WPF/ViewModels/MqttServerDetailViewModel.cs +++ b/DMS.WPF/ViewModels/MqttServerDetailViewModel.cs @@ -9,7 +9,7 @@ using DMS.WPF.Services; using DMS.WPF.ViewModels; using DMS.WPF.ViewModels.Items; -namespace DMS.ViewModels +namespace DMS.WPF.ViewModels { /// /// MQTT服务器详情视图模型。 diff --git a/DMS.WPF/ViewModels/MqttsViewModel.cs b/DMS.WPF/ViewModels/MqttsViewModel.cs index cf543eb..1f6fe8d 100644 --- a/DMS.WPF/ViewModels/MqttsViewModel.cs +++ b/DMS.WPF/ViewModels/MqttsViewModel.cs @@ -1,181 +1,184 @@ using System.Collections.ObjectModel; +using AutoMapper; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; +using DMS.Application.DTOs; +using DMS.Application.Interfaces; using DMS.Core.Enums; -using DMS.Services; -using DMS.WPF.Helper; using DMS.WPF.Interfaces; using DMS.WPF.Services; +using DMS.WPF.ViewModels.Dialogs; using DMS.WPF.ViewModels.Items; using Microsoft.Extensions.Logging; -using DMS.WPF.Views; namespace DMS.WPF.ViewModels; +/// +/// MQTT服务器管理视图模型,负责MQTT服务器的增删改查操作。 +/// public partial class MqttsViewModel : ViewModelBase { private readonly DataServices _dataServices; + private readonly IMqttAppService _mqttAppService; + private readonly IMapper _mapper; private readonly IDialogService _dialogService; - private readonly ILogger _logger; + private readonly INavigationService _navigationService; + private readonly INotificationService _notificationService; + + /// + /// MQTT服务器列表。 + /// [ObservableProperty] private ObservableCollection _mqtts; - // public ObservableCollection Mqtts - // { - // get => _mqtts; - // set - // { - // if (_mqtts != null) - // { - // foreach (var mqtt in _mqtts) - // { - // mqtt.PropertyChanged -= Mqtt_PropertyChanged; - // } - // } - // - // SetProperty(ref _mqtts, value); - // - // if (_mqtts != null) - // { - // foreach (var mqtt in _mqtts) - // { - // mqtt.PropertyChanged += Mqtt_PropertyChanged; - // } - // } - // } - // } - + /// + /// 当前选中的MQTT服务器。 + /// [ObservableProperty] private MqttServerItemViewModel _selectedMqtt; + private readonly ILogger _logger; + public MqttsViewModel( - ILogger logger, IDialogService dialogService, DataServices dataServices + ILogger logger, + IDialogService dialogService, + DataServices dataServices, + IMqttAppService mqttAppService, + IMapper mapper, + INavigationService navigationService, + INotificationService notificationService ) { _logger = logger; _dialogService = dialogService; _dataServices = dataServices; - - // if (_dataServices.Mqtts == null || _dataServices.Mqtts.Count == 0) - // { - // MessageHelper.SendLoadMessage(LoadTypes.Mqtts); - // } - // else - // { - // Mqtts = new ObservableCollection(_dataServices.Mqtts); - // } - // - // - // _dataServices.OnMqttListChanged += ( mqtts) => - // { - // Mqtts = new ObservableCollection(mqtts); - // }; - } - - private async void Mqtt_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) - { - // if (e.PropertyName == nameof(Mqtt.IsActive)) - // { - // if (sender is Mqtt mqtt) - // { - // try - // { - // await _mqttRepository.UpdateAsync(mqtt); - // NotificationHelper.ShowSuccess($"MQTT: {mqtt.Name} 的启用状态已更新。"); - // MessageHelper.SendLoadMessage(LoadTypes.Mqtts); - // } - // catch (Exception ex) - // { - // NotificationHelper.ShowError($"更新MQTT启用状态失败: {mqtt.Name} - {ex.Message}", ex); - // } - // } - // } + _mqttAppService = mqttAppService; + _mapper = mapper; + _navigationService = navigationService; + _notificationService = notificationService; + + Mqtts = _dataServices.MqttServers; } + /// + /// 添加MQTT服务器命令。 + /// [RelayCommand] - public async void AddMqtt() + public async Task AddMqtt() { - // try - // { - // var mqtt = await _dialogService.ShowAddMqttDialog(); - // if (mqtt == null) - // { - // _logger.LogInformation("用户取消了添加MQTT操作。"); - // return; - // } - // - // await _mqttRepository.AddAsync(mqtt); - // MessageHelper.SendLoadMessage(LoadTypes.Mqtts); - // MessageHelper.SendLoadMessage(LoadTypes.Menu); - // } - // catch (Exception e) - // { - // NotificationHelper.ShowError($"添加MQTT的过程中发生错误:{e.Message}", e); - // } + try + { + // 1. 显示添加MQTT服务器对话框 + MqttServerItemViewModel mqtt = await _dialogService.ShowDialogAsync(new MqttDialogViewModel() + { + Title = "添加MQTT服务器", + PrimaryButText = "添加MQTT服务器" + }); + // 如果用户取消或对话框未返回MQTT服务器,则直接返回 + if (mqtt == null) + { + return; + } + + var mqttItem = await _dataServices.AddMqttServer(_mqttAppService, mqtt); + _notificationService.ShowSuccess($"MQTT服务器添加成功:{mqttItem.ServerName}"); + } + catch (Exception e) + { + _logger.LogError(e, "添加MQTT服务器的过程中发生错误"); + _notificationService.ShowError($"添加MQTT服务器的过程中发生错误:{e.Message}", e); + } } + /// + /// 删除MQTT服务器命令。 + /// [RelayCommand] - public async void DeleteMqtt() + public async Task DeleteMqtt() { - // try - // { - // if (SelectedMqtt == null) - // { - // NotificationHelper.ShowError("你没有选择任何MQTT,请选择MQTT后再点击删除"); - // return; - // } - // - // string msg = $"确认要删除MQTT名为:{SelectedMqtt.Name}"; - // var isDel = await _dialogService.ShowConfrimeDialog("删除MQTT", msg, "删除MQTT"); - // if (isDel) - // { - // await _mqttRepository.DeleteAsync(SelectedMqtt); - // MessageHelper.SendLoadMessage(LoadTypes.Mqtts); - // MessageHelper.SendLoadMessage(LoadTypes.Menu); - // NotificationHelper.ShowSuccess($"删除MQTT成功,MQTT名:{SelectedMqtt.Name}"); - // } - // } - // catch (Exception e) - // { - // NotificationHelper.ShowError($"删除MQTT的过程中发生错误:{e.Message}", e); - // } + try + { + if (SelectedMqtt == null) + { + _notificationService.ShowError("你没有选择任何MQTT服务器,请选择MQTT服务器后再点击删除"); + return; + } + + var viewModel = new ConfirmDialogViewModel("删除MQTT服务器", $"确认要删除MQTT服务器名为:{SelectedMqtt.ServerName}", "删除MQTT服务器"); + if (await _dialogService.ShowDialogAsync(viewModel)) + { + var mqttName = SelectedMqtt.ServerName; + await _dataServices.DeleteMqttServer(_mqttAppService, SelectedMqtt); + _notificationService.ShowSuccess($"删除MQTT服务器成功,服务器名:{mqttName}"); + } + } + catch (Exception e) + { + _logger.LogError(e, "删除MQTT服务器的过程中发生错误"); + _notificationService.ShowError($"删除MQTT服务器的过程中发生错误:{e.Message}", e); + } } + /// + /// 编辑MQTT服务器命令。 + /// [RelayCommand] - public async void EditMqtt() + public async Task EditMqtt() { - // try - // { - // if (SelectedMqtt == null) - // { - // NotificationHelper.ShowError("你没有选择任何MQTT,请选择MQTT后再点击编辑"); - // return; - // } - // - // var editMqtt = await _dialogService.ShowEditMqttDialog(SelectedMqtt); - // if (editMqtt != null) - // { - // var res = await _mqttRepository.UpdateAsync(editMqtt); - // MessageHelper.SendLoadMessage(LoadTypes.Mqtts); - // } - // } - // catch (Exception e) - // { - // NotificationHelper.ShowError($"编辑MQTT的过程中发生错误:{e.Message}", e); - // } + try + { + if (SelectedMqtt == null) + { + _notificationService.ShowError("你没有选择任何MQTT服务器,请选择MQTT服务器后再点击编辑"); + return; + } + + MqttDialogViewModel mqttDialogViewModel = new MqttDialogViewModel(SelectedMqtt) + { + Title = "编辑MQTT服务器", + PrimaryButText = "保存修改" + }; + // 1. 显示MQTT服务器对话框 + MqttServerItemViewModel mqtt = await _dialogService.ShowDialogAsync(mqttDialogViewModel); + // 如果用户取消或对话框未返回MQTT服务器,则直接返回 + if (mqtt == null) + { + return; + } + + await _dataServices.UpdateMqttServer(_mqttAppService, mqtt); + + // 更新UI + _mapper.Map(mqtt, SelectedMqtt); + + _notificationService.ShowSuccess($"编辑MQTT服务器成功:{mqtt.ServerName}"); + } + catch (Exception e) + { + _logger.LogError(e, "编辑MQTT服务器的过程中发生错误"); + _notificationService.ShowError($"编辑MQTT服务器的过程中发生错误:{e.Message}", e); + } } /// /// 导航到MQTT服务器详情页面。 /// [RelayCommand] - private void NavigateToMqttDetail() + private async Task NavigateToMqttDetail() { - // if (SelectedMqtt == null) - // { - // NotificationHelper.ShowMessage("请选择一个MQTT服务器以查看详情。", NotificationType.Warning); - // return; - // } - // _navgatorServices.NavigateTo(SelectedMqtt); + if (SelectedMqtt == null) + { + _notificationService.ShowWarn("请选择一个MQTT服务器以查看详情。"); + return; + } + + // 导航到MQTT服务器详情页 + var menu = new MenuItemViewModel + { + TargetViewKey = "MqttServerDetailView", + TargetId = SelectedMqtt.Id + }; + + await _navigationService.NavigateToAsync(menu); } } \ No newline at end of file diff --git a/DMS.WPF/Views/Dialogs/MqttDialog.xaml b/DMS.WPF/Views/Dialogs/MqttDialog.xaml index d3e4110..8c188e5 100644 --- a/DMS.WPF/Views/Dialogs/MqttDialog.xaml +++ b/DMS.WPF/Views/Dialogs/MqttDialog.xaml @@ -4,119 +4,111 @@ 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:en="clr-namespace:DMS.Core.Enums" 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}" - Background="#fff" + PrimaryButtonCommand="{Binding PrimaryButtonCommand}" + CloseButtonCommand="{Binding CancelButtonCommand}" d:DataContext="{d:DesignInstance vmd:MqttDialogViewModel}" mc:Ignorable="d"> + + - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - - - - - - - - + + + - - - + - - - - - - - + - - - - - - + + - - - + - - - + + - - - - - - - - - + + + + + \ No newline at end of file diff --git a/DMS.WPF/Views/Dialogs/MqttDialog.xaml.cs b/DMS.WPF/Views/Dialogs/MqttDialog.xaml.cs index 43819ea..63b7ab6 100644 --- a/DMS.WPF/Views/Dialogs/MqttDialog.xaml.cs +++ b/DMS.WPF/Views/Dialogs/MqttDialog.xaml.cs @@ -5,9 +5,13 @@ namespace DMS.WPF.Views.Dialogs; public partial class MqttDialog : ContentDialog { - public MqttDialog(MqttDialogViewModel viewModel) + public MqttDialog() { InitializeComponent(); + } + + public MqttDialog(MqttDialogViewModel viewModel) : this() + { DataContext = viewModel; } } \ No newline at end of file diff --git a/DMS.WPF/Views/MqttServerDetailView.xaml b/DMS.WPF/Views/MqttServerDetailView.xaml index 54ad307..632c30a 100644 --- a/DMS.WPF/Views/MqttServerDetailView.xaml +++ b/DMS.WPF/Views/MqttServerDetailView.xaml @@ -40,22 +40,22 @@ - + - + - + - + - + @@ -88,13 +88,13 @@ IsReadOnly="True" SelectionMode="Extended"> - - + + - + diff --git a/DMS.sln b/DMS.sln index 0562014..0ac8efe 100644 --- a/DMS.sln +++ b/DMS.sln @@ -6,9 +6,6 @@ MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DMS.Core", "DMS.Core\DMS.Core.csproj", "{CD16527A-A5F9-482F-ABF7-755DDE1B0406}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DMS.Application", "DMS.Application\DMS.Application.csproj", "{46E180A5-38CB-4229-915F-C9BC44534E77}" - ProjectSection(ProjectDependencies) = postProject - {66FB5295-C6B7-4767-948C-5986480F6733} = {66FB5295-C6B7-4767-948C-5986480F6733} - EndProjectSection EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DMS.Infrastructure", "DMS.Infrastructure\DMS.Infrastructure.csproj", "{66FB5295-C6B7-4767-948C-5986480F6733}" ProjectSection(ProjectDependencies) = postProject