示例#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();
            }
        }
示例#2
0
 private void InternalAddToQueue(ToastNotificationBase toastNotification)
 {
     lock (_notificationQueueLock)
     {
         _notificationsQueue.Add(toastNotification);
     }
 }
示例#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);
     }
 }
示例#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);
            }
        }
示例#5
0
        private void ShowNextNotification()
        {
            lock (_notificationQueueLock)
            {
                CurrentNotification = _notificationsQueue.FirstOrDefault();

                if (CurrentNotification == null)
                {
                    return;
                }

                CurrentNotification.Show(this);
            }
        }
示例#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);
        }
示例#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);
            }
        }
示例#8
0
 public void CompleteToast(ToastNotificationBase toastNotificationBase)
 {
     CurrentNotification = null;
     Dequeue(toastNotificationBase);
     ShowNextNotification();
 }