梳理了所有的Db,DTO,ItemViewModel的属性
This commit is contained in:
@@ -351,7 +351,7 @@ public partial class DataServices : ObservableRecipient, IRecipient<LoadMessage>
|
||||
if (existingItem.DisplayValue != dto.DisplayValue) existingItem.DisplayValue = dto.DisplayValue;
|
||||
// 注意:VariableTable 和 MqttAliases 是复杂对象,需要更深层次的比较或重新映射
|
||||
// 为了简化,这里只比较基本类型属性
|
||||
if (existingItem.DataType != dto.DataType) existingItem.DataType = dto.DataType;
|
||||
if (existingItem.SignalType != dto.SignalType) existingItem.SignalType = dto.SignalType;
|
||||
if (existingItem.PollLevel != dto.PollLevel) existingItem.PollLevel = dto.PollLevel;
|
||||
if (existingItem.IsActive != dto.IsActive) existingItem.IsActive = dto.IsActive;
|
||||
if (existingItem.VariableTableId != dto.VariableTableId) existingItem.VariableTableId = dto.VariableTableId;
|
||||
|
||||
@@ -1,263 +1,61 @@
|
||||
using DMS.Core.Enums;
|
||||
using DMS.Core.Models;
|
||||
using DMS.Services;
|
||||
using DMS.WPF.ViewModels.Dialogs;
|
||||
using DMS.WPF.Views.Dialogs;
|
||||
using HandyControl.Tools.Extension;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using iNKORE.UI.WPF.Modern.Controls;
|
||||
|
||||
namespace DMS.WPF.Services;
|
||||
|
||||
public class DialogService :IDialogService
|
||||
namespace DMS.WPF.Services
|
||||
{
|
||||
// private readonly DataServices _dataServices;
|
||||
//
|
||||
// public DialogService(DataServices dataServices)
|
||||
// {
|
||||
// _dataServices = dataServices;
|
||||
// }
|
||||
//
|
||||
// public async Task<Device> ShowAddDeviceDialog()
|
||||
// {
|
||||
// var device = new Device();
|
||||
// DeviceDialogViewModel vm = new DeviceDialogViewModel(device);
|
||||
// vm.Title = "添加设备";
|
||||
// vm.PrimaryButContent = "添加设备";
|
||||
// return await ShowConentDialog(vm,device);
|
||||
// }
|
||||
//
|
||||
// private static async Task<Device> ShowConentDialog(DeviceDialogViewModel viewModel,Device device)
|
||||
// {
|
||||
// var dialog = new DeviceDialog(viewModel);
|
||||
// var res = await dialog.ShowAsync();
|
||||
// if (res == ContentDialogResult.Primary)
|
||||
// {
|
||||
// return device;
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// public async Task<Device> ShowEditDeviceDialog(Device device)
|
||||
// {
|
||||
// DeviceDialogViewModel vm = new DeviceDialogViewModel(device);
|
||||
// vm.Title = "编辑设备";
|
||||
// vm.PrimaryButContent = "编辑设备";
|
||||
// return await ShowConentDialog(vm,device);
|
||||
//
|
||||
// }
|
||||
//
|
||||
// public async Task<Mqtt> ShowAddMqttDialog()
|
||||
// {
|
||||
// var mqtt = new Mqtt();
|
||||
// MqttDialogViewModel vm = new MqttDialogViewModel(mqtt);
|
||||
// vm.Title = "添加MQTT";
|
||||
// vm.PrimaryButContent = "添加MQTT";
|
||||
// return await ShowConentDialog(vm, mqtt);
|
||||
// }
|
||||
//
|
||||
// public async Task<Mqtt> ShowEditMqttDialog(Mqtt mqtt)
|
||||
// {
|
||||
// MqttDialogViewModel vm = new MqttDialogViewModel(mqtt);
|
||||
// vm.Title = "编辑MQTT";
|
||||
// vm.PrimaryButContent = "编辑MQTT";
|
||||
// return await ShowConentDialog(vm, mqtt);
|
||||
// }
|
||||
//
|
||||
// private static async Task<Mqtt> ShowConentDialog(MqttDialogViewModel viewModel, Mqtt mqtt)
|
||||
// {
|
||||
// var dialog = new MqttDialog(viewModel);
|
||||
// var res = await dialog.ShowAsync();
|
||||
// if (res == ContentDialogResult.Primary)
|
||||
// {
|
||||
// return mqtt;
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// public async Task<bool> ShowConfrimeDialog(string title, string message,string buttonText="确认")
|
||||
// {
|
||||
// ConfrimDialogViewModel vm = new ConfrimDialogViewModel();
|
||||
// vm.Title = title;
|
||||
// vm.Message = message;
|
||||
// vm.PrimaryButtonText = buttonText;
|
||||
// var dialog = new ConfirmDialog(vm);
|
||||
// var res = await dialog.ShowAsync();
|
||||
// if (res == ContentDialogResult.Primary)
|
||||
// {
|
||||
// return true;
|
||||
// }
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// public async Task<VariableTable> ShowAddVarTableDialog()
|
||||
// {
|
||||
// VarTableDialogViewModel vm = new();
|
||||
// vm.Title = "添加变量表";
|
||||
// vm.PrimaryButtonText = "添加变量表";
|
||||
// vm.VariableTable = new VariableTable();
|
||||
// var dialog = new VarTableDialog(vm);
|
||||
// var res = await dialog.ShowAsync();
|
||||
// if (res == ContentDialogResult.Primary)
|
||||
// {
|
||||
// return vm.VariableTable;
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// public async Task<VariableTable> ShowEditVarTableDialog(VariableTable variableTable)
|
||||
// {
|
||||
// VarTableDialogViewModel vm = new();
|
||||
// vm.Title = "编辑变量表";
|
||||
// vm.PrimaryButtonText = "编辑变量表";
|
||||
// vm.VariableTable = variableTable;
|
||||
// var dialog = new VarTableDialog(vm);
|
||||
// var res = await dialog.ShowAsync();
|
||||
// if (res == ContentDialogResult.Primary)
|
||||
// {
|
||||
// return vm.VariableTable;
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// public async Task<Variable> ShowAddVarDataDialog()
|
||||
// {
|
||||
// VarDataDialogViewModel vm = new();
|
||||
// vm.Title = "添加变量";
|
||||
// vm.PrimaryButtonText = "添加变量";
|
||||
// vm.Variable = new Variable();
|
||||
// var dialog = new VarDataDialog(vm);
|
||||
// var res = await dialog.ShowAsync();
|
||||
// if (res == ContentDialogResult.Primary)
|
||||
// {
|
||||
// return vm.Variable;
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// public void ShowMessageDialog(string title, string message)
|
||||
// {
|
||||
// MessageBox.Show(message);
|
||||
// }
|
||||
//
|
||||
// public async Task<Variable> ShowEditVarDataDialog(Variable variable)
|
||||
// {
|
||||
// VarDataDialogViewModel vm = new();
|
||||
// vm.Title = "编辑变量";
|
||||
// vm.PrimaryButtonText = "编辑变量";
|
||||
// vm.Variable = variable;
|
||||
// var dialog = new VarDataDialog(vm);
|
||||
// var res = await dialog.ShowAsync();
|
||||
// if (res == ContentDialogResult.Primary)
|
||||
// {
|
||||
// return vm.Variable;
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// public async Task<string> ShowImportExcelDialog()
|
||||
// {
|
||||
// var vm = new ImportExcelDialogViewModel();
|
||||
// var dialog = new ImportExcelDialog(vm);
|
||||
// var result = await dialog.ShowAsync();
|
||||
// if (result == ContentDialogResult.Primary)
|
||||
// {
|
||||
// return vm.FilePath;
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// public ContentDialog ShowProcessingDialog(string title, string message)
|
||||
// {
|
||||
// ProcessingDialogViewModel vm = new ProcessingDialogViewModel();
|
||||
// vm.Title = title;
|
||||
// vm.Message = message;
|
||||
// var dialog = new ProcessingDialog(vm);
|
||||
// _ = dialog.ShowAsync(); // 不await,让它在后台显示
|
||||
// return dialog;
|
||||
// }
|
||||
//
|
||||
// public async Task<PollLevelType?> ShowPollLevelDialog(PollLevelType pollLevelType)
|
||||
// {
|
||||
// var vm = new PollLevelDialogViewModel(pollLevelType);
|
||||
// var dialog = new PollLevelDialog(vm);
|
||||
// var result = await dialog.ShowAsync();
|
||||
// if (result == ContentDialogResult.Primary)
|
||||
// {
|
||||
// return vm.SelectedPollLevelType;
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// public async Task<Mqtt?> ShowMqttSelectionDialog()
|
||||
// {
|
||||
// var vm = new MqttSelectionDialogViewModel(_dataServices);
|
||||
// var dialog = new MqttSelectionDialog(vm);
|
||||
// var result = await dialog.ShowAsync();
|
||||
// return result == ContentDialogResult.Primary ? vm.SelectedMqtt : null;
|
||||
// }
|
||||
//
|
||||
// public async Task<List<Variable>> ShowOpcUaImportDialog(string endpointUrl)
|
||||
// {
|
||||
// var vm= new OpcUaImportDialogViewModel();
|
||||
// vm.EndpointUrl = endpointUrl;
|
||||
// var dialog = new OpcUaImportDialog(vm);
|
||||
// var result = await dialog.ShowAsync();
|
||||
// return result == ContentDialogResult.Primary ? vm.GetSelectedVariables().ToList() : null;
|
||||
// }
|
||||
//
|
||||
// public async Task<OpcUaUpdateType?> ShowOpcUaUpdateTypeDialog()
|
||||
// {
|
||||
// var vm = new OpcUaUpdateTypeDialogViewModel();
|
||||
// var dialog = new OpcUaUpdateTypeDialog(vm);
|
||||
// var result = await dialog.ShowAsync();
|
||||
// if (result == ContentDialogResult.Primary)
|
||||
// {
|
||||
// return vm.SelectedUpdateType;
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// public async Task<bool?> ShowIsActiveDialog(bool currentIsActive)
|
||||
// {
|
||||
// var vm = new IsActiveDialogViewModel(currentIsActive);
|
||||
// var dialog = new IsActiveDialog(vm);
|
||||
// var result = await dialog.ShowAsync();
|
||||
// if (result == ContentDialogResult.Primary)
|
||||
// {
|
||||
// return vm.SelectedIsActive;
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// public async Task ShowImportResultDialog(List<string> importedVariables, List<string> existingVariables)
|
||||
// {
|
||||
// var vm = new ImportResultDialogViewModel(importedVariables, existingVariables);
|
||||
// var dialog = new ImportResultDialog(vm);
|
||||
// await dialog.ShowAsync();
|
||||
// }
|
||||
//
|
||||
// public async Task<string?> ShowMqttAliasDialog(string variableName, string mqttServerName)
|
||||
// {
|
||||
// var vm = new MqttAliasDialogViewModel(variableName, mqttServerName);
|
||||
// var dialog = new MqttAliasDialog(vm);
|
||||
// var result = await dialog.ShowAsync();
|
||||
// if (result == ContentDialogResult.Primary)
|
||||
// {
|
||||
// return vm.MqttAlias;
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// public async Task<List<VariableMqtt>> ShowMqttAliasBatchEditDialog(List<Variable> selectedVariables, Mqtt selectedMqtt)
|
||||
// {
|
||||
// var vm = new MqttAliasBatchEditDialogViewModel(selectedVariables, selectedMqtt);
|
||||
// var dialog = new MqttAliasBatchEditDialog(vm);
|
||||
// var result = await dialog.ShowAsync();
|
||||
// if (result == ContentDialogResult.Primary)
|
||||
// {
|
||||
// return vm.VariablesToEdit.ToList();
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
public class DialogService : IDialogService
|
||||
{
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
private static readonly Dictionary<Type, Type> _viewModelViewMap = new Dictionary<Type, Type>
|
||||
{
|
||||
{ typeof(DeviceDialogViewModel), typeof(DeviceDialog) },
|
||||
// { typeof(MqttDialogViewModel), typeof(MqttDialog) }, // Add other mappings here
|
||||
// ... other dialogs
|
||||
};
|
||||
|
||||
public DialogService(IServiceProvider serviceProvider)
|
||||
{
|
||||
_serviceProvider = serviceProvider;
|
||||
}
|
||||
|
||||
public async Task<TResult> ShowDialogAsync<TResult>(DialogViewModelBase<TResult> viewModel)
|
||||
{
|
||||
if (_viewModelViewMap.TryGetValue(viewModel.GetType(), out var viewType))
|
||||
{
|
||||
var tcs = new TaskCompletionSource<TResult>();
|
||||
|
||||
var dialog = (ContentDialog)_serviceProvider.GetService(viewType);
|
||||
if (dialog == null)
|
||||
{
|
||||
// If not registered in DI, create an instance directly
|
||||
dialog = (ContentDialog)Activator.CreateInstance(viewType);
|
||||
}
|
||||
|
||||
dialog.DataContext = viewModel;
|
||||
|
||||
Func<TResult, Task> closeHandler = null;
|
||||
closeHandler = async (result) =>
|
||||
{
|
||||
viewModel.CloseRequested -= closeHandler;
|
||||
dialog.Hide();
|
||||
tcs.SetResult(result);
|
||||
};
|
||||
|
||||
viewModel.CloseRequested += closeHandler;
|
||||
|
||||
_ = dialog.ShowAsync();
|
||||
|
||||
return await tcs.Task;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ArgumentException($"No view registered for view model {viewModel.GetType().Name}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,31 +1,10 @@
|
||||
using DMS.Core.Enums;
|
||||
using iNKORE.UI.WPF.Modern.Controls;
|
||||
using DMS.WPF.ViewModels.Dialogs;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DMS.Services;
|
||||
|
||||
public interface IDialogService
|
||||
namespace DMS.WPF.Services
|
||||
{
|
||||
// Task<Device> ShowAddDeviceDialog();
|
||||
// Task<Device> ShowEditDeviceDialog(Device device);
|
||||
// Task<Mqtt> ShowAddMqttDialog();
|
||||
// Task<Mqtt> ShowEditMqttDialog(Mqtt mqtt);
|
||||
// Task<bool> ShowConfrimeDialog(string title, string message,string buttonText="确认");
|
||||
//
|
||||
// Task<VariableTable> ShowAddVarTableDialog();
|
||||
// Task<VariableTable> ShowEditVarTableDialog(VariableTable variableTable);
|
||||
//
|
||||
// Task<Variable> ShowAddVarDataDialog();
|
||||
//
|
||||
// void ShowMessageDialog(string title, string message);
|
||||
// Task<Variable> ShowEditVarDataDialog(Variable variable);
|
||||
// Task<string> ShowImportExcelDialog();
|
||||
// ContentDialog ShowProcessingDialog(string title, string message);
|
||||
// Task<PollLevelType?> ShowPollLevelDialog(PollLevelType pollLevelType);
|
||||
// Task<Mqtt?> ShowMqttSelectionDialog();
|
||||
// Task<List<Variable>> ShowOpcUaImportDialog(string endpointUrl);
|
||||
// Task<OpcUaUpdateType?> ShowOpcUaUpdateTypeDialog();
|
||||
// Task<bool?> ShowIsActiveDialog(bool currentIsActive);
|
||||
// Task ShowImportResultDialog(List<string> importedVariables, List<string> existingVariables);
|
||||
// Task<string?> ShowMqttAliasDialog(string variableName, string mqttServerName);
|
||||
// Task<List<VariableMqtt>> ShowMqttAliasBatchEditDialog(List<Variable> selectedVariables, Mqtt selectedMqtt);
|
||||
public interface IDialogService
|
||||
{
|
||||
Task<TResult> ShowDialogAsync<TResult>(DialogViewModelBase<TResult> viewModel);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user