using System; using System.Diagnostics.CodeAnalysis; using System.Threading.Tasks; namespace AntDesign { /// /// AntNotification Service /// public class NotificationService { internal event Action OnConfiging; internal event Func OnNoticing; internal event Func OnClosing; internal event Action OnDestroying; public void Config(NotificationGlobalConfig config) { OnConfiging?.Invoke(config); } /// /// Open a notification box /// /// public async Task Open([NotNull] NotificationConfig config) { if (config == null) { throw new ArgumentNullException(nameof(config)); } if (OnNoticing != null) { await OnNoticing.Invoke(config); } } #region Api /// /// /// /// public async Task Success(NotificationConfig config) { if (config != null) { config.NotificationType = NotificationType.Success; await Open(config); } } /// /// /// /// public async Task Error(NotificationConfig config) { if (config != null) { config.NotificationType = NotificationType.Error; await Open(config); } } /// /// /// /// public async Task Info(NotificationConfig config) { if (config != null) { config.NotificationType = NotificationType.Info; await Open(config); } } /// /// /// /// public async Task Warning(NotificationConfig config) { if (config != null) { config.NotificationType = NotificationType.Warning; await Open(config); } } /// /// /// /// public async Task Warn(NotificationConfig config) { await Warning(config); } /// /// close notification by key /// /// /// public async Task Close(string key) { if (OnClosing != null) { await OnClosing.Invoke(key); } } /// /// destroy /// public void Destroy() { OnDestroying?.Invoke(); } #endregion } }