Example #1
0
        public virtual async Task AddLocalNotification(Notification notification)
        {
            notification.Id = Guid.NewGuid().ToString();

            _allLocalNotifications.Add(notification);

            lock (_toastLock)
                _localToastNotifications.Add(notification);

            new Timer(s => DismissToastNotification(notification), null, DefaultToastPopTimerPeriod, Timeout.Infinite);

            NotificationsAdded?.Invoke(this, new NotificationsEventArgs(notification));
            ToastNotificationsAdded?.Invoke(this, new NotificationsEventArgs(notification));
        }
Example #2
0
        public virtual async Task AddOrUpdateNotification(Notification notification)
        {
            if (_surpressedNotifications.Contains(notification.Id))
            {
                return;
            }

            Notification existing = null;
            bool         isNew    = false;

            lock (_lock)
            {
                existing = _allRemoteNotifications.FirstOrDefault(x => x.Id == notification.Id);
                isNew    = existing == null;

                if (isNew)
                {
                    _allRemoteNotifications.Add(notification);

                    lock (_toastLock)
                        _toastNotifications.Add(notification);

                    new Timer(s => DismissToastNotification(notification), null, DefaultToastPopTimerPeriod, Timeout.Infinite);
                }
                else
                {
                    existing.Description         = notification.Description;
                    existing.ActionLinks         = notification.ActionLinks;
                    existing.ProgressPercent     = notification.ProgressPercent;
                    existing.ProgressDescription = notification.ProgressDescription;
                    existing.Read       = existing.Read || notification.Read;
                    existing.Severity   = notification.Severity;
                    existing.Title      = notification.Title;
                    existing.CreatedUtc = notification.CreatedUtc;
                    existing.UpdatedUtc = notification.UpdatedUtc;
                }
            }

            if (isNew)
            {
                NotificationsAdded?.Invoke(this, new NotificationsEventArgs(notification));
                ToastNotificationsAdded?.Invoke(this, new NotificationsEventArgs(notification));
            }
            else
            {
                NotificationsUpdated?.Invoke(this, new NotificationsEventArgs(existing));
            }
        }