Exemplo n.º 1
0
        private Task RemoveItem(NotificationConfig option)
        {
            //avoid user do click and option.Duration toggle twice
            if (option.AnimationClass == AnimationType.Enter)
            {
                option.AnimationClass = AnimationType.Leave;
                StateHasChanged();
                option.InvokeOnClose();

                Debug.Assert(option.Placement != null, "option.Placement != null");
                if (_configDict.TryGetValue(option.Placement.Value, out var configList))
                {
                    configList.Remove(option);
                }

                if (!string.IsNullOrWhiteSpace(option.Key))
                {
                    _configKeyDict.TryRemove(option.Key, out var _);
                }

                //when next notification item fade out or add new notice item, item will toggle StateHasChanged
                //StateHasChanged();
            }

            return(Task.CompletedTask);
        }
Exemplo n.º 2
0
 private async Task Remove(NotificationConfig option)
 {
     if (option.Duration > 0)
     {
         await Task.Delay(TimeSpan.FromSeconds(option.Duration.Value));
         await RemoveItem(option);
     }
 }
Exemplo n.º 3
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="config"></param>
 public async Task Warning(NotificationConfig config)
 {
     if (config != null)
     {
         config.NotificationType = NotificationType.Warning;
         await Open(config);
     }
 }
Exemplo n.º 4
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="config"></param>
 public async Task Info(NotificationConfig config)
 {
     if (config != null)
     {
         config.NotificationType = NotificationType.Info;
         await Open(config);
     }
 }
Exemplo n.º 5
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="config"></param>
 public async Task Error(NotificationConfig config)
 {
     if (config != null)
     {
         config.NotificationType = NotificationType.Error;
         await Open(config);
     }
 }
Exemplo n.º 6
0
 /// <summary>
 /// Open a notification box
 /// </summary>
 /// <param name="config"></param>
 public void Open([NotNull] NotificationConfig config)
 {
     if (config == null)
     {
         return;
     }
     OnNotice?.Invoke(config);
 }
Exemplo n.º 7
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="config"></param>
 public void Warning(NotificationConfig config)
 {
     if (config != null)
     {
         config.NotificationType = NotificationType.Warning;
         Open(config);
     }
 }
Exemplo n.º 8
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="config"></param>
 public void Info(NotificationConfig config)
 {
     if (config != null)
     {
         config.NotificationType = NotificationType.Info;
         Open(config);
     }
 }
Exemplo n.º 9
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="config"></param>
 public void Error(NotificationConfig config)
 {
     if (config != null)
     {
         config.NotificationType = NotificationType.Error;
         Open(config);
     }
 }
Exemplo n.º 10
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="config"></param>
 public void Success(NotificationConfig config)
 {
     if (config != null)
     {
         config.NotificationType = NotificationType.Success;
         Open(config);
     }
 }
Exemplo n.º 11
0
        private NotificationConfig ExtendConfig(NotificationConfig config)
        {
            config.Placement ??= _defaultPlacement;
            config.Duration ??= _defaultDuration;
            config.CloseIcon ??= _defaultCloseIcon;

            return(config);
        }
Exemplo n.º 12
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="config"></param>
 public async Task Success(NotificationConfig config)
 {
     if (config != null)
     {
         config.NotificationType = NotificationType.Success;
         await Open(config);
     }
 }
Exemplo n.º 13
0
        /// <summary>
        /// Open a notification box
        /// </summary>
        /// <param name="config"></param>
        public async Task Open([NotNull] NotificationConfig config)
        {
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }
            var task = OnNoticing?.Invoke(config);

            if (task != null)
            {
                await task;
            }
        }
Exemplo n.º 14
0
        private async Task NotifyAsync(NotificationConfig option)
        {
            if (option == null)
            {
                return;
            }
            option = ExtendConfig(option);

            Debug.Assert(option.Placement != null, "option.Placement != null");
            var  placement = option.Placement.Value;
            bool canAdd    = true;

            if (!_configDict.ContainsKey(placement))
            {
                canAdd = _configDict.TryAdd(placement, new List <NotificationConfig>());
            }
            if (canAdd)
            {
                if (!string.IsNullOrWhiteSpace(option.Key))
                {
                    if (_configKeyDict.TryGetValue(option.Key, out var oldConfig))
                    {
                        oldConfig.Message     = option.Message;
                        oldConfig.Description = option.Description;
                        await InvokeAsync(StateHasChanged);

                        return;
                    }
                    canAdd = _configKeyDict.TryAdd(option.Key, option);
                }

                if (canAdd)
                {
                    _configDict[placement].Add(option);
                    await InvokeAsync(StateHasChanged);
                    await Remove(option);
                }
            }
        }
Exemplo n.º 15
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="config"></param>
 public void Warn(NotificationConfig config)
 {
     Warning(config);
 }
Exemplo n.º 16
0
 private async void NotificationService_OnNotice(NotificationConfig e)
 {
     await NotifyAsync(e);
 }
Exemplo n.º 17
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="config"></param>
 public async Task Warn(NotificationConfig config)
 {
     await Warning(config);
 }