private static void UpdateNotification(TileUpdater updater, Countdown countdown, DateTime now) { var name = countdown.Name; var imageUri = countdown.GetImageFileUri(); var daysRemaining = countdown.GetDaysRemaining(now); var content = CreateTileContent(name, imageUri, daysRemaining); var notification = new TileNotification(content); updater.Update(notification); }
private static void UpdateScheduledNotifications(TileUpdater updater, Countdown countdown, DateTime now) { var start = now.Date + countdown.Date.TimeOfDay; if (start < now) { start = start.AddDays(1); } var scheduledNotifications = updater.GetScheduledTileNotifications(); if (scheduledNotifications.Count > 0) { var latest = scheduledNotifications.Max(x => x.DeliveryTime.DateTime); if (latest > start) { start = latest; } } var name = countdown.Name; var imageUri = countdown.GetImageFileUri(); var diff = (start.Date - now.Date).TotalDays; if (diff < MaxScheduledNotifications) { var end = start.AddDays(MaxScheduledNotifications - diff); for (var plan = start; plan <= end; plan = plan.AddDays(1)) { var daysRemaining = countdown.GetDaysRemaining(plan); var content = CreateTileContent(name, imageUri, daysRemaining); var notification = new ScheduledTileNotification(content, plan); updater.AddToSchedule(notification); } } }
private static bool UpdateNotification(ToastNotifier notifier, string notificationId, Countdown countdown) { var now = DateTime.Now; var schedule = CountdownCalculator.GetSchedule(countdown, now); var date = schedule.NextCycle; var content = CreateNotificationContent(countdown.Name, countdown.GetImageFileUri(), countdown.Guid); var notification = new ScheduledToastNotification(content, new DateTimeOffset(date)) { Id = notificationId }; if (notification.DeliveryTime > DateTime.Now) { notifier.AddToSchedule(notification); return(true); } return(false); }