将NotificationService抽取成接口,并将所有使用NotificationService全部替换为接口INotificationService
This commit is contained in:
@@ -75,7 +75,7 @@ public partial class App : System.Windows.Application
|
|||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
var notificationService = Host.Services.GetRequiredService<NotificationService>();
|
var notificationService = Host.Services.GetRequiredService<INotificationService>();
|
||||||
notificationService.ShowError($"加载数据时发生错误,如果是连接字符串不正确,可以在设置界面更改:{exception.Message}", exception);
|
notificationService.ShowError($"加载数据时发生错误,如果是连接字符串不正确,可以在设置界面更改:{exception.Message}", exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,7 +109,7 @@ public partial class App : System.Windows.Application
|
|||||||
services.AddSingleton<ILoggerFactory, NLogLoggerFactory>();
|
services.AddSingleton<ILoggerFactory, NLogLoggerFactory>();
|
||||||
//
|
//
|
||||||
services.AddSingleton<GrowlNotificationService>();
|
services.AddSingleton<GrowlNotificationService>();
|
||||||
services.AddSingleton<NotificationService>();
|
services.AddSingleton<INotificationService, NotificationService>();
|
||||||
// services.AddHostedService<S7BackgroundService>();
|
// services.AddHostedService<S7BackgroundService>();
|
||||||
// services.AddHostedService<OpcUaBackgroundService>();
|
// services.AddHostedService<OpcUaBackgroundService>();
|
||||||
// services.AddHostedService<DMS.Infrastructure.Services.MqttBackgroundService>();
|
// services.AddHostedService<DMS.Infrastructure.Services.MqttBackgroundService>();
|
||||||
|
|||||||
@@ -1,7 +1,73 @@
|
|||||||
namespace DMS.WPF.Interfaces;
|
using System;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using DMS.Core.Enums;
|
||||||
|
|
||||||
|
namespace DMS.WPF.Interfaces;
|
||||||
|
|
||||||
public interface INotificationService
|
public interface INotificationService
|
||||||
{
|
{
|
||||||
// void Show(Notification notification);
|
/// <summary>
|
||||||
// void Show(string message, NotificationType type = NotificationType.Info, bool IsGlobal = true);
|
/// 显示一个通用通知消息,并根据通知类型记录日志。支持节流。
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="msg">通知消息内容。</param>
|
||||||
|
/// <param name="notificationType">通知类型(如信息、错误、成功等)。</param>
|
||||||
|
/// <param name="throttle">是否启用通知节流。</param>
|
||||||
|
/// <param name="callerFilePath">自动捕获:调用此方法的源文件完整路径。</param>
|
||||||
|
/// <param name="callerLineNumber">自动捕获:调用此方法的行号。</param>
|
||||||
|
void ShowMessage(string msg, NotificationType notificationType = NotificationType.Info, bool throttle = true,
|
||||||
|
[CallerFilePath] string callerFilePath = "",
|
||||||
|
[CallerLineNumber] int callerLineNumber = 0);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 显示一个错误通知消息,并记录错误日志。支持节流。
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="msg">错误消息内容。</param>
|
||||||
|
/// <param name="exception">可选:要记录的异常对象。</param>
|
||||||
|
/// <param name="throttle">是否启用通知和日志节流。</param>
|
||||||
|
/// <param name="callerFilePath">自动捕获:调用此方法的源文件完整路径。</param>
|
||||||
|
/// <param name="callerMember">自动捕获:调用此方法的成员或属性名称。</param>
|
||||||
|
/// <param name="callerLineNumber">自动捕获:调用此方法的行号。</param>
|
||||||
|
void ShowError(string msg, Exception exception = null, bool throttle = true,
|
||||||
|
[CallerFilePath] string callerFilePath = "",
|
||||||
|
[CallerMemberName] string callerMember = "",
|
||||||
|
[CallerLineNumber] int callerLineNumber = 0);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 显示一个成功通知消息,并记录信息日志。支持节流。
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="msg">成功消息内容。</param>
|
||||||
|
/// <param name="throttle">是否启用通知和日志节流。</param>
|
||||||
|
/// <param name="callerFilePath">自动捕获:调用此方法的源文件完整路径。</param>
|
||||||
|
/// <param name="callerMember">自动捕获:调用此方法的成员或属性名称。</param>
|
||||||
|
/// <param name="callerLineNumber">自动捕获:调用此方法的行号。</param>
|
||||||
|
void ShowSuccess(string msg, bool throttle = true,
|
||||||
|
[CallerFilePath] string callerFilePath = "",
|
||||||
|
[CallerMemberName] string callerMember = "",
|
||||||
|
[CallerLineNumber] int callerLineNumber = 0);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 显示一个信息通知消息,并记录信息日志。支持节流。
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="msg">信息消息内容。</param>
|
||||||
|
/// <param name="throttle">是否启用通知和日志节流。</param>
|
||||||
|
/// <param name="callerFilePath">自动捕获:调用此方法的源文件完整路径。</param>
|
||||||
|
/// <param name="callerMember">自动捕获:调用此方法的成员或属性名称。</param>
|
||||||
|
/// <param name="callerLineNumber">自动捕获:调用此方法的行号。</param>
|
||||||
|
void ShowInfo(string msg, bool throttle = true,
|
||||||
|
[CallerFilePath] string callerFilePath = "",
|
||||||
|
[CallerMemberName] string callerMember = "",
|
||||||
|
[CallerLineNumber] int callerLineNumber = 0);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 显示一个警告通知消息,并记录警告日志。支持节流。
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="msg">警告消息内容。</param>
|
||||||
|
/// <param name="throttle">是否启用通知和日志节流。</param>
|
||||||
|
/// <param name="callerFilePath">自动捕获:调用此方法的源文件完整路径。</param>
|
||||||
|
/// <param name="callerMember">自动捕获:调用此方法的成员或属性名称。</param>
|
||||||
|
/// <param name="callerLineNumber">自动捕获:调用此方法的行号。</param>
|
||||||
|
void ShowWarn(string msg, bool throttle = true,
|
||||||
|
[CallerFilePath] string callerFilePath = "",
|
||||||
|
[CallerMemberName] string callerMember = "",
|
||||||
|
[CallerLineNumber] int callerLineNumber = 0);
|
||||||
}
|
}
|
||||||
@@ -1,16 +1,8 @@
|
|||||||
// 文件: DMS.WPF/Services/NavigationService.cs
|
|
||||||
|
|
||||||
using DMS.ViewModels;
|
using DMS.ViewModels;
|
||||||
|
using DMS.WPF.Interfaces;
|
||||||
using DMS.WPF.ViewModels;
|
using DMS.WPF.ViewModels;
|
||||||
using DMS.WPF.ViewModels.Items;
|
using DMS.WPF.ViewModels.Items;
|
||||||
using DMS.WPF.Views;
|
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Windows;
|
|
||||||
using DMS.WPF.Interfaces;
|
|
||||||
using DMS.WPF.Services;
|
|
||||||
|
|
||||||
namespace DMS.WPF.Services;
|
namespace DMS.WPF.Services;
|
||||||
|
|
||||||
@@ -43,7 +35,7 @@ public class NavigationService : INavigationService
|
|||||||
var viewModel = GetViewModelByKey(menu.TargetViewKey);
|
var viewModel = GetViewModelByKey(menu.TargetViewKey);
|
||||||
if (viewModel == null)
|
if (viewModel == null)
|
||||||
{
|
{
|
||||||
var notificationService = App.Current.Services.GetRequiredService<NotificationService>();
|
var notificationService = App.Current.Services.GetRequiredService<INotificationService>();
|
||||||
notificationService.ShowError($"切换界面失败,没有找到界面:{menu.TargetViewKey}");
|
notificationService.ShowError($"切换界面失败,没有找到界面:{menu.TargetViewKey}");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ using System.Threading;
|
|||||||
using CommunityToolkit.Mvvm.Messaging;
|
using CommunityToolkit.Mvvm.Messaging;
|
||||||
using DMS.Core.Enums;
|
using DMS.Core.Enums;
|
||||||
using DMS.Message;
|
using DMS.Message;
|
||||||
|
using DMS.WPF.Interfaces;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
namespace DMS.WPF.Services;
|
namespace DMS.WPF.Services;
|
||||||
@@ -13,7 +14,7 @@ namespace DMS.WPF.Services;
|
|||||||
/// 通知服务类,用于显示各种类型的通知消息,并集成日志记录功能。
|
/// 通知服务类,用于显示各种类型的通知消息,并集成日志记录功能。
|
||||||
/// 新增了通知节流功能,以防止在短时间内向用户发送大量重复的通知。
|
/// 新增了通知节流功能,以防止在短时间内向用户发送大量重复的通知。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class NotificationService
|
public class NotificationService : INotificationService
|
||||||
{
|
{
|
||||||
private readonly ILogger<NotificationService> _logger;
|
private readonly ILogger<NotificationService> _logger;
|
||||||
|
|
||||||
|
|||||||
@@ -27,10 +27,10 @@ public partial class DeviceDetailViewModel : ViewModelBase, INavigatable
|
|||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
private VariableTableItemViewModel _selectedVariableTable;
|
private VariableTableItemViewModel _selectedVariableTable;
|
||||||
|
|
||||||
private readonly NotificationService _notificationService;
|
private readonly INotificationService _notificationService;
|
||||||
|
|
||||||
public DeviceDetailViewModel(IMapper mapper, IDialogService dialogService, INavigationService navigationService,
|
public DeviceDetailViewModel(IMapper mapper, IDialogService dialogService, INavigationService navigationService,
|
||||||
DataServices dataServices, NotificationService notificationService)
|
DataServices dataServices, INotificationService notificationService)
|
||||||
{
|
{
|
||||||
_mapper = mapper;
|
_mapper = mapper;
|
||||||
_dialogService = dialogService;
|
_dialogService = dialogService;
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ public partial class DevicesViewModel : ViewModelBase, INavigatable
|
|||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
private DeviceItemViewModel _selectedDevice;
|
private DeviceItemViewModel _selectedDevice;
|
||||||
|
|
||||||
private readonly NotificationService _notificationService;
|
private readonly INotificationService _notificationService;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 初始化 <see cref="DevicesViewModel"/> 类的新实例。
|
/// 初始化 <see cref="DevicesViewModel"/> 类的新实例。
|
||||||
@@ -49,7 +49,7 @@ public partial class DevicesViewModel : ViewModelBase, INavigatable
|
|||||||
public DevicesViewModel(IMapper mapper,
|
public DevicesViewModel(IMapper mapper,
|
||||||
IDialogService dialogService, INavigationService navigationService,
|
IDialogService dialogService, INavigationService navigationService,
|
||||||
DataServices dataServices, IDeviceAppService deviceAppService,
|
DataServices dataServices, IDeviceAppService deviceAppService,
|
||||||
NotificationService notificationService)
|
INotificationService notificationService)
|
||||||
{
|
{
|
||||||
_mapper = mapper;
|
_mapper = mapper;
|
||||||
_dialogService = dialogService;
|
_dialogService = dialogService;
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ using CommunityToolkit.Mvvm.ComponentModel;
|
|||||||
using CommunityToolkit.Mvvm.Input;
|
using CommunityToolkit.Mvvm.Input;
|
||||||
using DMS.Core.Interfaces.Services;
|
using DMS.Core.Interfaces.Services;
|
||||||
using DMS.Core.Models;
|
using DMS.Core.Models;
|
||||||
|
using DMS.WPF.Interfaces;
|
||||||
using DMS.WPF.Services;
|
using DMS.WPF.Services;
|
||||||
using DMS.WPF.ViewModels.Items;
|
using DMS.WPF.ViewModels.Items;
|
||||||
|
|
||||||
@@ -15,7 +16,7 @@ public partial class ImportExcelDialogViewModel : DialogViewModelBase<List<Varia
|
|||||||
{
|
{
|
||||||
private readonly IMapper _mapper;
|
private readonly IMapper _mapper;
|
||||||
private readonly IExcelService _excelService;
|
private readonly IExcelService _excelService;
|
||||||
private readonly NotificationService _notificationService;
|
private readonly INotificationService _notificationService;
|
||||||
|
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
private string? _filePath;
|
private string? _filePath;
|
||||||
@@ -29,7 +30,7 @@ public partial class ImportExcelDialogViewModel : DialogViewModelBase<List<Varia
|
|||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
private IList _selectedVariables = new ArrayList();
|
private IList _selectedVariables = new ArrayList();
|
||||||
|
|
||||||
public ImportExcelDialogViewModel(IMapper mapper,IExcelService excelService, NotificationService notificationService)
|
public ImportExcelDialogViewModel(IMapper mapper,IExcelService excelService, INotificationService notificationService)
|
||||||
{
|
{
|
||||||
_mapper = mapper;
|
_mapper = mapper;
|
||||||
_excelService = excelService;
|
_excelService = excelService;
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ using CommunityToolkit.Mvvm.Input;
|
|||||||
using DMS.Core.Enums;
|
using DMS.Core.Enums;
|
||||||
using DMS.Infrastructure.Interfaces.Services;
|
using DMS.Infrastructure.Interfaces.Services;
|
||||||
using DMS.Infrastructure.Models;
|
using DMS.Infrastructure.Models;
|
||||||
|
using DMS.WPF.Interfaces;
|
||||||
using DMS.WPF.Services;
|
using DMS.WPF.Services;
|
||||||
using DMS.WPF.ViewModels.Items;
|
using DMS.WPF.ViewModels.Items;
|
||||||
using Opc.Ua;
|
using Opc.Ua;
|
||||||
@@ -92,7 +93,7 @@ public partial class ImportOpcUaDialogViewModel : DialogViewModelBase<List<Varia
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 通知服务实例
|
/// 通知服务实例
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly NotificationService _notificationService;
|
private readonly INotificationService _notificationService;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 构造函数
|
/// 构造函数
|
||||||
@@ -101,7 +102,7 @@ public partial class ImportOpcUaDialogViewModel : DialogViewModelBase<List<Varia
|
|||||||
/// <param name="opcUaService">OPC UA服务接口实例</param>
|
/// <param name="opcUaService">OPC UA服务接口实例</param>
|
||||||
/// <param name="mapper">对象映射器实例</param>
|
/// <param name="mapper">对象映射器实例</param>
|
||||||
/// <param name="notificationService">通知服务实例</param>
|
/// <param name="notificationService">通知服务实例</param>
|
||||||
public ImportOpcUaDialogViewModel(IOpcUaService opcUaService, IMapper mapper, NotificationService notificationService)
|
public ImportOpcUaDialogViewModel(IOpcUaService opcUaService, IMapper mapper, INotificationService notificationService)
|
||||||
{
|
{
|
||||||
_opcUaService = opcUaService;
|
_opcUaService = opcUaService;
|
||||||
_mapper = mapper;
|
_mapper = mapper;
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ namespace DMS.ViewModels
|
|||||||
private readonly ILogger<MqttServerDetailViewModel> _logger;
|
private readonly ILogger<MqttServerDetailViewModel> _logger;
|
||||||
private readonly DataServices _dataServices;
|
private readonly DataServices _dataServices;
|
||||||
private readonly IDialogService _dialogService;
|
private readonly IDialogService _dialogService;
|
||||||
private readonly NotificationService _notificationService;
|
private readonly INotificationService _notificationService;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 当前正在编辑的MQTT服务器对象。
|
/// 当前正在编辑的MQTT服务器对象。
|
||||||
@@ -43,7 +43,7 @@ namespace DMS.ViewModels
|
|||||||
/// <param name="dialogService">对话框服务。</param>
|
/// <param name="dialogService">对话框服务。</param>
|
||||||
/// <param name="notificationService">通知服务。</param>
|
/// <param name="notificationService">通知服务。</param>
|
||||||
public MqttServerDetailViewModel(ILogger<MqttServerDetailViewModel> logger, DataServices dataServices,
|
public MqttServerDetailViewModel(ILogger<MqttServerDetailViewModel> logger, DataServices dataServices,
|
||||||
IDialogService dialogService, NotificationService notificationService)
|
IDialogService dialogService, INotificationService notificationService)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_dataServices = dataServices;
|
_dataServices = dataServices;
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ using DMS.Application.DTOs;
|
|||||||
using DMS.Application.Interfaces;
|
using DMS.Application.Interfaces;
|
||||||
using DMS.Core.Enums;
|
using DMS.Core.Enums;
|
||||||
using DMS.Core.Models;
|
using DMS.Core.Models;
|
||||||
|
using DMS.WPF.Interfaces;
|
||||||
using DMS.WPF.Services;
|
using DMS.WPF.Services;
|
||||||
using DMS.WPF.ViewModels.Dialogs;
|
using DMS.WPF.ViewModels.Dialogs;
|
||||||
using DMS.WPF.ViewModels.Items;
|
using DMS.WPF.ViewModels.Items;
|
||||||
@@ -13,7 +14,6 @@ using ObservableCollections;
|
|||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using DMS.WPF.Interfaces;
|
|
||||||
|
|
||||||
namespace DMS.WPF.ViewModels;
|
namespace DMS.WPF.ViewModels;
|
||||||
|
|
||||||
@@ -86,10 +86,10 @@ partial class VariableTableViewModel : ViewModelBase, INavigatable
|
|||||||
private readonly ISynchronizedView<VariableItemViewModel, VariableItemViewModel> _synchronizedView;
|
private readonly ISynchronizedView<VariableItemViewModel, VariableItemViewModel> _synchronizedView;
|
||||||
public NotifyCollectionChangedSynchronizedViewList<VariableItemViewModel> VariableItemListView { get; }
|
public NotifyCollectionChangedSynchronizedViewList<VariableItemViewModel> VariableItemListView { get; }
|
||||||
|
|
||||||
private readonly NotificationService _notificationService;
|
private readonly INotificationService _notificationService;
|
||||||
|
|
||||||
public VariableTableViewModel(IMapper mapper, IDialogService dialogService, IVariableAppService variableAppService,
|
public VariableTableViewModel(IMapper mapper, IDialogService dialogService, IVariableAppService variableAppService,
|
||||||
DataServices dataServices, NotificationService notificationService)
|
DataServices dataServices, INotificationService notificationService)
|
||||||
{
|
{
|
||||||
_mapper = mapper;
|
_mapper = mapper;
|
||||||
_dialogService = dialogService;
|
_dialogService = dialogService;
|
||||||
@@ -198,6 +198,7 @@ partial class VariableTableViewModel : ViewModelBase, INavigatable
|
|||||||
// 更新数据库中的变量数据
|
// 更新数据库中的变量数据
|
||||||
var updateResult = await _variableAppService.UpdateVariableAsync(_mapper.Map<VariableDto>(editedVariable));
|
var updateResult = await _variableAppService.UpdateVariableAsync(_mapper.Map<VariableDto>(editedVariable));
|
||||||
|
|
||||||
|
|
||||||
if (updateResult > 0)
|
if (updateResult > 0)
|
||||||
{
|
{
|
||||||
// 更新当前页面显示的数据:找到原数据在集合中的索引并替换
|
// 更新当前页面显示的数据:找到原数据在集合中的索引并替换
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using DMS.Services;
|
using DMS.Services;
|
||||||
using DMS.WPF.Helper;
|
using DMS.WPF.Helper;
|
||||||
|
using DMS.WPF.Interfaces;
|
||||||
using DMS.WPF.Services;
|
using DMS.WPF.Services;
|
||||||
using DMS.WPF.ViewModels.Dialogs;
|
using DMS.WPF.ViewModels.Dialogs;
|
||||||
using DMS.WPF.ViewModels.Items;
|
using DMS.WPF.ViewModels.Items;
|
||||||
@@ -52,7 +53,7 @@ public partial class ImportOpcUaDialog : ContentDialog
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
var notificationService = App.Current.Services.GetRequiredService<NotificationService>();
|
var notificationService = App.Current.Services.GetRequiredService<INotificationService>();
|
||||||
notificationService.ShowError($"选择节点时发生了错误:{ex.Message}");
|
notificationService.ShowError($"选择节点时发生了错误:{ex.Message}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using System.Windows.Controls;
|
|||||||
using System.Windows.Data;
|
using System.Windows.Data;
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
using DMS.WPF.ViewModels;
|
using DMS.WPF.ViewModels;
|
||||||
|
using DMS.WPF.Interfaces;
|
||||||
using DMS.WPF.Services;
|
using DMS.WPF.Services;
|
||||||
using iNKORE.UI.WPF.Modern.Controls;
|
using iNKORE.UI.WPF.Modern.Controls;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
@@ -39,7 +40,7 @@ public partial class VariableTableView : UserControl
|
|||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
var notificationService = App.Current.Services.GetRequiredService<NotificationService>();
|
var notificationService = App.Current.Services.GetRequiredService<INotificationService>();
|
||||||
notificationService.ShowError($"修改变量表启用,停用时发生了错误:{exception.Message}", exception);
|
notificationService.ShowError($"修改变量表启用,停用时发生了错误:{exception.Message}", exception);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user