修改了Mqtt服务器启动不加载的问题

This commit is contained in:
2025-09-06 13:19:20 +08:00
parent 52f76e2377
commit 56130cd92a
9 changed files with 308 additions and 244 deletions

View File

@@ -4,12 +4,14 @@ using AutoMapper;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Messaging;
using DMS.Application.DTOs;
using DMS.Application.DTOs.Events;
using DMS.Core.Models;
using DMS.Application.Interfaces;
using DMS.Core.Enums;
using DMS.Core.Models;
using DMS.Message;
using DMS.WPF.ViewModels.Items;
using Microsoft.IdentityModel.Protocols.OpenIdConnect;
namespace DMS.WPF.Services;
@@ -99,17 +101,27 @@ public partial class DataServices : ObservableObject, IRecipient<LoadMessage>, I
// 监听变量值变更事件
_dataCenterService.VariableValueChanged += OnVariableValueChanged;
_dataCenterService.DataLoadCompleted += OnDataLoadCompleted;
// 注册消息接收
// WeakReferenceMessenger.Register<LoadMessage>(this, (r, m) => r.Receive(m));
}
private void OnDataLoadCompleted(object? sender, DataLoadCompletedEventArgs e)
{
if (e.IsSuccess)
{
LoadAllDatas();
}
}
/// <summary>
/// 异步加载设备数据并以高效的方式更新UI集合。
/// 此方法会比较新旧数据只对有变化的设备进行更新、添加或删除避免不必要的UI刷新。
/// </summary>
public async Task LoadAllDatas()
private void LoadAllDatas()
{
Devices = _mapper.Map<ObservableCollection<DeviceItemViewModel>>(_dataCenterService.Devices.Values);
foreach (var device in Devices)
@@ -125,6 +137,9 @@ public partial class DataServices : ObservableObject, IRecipient<LoadMessage>, I
}
Menus = _mapper.Map<ObservableCollection<MenuItemViewModel>>(_dataCenterService.Menus.Values);
// 加载MQTT服务器数据
MqttServers = _mapper.Map<ObservableCollection<MqttServerItemViewModel>>(_dataCenterService.MqttServers.Values);
BuildMenuTrees();
}