コード例 #1
0
        public Task <NotificationResult> ShowAsync(out ToastId toastId, CancellationToken cancellationToken)
        {
            var tcs = new TaskCompletionSource <NotificationResult>();
            var tn  = new ToastNotification(xmlDocument);

            tn.Tag = string.IsNullOrEmpty(notificationBuilder.Tag) ? Guid.NewGuid().ToString() : notificationBuilder.Tag;
            if (string.IsNullOrEmpty(notificationBuilder.Group) == false)
            {
                tn.Group = notificationBuilder.Group;
            }
            if (string.IsNullOrEmpty(notificationBuilder.RemoteId) == false)
            {
                tn.RemoteId = notificationBuilder.RemoteId;
            }
            tn.Activated += (o, e) => tcs.TrySetResult(NotificationResult.Activated);
            tn.Dismissed += (o, e) => tcs.TrySetResult(ToNotificationResult(e.Reason));
            tn.Failed    += (o, e) => tcs.TrySetException(new NotificationException(e.ErrorCode.Message, e.ErrorCode));
            ToastNotificationManager.CreateToastNotifier().Show(tn);
            toastId = ToastId.FromNotification(tn);

            if (cancellationToken.CanBeCanceled)
            {
                return(tcs.WatchCancellationAsync(cancellationToken, () => ToastNotificationManager.History.Remove(tn.Tag)));
            }
            return(tcs.Task);
        }
コード例 #2
0
        public ScheduledToastCancellation(ScheduledToastNotification toastNotification)
        {
            this.toastNotifier     = ToastNotificationManager.CreateToastNotifier();
            this.toastNotification = toastNotification;
            ToastId = ToastId.FromNotification(toastNotification);

            toastNotifier.AddToSchedule(toastNotification);
        }
コード例 #3
0
        public void FromScheduledToastNotification()
        {
            var tn = new ScheduledToastNotification(new XmlDocument(), DateTimeOffset.Now + TimeSpan.FromDays(1))
            {
                Tag   = Guid.NewGuid().ToString(),
                Group = Guid.NewGuid().ToString(),
            };

            var toastId = ToastId.FromNotification(tn);

            Assert.Equal(tn.Tag, toastId.Tag);
            Assert.Equal(tn.Group, toastId.Group);
        }
コード例 #4
0
        public void FromToastNotification()
        {
            var tn = new ToastNotification(new XmlDocument())
            {
                Tag   = Guid.NewGuid().ToString(),
                Group = Guid.NewGuid().ToString(),
            };

            var toastId = ToastId.FromNotification(tn);

            Assert.Equal(tn.Tag, toastId.Tag);
            Assert.Equal(tn.Group, toastId.Group);
        }