修改了Mqtt服务器启动不加载的问题
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
@@ -27,6 +27,9 @@ public partial class MqttServerItemViewModel : ObservableObject
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _isActive;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _isConnect;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _subscribeTopic;
|
||||
|
||||
@@ -50,17 +50,8 @@ public partial class SplashViewModel : ObservableObject
|
||||
LoadingMessage = "正在初始化数据库...";
|
||||
_initializeService.InitializeTables();
|
||||
_initializeService.InitializeMenus();
|
||||
await _dataCenterService.LoadAllDataToMemoryAsync();
|
||||
|
||||
LoadingMessage = "正在加载系统配置...";
|
||||
await _dataServices.LoadAllDatas();
|
||||
// await _dataServices.LoadVariableTables();
|
||||
// await _dataServices.LoadVariables();
|
||||
// await _dataServices.LoadMenus();
|
||||
|
||||
|
||||
// _dataServices.AssociateVariableTablesToDevices();
|
||||
// _dataServices.AssociateVariablesToVariableTables();
|
||||
await _dataCenterService.LoadAllDataToMemoryAsync();
|
||||
|
||||
// 可以在这里添加加载配置的逻辑
|
||||
await Task.Delay(500); // 模拟耗时
|
||||
@@ -83,7 +74,7 @@ public partial class SplashViewModel : ObservableObject
|
||||
{
|
||||
// 处理初始化过程中的异常
|
||||
LoadingMessage = $"初始化失败: {ex.Message}";
|
||||
Console.WriteLine($"初始化失败: {ex}");
|
||||
_logger.LogError(ex,$"初始化失败: {ex}");
|
||||
// 在此可以记录日志或显示错误对话框
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -63,6 +63,7 @@
|
||||
Grid.Row="1"
|
||||
Grid.Column="0"
|
||||
Margin="0,15,0,0"
|
||||
hc:InfoElement.Title="服务器地址:"
|
||||
Text="{Binding MqttServer.ServerUrl, UpdateSourceTrigger=PropertyChanged}" />
|
||||
|
||||
<hc:TextBox
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
<Style TargetType="Border">
|
||||
<Setter Property="Background" Value="{DynamicResource SystemControlBackgroundAltHighBrush}" />
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding IsConnected}" Value="True">
|
||||
<DataTrigger Binding="{Binding IsConnect}" Value="True">
|
||||
<Setter Property="Background" Value="LightGreen" />
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
@@ -47,7 +47,7 @@
|
||||
IsOn="{Binding IsActive}"
|
||||
OffContent="停止"
|
||||
OnContent="启动" />
|
||||
<TextBlock Text="{Binding Name}"
|
||||
<TextBlock Text="{Binding ServerName}"
|
||||
FontSize="20"
|
||||
FontWeight="SemiBold"
|
||||
VerticalAlignment="Center" />
|
||||
@@ -62,7 +62,7 @@
|
||||
VerticalAlignment="Center"
|
||||
Margin="0,0,8,0"
|
||||
FontSize="14" />
|
||||
<TextBlock Text="{Binding Remark}"
|
||||
<TextBlock Text="{Binding MessageFormat}"
|
||||
Foreground="{DynamicResource SystemControlForegroundBaseMediumBrush}"
|
||||
TextTrimming="CharacterEllipsis" />
|
||||
</StackPanel>
|
||||
@@ -73,7 +73,7 @@
|
||||
Margin="0,0,8,0"
|
||||
FontSize="14" />
|
||||
<TextBlock>
|
||||
<Run Text="{Binding Host, FallbackValue='127.0.0.1'}" />
|
||||
<Run Text="{Binding ServerUrl, FallbackValue='127.0.0.1'}" />
|
||||
<Run Text=":" />
|
||||
<Run Text="{Binding Port, FallbackValue='1883'}" />
|
||||
</TextBlock>
|
||||
@@ -85,7 +85,7 @@
|
||||
Margin="0,0,8,0"
|
||||
FontSize="14" />
|
||||
<TextBlock>
|
||||
<Run Text="{Binding Platform, FallbackValue='EMQX'}" />
|
||||
<Run Text="未指定平台" />
|
||||
</TextBlock>
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal"
|
||||
@@ -94,7 +94,7 @@
|
||||
VerticalAlignment="Center"
|
||||
Margin="0,0,8,0"
|
||||
FontSize="14" />
|
||||
<TextBlock Text="{Binding ClientID}" />
|
||||
<TextBlock Text="{Binding ClientId}" />
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal"
|
||||
Margin="0,2">
|
||||
@@ -102,7 +102,7 @@
|
||||
VerticalAlignment="Center"
|
||||
Margin="0,0,8,0"
|
||||
FontSize="14" />
|
||||
<TextBlock Text="{Binding UserName}" />
|
||||
<TextBlock Text="{Binding Username}" />
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal"
|
||||
Margin="0,2">
|
||||
@@ -110,7 +110,7 @@
|
||||
VerticalAlignment="Center"
|
||||
Margin="0,0,8,0"
|
||||
FontSize="14" />
|
||||
<TextBlock Text="{Binding PassWord}" />
|
||||
<TextBlock Text="{Binding Password}" />
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal"
|
||||
Margin="0,2">
|
||||
@@ -126,7 +126,7 @@
|
||||
VerticalAlignment="Center"
|
||||
Margin="0,0,8,0"
|
||||
FontSize="14" />
|
||||
<TextBlock Text="{Binding SubTopic}" />
|
||||
<TextBlock Text="{Binding SubscribeTopic}" />
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal"
|
||||
Margin="0,2">
|
||||
@@ -134,7 +134,7 @@
|
||||
VerticalAlignment="Center"
|
||||
Margin="0,0,8,0"
|
||||
FontSize="14" />
|
||||
<TextBlock Text="{Binding ConnTime}" />
|
||||
<TextBlock Text="{Binding ConnectedAt}" />
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal"
|
||||
Margin="0,2">
|
||||
@@ -142,7 +142,7 @@
|
||||
VerticalAlignment="Center"
|
||||
Margin="0,0,8,0"
|
||||
FontSize="14" />
|
||||
<TextBlock Text="{Binding ConnectMessage}" />
|
||||
<TextBlock Text="{Binding MessageFormat}" />
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal"
|
||||
Margin="0,2">
|
||||
@@ -150,7 +150,8 @@
|
||||
VerticalAlignment="Center"
|
||||
Margin="0,0,8,0"
|
||||
FontSize="14" />
|
||||
<TextBlock Text="{Binding IsDefault}" />
|
||||
<!-- IsDefault 属性未在 ViewModel 中定义,已移除绑定 -->
|
||||
<TextBlock Text="未设置默认" />
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
|
||||
Reference in New Issue
Block a user