Exemple #1
0
        public async Task <ScheduledToastNotification> AddBreakFinishedToastNotificationScheduleAsync(DateTime time, string audioUri, bool isRemoveOthers = true)
        {
            if (ApiInformation.IsTypePresent("Windows.ApplicationModel.Background.ToastNotificationActionTrigger") == false)
            {
                return(null);
            }
            if (time < DateTime.Now)
            {
                return(null);
            }

            if (isRemoveOthers)
            {
                await RemoveBreakFinishedToastNotificationScheduleAsync();
            }

            var toastBuilder = CreatePomodoroToastBuilder();

            if (string.IsNullOrWhiteSpace(audioUri) == false)
            {
                toastBuilder.AddAudio(new Uri(audioUri));
            }

            XmlDocument xml = null;
            ScheduledToastNotification toast;

            try
            {
                xml   = toastBuilder.GetXml();
                toast = new ScheduledToastNotification(xml, time)
                {
                    Tag            = BreakTag,
                    Group          = ToastGroup,
                    ExpirationTime = time.AddHours(1),
                    Id             = _id++.ToString()
                };
                var toastNotifier = await ToastNotificationToolkit.CreateToastNotifierAsync();

                toastNotifier.AddToSchedule(toast);
                Debug.WriteLine("add break:" + toast.Id);
            }
            catch (Exception ex)
            {
                var properties = new Dictionary <string, string>
                {
                    { "xml", xml.GetXml() },
                    { "time", time.ToString() },
                    { "now", DateTime.Now.ToString() },
                    { "utc_now", DateTimeOffset.UtcNow.ToString() },
                };
                Microsoft.AppCenter.Crashes.Crashes.TrackError(ex, properties);
                throw;
            }
            return(toast);
        }
Exemple #2
0
        public async Task <IEnumerable <string> > RemovePomodoroFinishedToastNotificationScheduleAsync(string id = null)
        {
            if (ApiInformation.IsTypePresent("Windows.ApplicationModel.Background.ToastNotificationActionTrigger") == false)
            {
                return(new List <string>());
            }

            var notifier = await ToastNotificationToolkit.CreateToastNotifierAsync();

            List <string> result = new List <string>();

            foreach (var scheduledToast in notifier.GetScheduledToastNotifications())
            {
                if (scheduledToast.Group == ToastGroup && scheduledToast.Tag == PomodoroTag && (string.IsNullOrWhiteSpace(id) || scheduledToast.Id == id))
                {
                    notifier.RemoveFromSchedule(scheduledToast);
                    result.Add(scheduledToast.Id);
                    Debug.WriteLine("remove pomodoro:" + scheduledToast.Id);
                }
            }

            return(result);
        }