Ejemplo n.º 1
0
        /// <summary>
        /// Enqueues a notification. If a notification with the same Id exists,
        /// replace the existing notification.
        /// </summary>
        /// <param name="toastNotification">The <see cref="ToastNotificationBase"/> to enqueue or update.</param>
        public void Enqueue(ToastNotificationBase toastNotification)
        {
            // If the toastNotification is on screen, replace datacontext
            if (CurrentNotification != null && CurrentNotification.Id == toastNotification.Id)
            {
                SwipeCurrentNotification(toastNotification);
                return;
            }


            // else-if notification is on queue, replace existing instance
            if (_notificationsQueue.Any(notification => notification.Id == toastNotification.Id && notification.Id != null))
            {
                InternalReplaceQueueItem(toastNotification);
            }
            else
            {
                // else add to queue
                InternalAddToQueue(toastNotification);
            }

            if (CurrentNotification == null)
            {
                ShowNextNotification();
            }
        }
Ejemplo n.º 2
0
 private void InternalAddToQueue(ToastNotificationBase toastNotification)
 {
     lock (_notificationQueueLock)
     {
         _notificationsQueue.Add(toastNotification);
     }
 }
Ejemplo n.º 3
0
 private void SwipeCurrentNotification(ToastNotificationBase toastNotification)
 {
     lock (_notificationQueueLock)
     {
         CurrentNotification.AbortNotification();
         CurrentNotification.CompleteToast(DismissStatus.Dismissed, notifyManager: false);
         _notificationsQueue.Remove(CurrentNotification);
         CurrentNotification = toastNotification;
         CurrentNotification.Show(this);
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Removes a notification from the queue.
        /// </summary>
        /// <param name="toastNotification">The <see cref="ToastNotificationBase"/> to remove.</param>
        public void Dequeue(ToastNotificationBase toastNotification)
        {
            if (CurrentNotification == toastNotification)
            {
                toastNotification.CompleteToast(DismissStatus.InternalDismissed);
            }

            lock (_notificationQueueLock)
            {
                _notificationsQueue.Remove(toastNotification);
            }
        }
Ejemplo n.º 5
0
        private void ShowNextNotification()
        {
            lock (_notificationQueueLock)
            {
                CurrentNotification = _notificationsQueue.FirstOrDefault();

                if (CurrentNotification == null)
                {
                    return;
                }

                CurrentNotification.Show(this);
            }
        }
Ejemplo n.º 6
0
        internal void RemoveNotificationFromVisualTree(ToastNotificationBase toastNotificationBase)
        {
            if (toastNotificationBase == null)
            {
                throw new ArgumentNullException("toastNotificationBase");
            }

            if (toastNotificationBase.ToastControlMainBorder == null)
            {
                throw new ArgumentNullException("toastNotificationBase", "ToastNotificationBase object must contain a ToastControlMainBorder");
            }

            RootGrid.Children.Remove(toastNotificationBase.ToastControlMainBorder);
        }
Ejemplo n.º 7
0
        private void InternalReplaceQueueItem(ToastNotificationBase toastNotification)
        {
            lock (_notificationQueueLock)
            {
                ToastNotificationBase actualNotification = _notificationsQueue.FirstOrDefault(notification => notification.Id == toastNotification.Id && notification.Id != null);
                if (actualNotification == null)
                {
                    throw new ArgumentNullException("actualNotification");
                }

                actualNotification.CompleteToast(dismissStatus: DismissStatus.InternalDismissed);

                int actualNotificationIndex = _notificationsQueue.IndexOf(actualNotification);
                _notificationsQueue.Remove(actualNotification);
                _notificationsQueue.Insert(actualNotificationIndex, toastNotification);
            }
        }
Ejemplo n.º 8
0
 public void CompleteToast(ToastNotificationBase toastNotificationBase)
 {
     CurrentNotification = null;
     Dequeue(toastNotificationBase);
     ShowNextNotification();
 }