将NotificationService抽取成接口,并将所有使用NotificationService全部替换为接口INotificationService

This commit is contained in:
2025-09-04 19:59:35 +08:00
parent bb650e2682
commit 9d446c370e
12 changed files with 95 additions and 31 deletions

View File

@@ -27,10 +27,10 @@ public partial class DeviceDetailViewModel : ViewModelBase, INavigatable
[ObservableProperty]
private VariableTableItemViewModel _selectedVariableTable;
private readonly NotificationService _notificationService;
private readonly INotificationService _notificationService;
public DeviceDetailViewModel(IMapper mapper, IDialogService dialogService, INavigationService navigationService,
DataServices dataServices, NotificationService notificationService)
DataServices dataServices, INotificationService notificationService)
{
_mapper = mapper;
_dialogService = dialogService;

View File

@@ -38,7 +38,7 @@ public partial class DevicesViewModel : ViewModelBase, INavigatable
[ObservableProperty]
private DeviceItemViewModel _selectedDevice;
private readonly NotificationService _notificationService;
private readonly INotificationService _notificationService;
/// <summary>
/// 初始化 <see cref="DevicesViewModel"/> 类的新实例。
@@ -49,7 +49,7 @@ public partial class DevicesViewModel : ViewModelBase, INavigatable
public DevicesViewModel(IMapper mapper,
IDialogService dialogService, INavigationService navigationService,
DataServices dataServices, IDeviceAppService deviceAppService,
NotificationService notificationService)
INotificationService notificationService)
{
_mapper = mapper;
_dialogService = dialogService;

View File

@@ -6,6 +6,7 @@ using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using DMS.Core.Interfaces.Services;
using DMS.Core.Models;
using DMS.WPF.Interfaces;
using DMS.WPF.Services;
using DMS.WPF.ViewModels.Items;
@@ -15,7 +16,7 @@ public partial class ImportExcelDialogViewModel : DialogViewModelBase<List<Varia
{
private readonly IMapper _mapper;
private readonly IExcelService _excelService;
private readonly NotificationService _notificationService;
private readonly INotificationService _notificationService;
[ObservableProperty]
private string? _filePath;
@@ -29,7 +30,7 @@ public partial class ImportExcelDialogViewModel : DialogViewModelBase<List<Varia
[ObservableProperty]
private IList _selectedVariables = new ArrayList();
public ImportExcelDialogViewModel(IMapper mapper,IExcelService excelService, NotificationService notificationService)
public ImportExcelDialogViewModel(IMapper mapper,IExcelService excelService, INotificationService notificationService)
{
_mapper = mapper;
_excelService = excelService;

View File

@@ -6,6 +6,7 @@ using CommunityToolkit.Mvvm.Input;
using DMS.Core.Enums;
using DMS.Infrastructure.Interfaces.Services;
using DMS.Infrastructure.Models;
using DMS.WPF.Interfaces;
using DMS.WPF.Services;
using DMS.WPF.ViewModels.Items;
using Opc.Ua;
@@ -92,7 +93,7 @@ public partial class ImportOpcUaDialogViewModel : DialogViewModelBase<List<Varia
/// <summary>
/// 通知服务实例
/// </summary>
private readonly NotificationService _notificationService;
private readonly INotificationService _notificationService;
/// <summary>
/// 构造函数
@@ -101,7 +102,7 @@ public partial class ImportOpcUaDialogViewModel : DialogViewModelBase<List<Varia
/// <param name="opcUaService">OPC UA服务接口实例</param>
/// <param name="mapper">对象映射器实例</param>
/// <param name="notificationService">通知服务实例</param>
public ImportOpcUaDialogViewModel(IOpcUaService opcUaService, IMapper mapper, NotificationService notificationService)
public ImportOpcUaDialogViewModel(IOpcUaService opcUaService, IMapper mapper, INotificationService notificationService)
{
_opcUaService = opcUaService;
_mapper = mapper;

View File

@@ -20,7 +20,7 @@ namespace DMS.ViewModels
private readonly ILogger<MqttServerDetailViewModel> _logger;
private readonly DataServices _dataServices;
private readonly IDialogService _dialogService;
private readonly NotificationService _notificationService;
private readonly INotificationService _notificationService;
/// <summary>
/// 当前正在编辑的MQTT服务器对象。
@@ -43,7 +43,7 @@ namespace DMS.ViewModels
/// <param name="dialogService">对话框服务。</param>
/// <param name="notificationService">通知服务。</param>
public MqttServerDetailViewModel(ILogger<MqttServerDetailViewModel> logger, DataServices dataServices,
IDialogService dialogService, NotificationService notificationService)
IDialogService dialogService, INotificationService notificationService)
{
_logger = logger;
_dataServices = dataServices;

View File

@@ -5,6 +5,7 @@ using DMS.Application.DTOs;
using DMS.Application.Interfaces;
using DMS.Core.Enums;
using DMS.Core.Models;
using DMS.WPF.Interfaces;
using DMS.WPF.Services;
using DMS.WPF.ViewModels.Dialogs;
using DMS.WPF.ViewModels.Items;
@@ -13,7 +14,6 @@ using ObservableCollections;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using DMS.WPF.Interfaces;
namespace DMS.WPF.ViewModels;
@@ -86,10 +86,10 @@ partial class VariableTableViewModel : ViewModelBase, INavigatable
private readonly ISynchronizedView<VariableItemViewModel, VariableItemViewModel> _synchronizedView;
public NotifyCollectionChangedSynchronizedViewList<VariableItemViewModel> VariableItemListView { get; }
private readonly NotificationService _notificationService;
private readonly INotificationService _notificationService;
public VariableTableViewModel(IMapper mapper, IDialogService dialogService, IVariableAppService variableAppService,
DataServices dataServices, NotificationService notificationService)
DataServices dataServices, INotificationService notificationService)
{
_mapper = mapper;
_dialogService = dialogService;
@@ -198,6 +198,7 @@ partial class VariableTableViewModel : ViewModelBase, INavigatable
// 更新数据库中的变量数据
var updateResult = await _variableAppService.UpdateVariableAsync(_mapper.Map<VariableDto>(editedVariable));
if (updateResult > 0)
{
// 更新当前页面显示的数据:找到原数据在集合中的索引并替换