using System; using System.Threading.Tasks; using Localization.Resources.AbpUi; using Microsoft.Extensions.Localization; using Volo.Abp.AspNetCore.Components.WebAssembly; using Volo.Abp.DependencyInjection; namespace Volo.Abp.BlazoriseUI { [Dependency(ReplaceServices = true)] public class BlazoriseUiNotificationService : IUiNotificationService, IScopedDependency { /// /// An event raised after the notification is received. /// public event EventHandler NotificationReceived; private readonly IStringLocalizer localizer; public BlazoriseUiNotificationService( IStringLocalizer localizer) { this.localizer = localizer; } public Task Info(string message, string title = null, Action options = null) { var uiNotificationOptions = CreateDefaultOptions(); options?.Invoke(uiNotificationOptions); NotificationReceived?.Invoke(this, new UiNotificationEventArgs(UiNotificationType.Info, message, title, uiNotificationOptions)); return Task.CompletedTask; } public Task Success(string message, string title = null, Action options = null) { var uiNotificationOptions = CreateDefaultOptions(); options?.Invoke(uiNotificationOptions); NotificationReceived?.Invoke(this, new UiNotificationEventArgs(UiNotificationType.Success, message, title, uiNotificationOptions)); return Task.CompletedTask; } public Task Warn(string message, string title = null, Action options = null) { var uiNotificationOptions = CreateDefaultOptions(); options?.Invoke(uiNotificationOptions); NotificationReceived?.Invoke(this, new UiNotificationEventArgs(UiNotificationType.Warning, message, title, uiNotificationOptions)); return Task.CompletedTask; } public Task Error(string message, string title = null, Action options = null) { var uiNotificationOptions = CreateDefaultOptions(); options?.Invoke(uiNotificationOptions); NotificationReceived?.Invoke(this, new UiNotificationEventArgs(UiNotificationType.Error, message, title, uiNotificationOptions)); return Task.CompletedTask; } protected virtual UiNotificationOptions CreateDefaultOptions() { return new UiNotificationOptions { }; } } }