消除所有错误,重新构建
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using DMS.Data.Repositories;
|
||||
using DMS.Core.Enums;
|
||||
using DMS.Helper;
|
||||
using DMS.WPF.Models;
|
||||
using DMS.Services;
|
||||
using DMS.WPF.Helper;
|
||||
using DMS.WPF.Services;
|
||||
using DMS.WPF.ViewModels.Items;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using DMS.Data;
|
||||
using DMS.WPF.Views;
|
||||
|
||||
namespace DMS.WPF.ViewModels;
|
||||
@@ -16,11 +16,10 @@ public partial class MqttsViewModel : ViewModelBase
|
||||
{
|
||||
private readonly DataServices _dataServices;
|
||||
private readonly IDialogService _dialogService;
|
||||
private readonly MqttRepository _mqttRepository;
|
||||
private readonly ILogger<MqttsViewModel> _logger;
|
||||
private readonly NavgatorServices _navgatorServices;
|
||||
[ObservableProperty]
|
||||
private ObservableCollection<Mqtt> _mqtts;
|
||||
private ObservableCollection<MqttServerItemViewModel> _mqtts;
|
||||
|
||||
// public ObservableCollection<Mqtt> Mqtts
|
||||
// {
|
||||
@@ -48,125 +47,124 @@ public partial class MqttsViewModel : ViewModelBase
|
||||
// }
|
||||
|
||||
[ObservableProperty]
|
||||
private Mqtt _selectedMqtt;
|
||||
private MqttServerItemViewModel _selectedMqtt;
|
||||
|
||||
public MqttsViewModel(
|
||||
ILogger<MqttsViewModel> logger, IDialogService dialogService, DataServices dataServices, NavgatorServices navgatorServices,MqttRepository mqttRepository
|
||||
ILogger<MqttsViewModel> logger, IDialogService dialogService, DataServices dataServices, NavgatorServices navgatorServices
|
||||
)
|
||||
{
|
||||
_mqttRepository = mqttRepository;
|
||||
_logger = logger;
|
||||
_dialogService = dialogService;
|
||||
_dataServices = dataServices;
|
||||
_navgatorServices = navgatorServices;
|
||||
|
||||
if (dataServices.Mqtts == null || dataServices.Mqtts.Count == 0)
|
||||
{
|
||||
MessageHelper.SendLoadMessage(LoadTypes.Mqtts);
|
||||
}
|
||||
else
|
||||
{
|
||||
Mqtts = new ObservableCollection<Mqtt>(dataServices.Mqtts);
|
||||
}
|
||||
|
||||
|
||||
_dataServices.OnMqttListChanged += ( mqtts) =>
|
||||
{
|
||||
Mqtts = new ObservableCollection<Mqtt>(mqtts);
|
||||
};
|
||||
// if (dataServices.Mqtts == null || dataServices.Mqtts.Count == 0)
|
||||
// {
|
||||
// MessageHelper.SendLoadMessage(LoadTypes.Mqtts);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// Mqtts = new ObservableCollection<Mqtt>(dataServices.Mqtts);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// _dataServices.OnMqttListChanged += ( mqtts) =>
|
||||
// {
|
||||
// Mqtts = new ObservableCollection<Mqtt>(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
// 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);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
public async void 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
|
||||
// {
|
||||
// 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);
|
||||
// }
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
public async void 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)
|
||||
// {
|
||||
// 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);
|
||||
// }
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
public async void 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)
|
||||
// {
|
||||
// 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);
|
||||
// }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user