public WpfPredefinedToastNotification(WpfPredefinedToastNotificationContent content, CustomNotifier notifier)
 {
     this.toast    = new CustomNotification(content.ViewModel, notifier);
     this.content  = content;
     this.notifier = notifier;
     this.notifier.ContentTemplate = NotificationServiceTemplatesHelper.PredefinedToastTemplate;
 }
        internal void Hide(CustomNotification toast)
        {
            ToastInfo info = toastsQueue.FirstOrDefault(i => i.toast == toast);

            if (info != null)
            {
                toastsQueue.Remove(info);
                info.source.SetResult(NotificationResult.ApplicationHidden);
                return;
            }
            RemoveVisibleToast(toast, NotificationResult.ApplicationHidden);
            ShowNext();
        }
        void RemoveVisibleToast(CustomNotification toast, NotificationResult result)
        {
            ToastInfo info = GetVisibleToastInfo(toast);

            if (info == null)
            {
                return;
            }
            info.win.Close();
            info.timer.Stop();
            positioner.Remove(info);
            info.source.SetResult(result);
        }
        public Task <NotificationResult> ShowAsync(CustomNotification toast, int msDuration = 3000)
        {
            var info = new ToastInfo {
                toast = toast,
                timer = new Timer()
                {
                    Interval = msDuration
                },
                source = new TaskCompletionSource <NotificationResult>()
            };

            toastsQueue.Add(info);
            ShowNext();
            return(info.source.Task);
        }
        public void ResultsTest() {
            CustomNotification toast;
            Task<NotificationResult> task;
            var notifier = new CustomNotifier();

            toast = new CustomNotification(null, notifier);
            task = notifier.ShowAsync(toast, 1);
            WaitWithDispatcher(task);
            Assert.AreEqual(NotificationResult.TimedOut, task.Result);

            toast = new CustomNotification(null, notifier);
            task = notifier.ShowAsync(toast, 1);
            toast.Activate();
            WaitWithDispatcher(task);
            Assert.AreEqual(NotificationResult.Activated, task.Result);

            toast = new CustomNotification(null, notifier);
            task = notifier.ShowAsync(toast, 1);
            toast.Dismiss();
            WaitWithDispatcher(task);
            Assert.AreEqual(NotificationResult.UserCanceled, task.Result);

            toast = new CustomNotification(null, notifier);
            task = notifier.ShowAsync(toast, 1);
            toast.Hide();
            WaitWithDispatcher(task);
            Assert.AreEqual(NotificationResult.ApplicationHidden, task.Result);

            var tasks = Enumerable.Range(0, 10).Select(_ => notifier.ShowAsync(new CustomNotification(null, notifier), 1)).ToList();
            tasks.ToList().ForEach(WaitWithDispatcher);
            tasks.ToList().ForEach(t => Assert.AreEqual(NotificationResult.TimedOut, t.Result));
        }
 public MvvmCustomNotification(object viewModel, CustomNotifier notifier, int duration) {
     this.notifier = notifier;
     this.duration = duration;
     this.notification = new CustomNotification(viewModel, notifier);
 }
 internal void ResetTimer(CustomNotification toast)
 {
     GetVisibleToastInfo(toast).Do(t => t.timer.Start());
 }
 internal void StopTimer(CustomNotification toast)
 {
     GetVisibleToastInfo(toast).Do(t => t.timer.Stop());
 }
 private ToastInfo GetVisibleToastInfo(CustomNotification toast)
 {
     return(positioner.Items.FirstOrDefault(t => t != null && t.toast == toast));
 }
Ejemplo n.º 10
0
 public void CustomNotificationTemplateSelectorTest() {
     var customNotifier = new CustomNotifier(new TestScreen { bounds = new Rect(0, 0, 1000, 500) });
     var selector = new TestTemplateSelector();
     customNotifier.ContentTemplateSelector = selector;
     var toast = new CustomNotification(null, customNotifier);
     WaitWithDispatcher(customNotifier.ShowAsync(toast, 1));
     Assert.IsTrue(selector.Called);
 }
 internal void TimeOut(CustomNotification toast)
 {
     RemoveVisibleToast(toast, NotificationResult.TimedOut);
     ShowNext();
 }
 internal void Dismiss(CustomNotification toast)
 {
     RemoveVisibleToast(toast, NotificationResult.UserCanceled);
     ShowNext();
 }
 internal void Activate(CustomNotification toast)
 {
     RemoveVisibleToast(toast, NotificationResult.Activated);
     ShowNext();
 }
 public WpfPredefinedToastNotification(WpfPredefinedToastNotificationContent content, CustomNotifier notifier) {
     this.toast = new CustomNotification(content.ViewModel, notifier);
     this.content = content;
     this.notifier = notifier;
     this.notifier.ContentTemplate = NotificationServiceTemplatesHelper.PredefinedToastTemplate;
 }
        public void UpdatingPositionerTest() {
            CustomNotification toast;
            Task<NotificationResult> task;
            var notifier = new CustomNotifier();
            var tasks = Enumerable.Range(0, 5).Select(_ => notifier.ShowAsync(new CustomNotification(null, notifier), 1)).ToList();
            tasks.ToList().ForEach(WaitWithDispatcher);
            tasks.ToList().ForEach(t => Assert.AreEqual(NotificationResult.TimedOut, t.Result));

            toast = new CustomNotification(null, notifier);
            task = notifier.ShowAsync(toast, 1);
            notifier.UpdatePositioner(NotificationPosition.TopRight, 2);
            WaitWithDispatcher(task);
            Assert.AreEqual(NotificationResult.TimedOut, task.Result);
            tasks = Enumerable.Range(0, 10).Select(_ => notifier.ShowAsync(new CustomNotification(null, notifier), 1)).ToList();
            notifier.UpdatePositioner(NotificationPosition.TopRight, 2);
            tasks.ToList().ForEach(WaitWithDispatcher);
            tasks.ToList().ForEach(t => Assert.AreEqual(NotificationResult.TimedOut, t.Result));
        }
        public void UpdatePositionerTest() {
            var testScreen = new TestScreen { bounds = new System.Drawing.Rectangle(0, 0, 800, 600) };
            var notifier = new CustomNotifier(testScreen);
            var pos = CustomNotifier.positioner;

            var toast = new CustomNotification(null, notifier);
            var task = notifier.ShowAsync(toast, 1);
            var p1 = CustomNotifier.positioner.GetItemPosition(CustomNotifier.positioner.Items[0]);
            Assert.AreEqual(415, p1.X);
            Assert.AreEqual(20, p1.Y);

            notifier.UpdatePositioner(NotificationPosition.BottomRight, 3);
            p1 = CustomNotifier.positioner.GetItemPosition(CustomNotifier.positioner.Items[0]);
            Assert.AreEqual(415, p1.X);
            Assert.AreEqual(490, p1.Y);

            WaitWithDispatcher(task);
        }
Ejemplo n.º 17
0
 public void ResettingTimerOfHiddenNotificationTest() {
     var customNotifier = new CustomNotifier(new TestScreen());
     var toast = new CustomNotification(null, customNotifier);
     customNotifier.ShowAsync(toast);
     customNotifier.Hide(toast);
     customNotifier.ResetTimer(toast);
     customNotifier.StopTimer(toast);
 }