예제 #1
0
        public static Uri GetImageFileUri(this Countdown countdown)
        {
            var imageUri = countdown.HasImage ? new Uri("ms-appdata:///local/" + countdown.Guid) : null;

            return(imageUri);
        }
예제 #2
0
        public void RefreshCountdown(Countdown countdown)
        {
            SelectedCountdown = countdownCollection.RefreshCountdown(countdown);

            UpdateCountdownsEmpty();
        }
예제 #3
0
        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);
        }
예제 #4
0
        public async Task <Countdown> SaveCountdown(int countdownId, string name, DateTime dateTime, bool isRecurrent, byte[] imageData,
                                                    bool finishedNotification, bool pinnedToStart)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                name = "Countdown";
            }

            using (var database = new CountdownContext())
            {
                var countdown = database.Countdowns.SingleOrDefault(x => x.Id == countdownId);
                if (countdown == null)
                {
                    countdown = new Countdown
                    {
                        Created = DateTime.Now,
                        Guid    = Guid.NewGuid().ToString()
                    };

                    database.Countdowns.Add(countdown);
                }
                else
                {
                    if (imageData == null && countdown.Name == name &&
                        countdown.Date == dateTime && countdown.IsRecurrent == isRecurrent &&
                        countdown.FinishedNotification == finishedNotification && countdown.PinnedToStart == pinnedToStart)
                    {
                        return(countdown);
                    }
                }

                countdown.Name                 = name;
                countdown.Date                 = dateTime;
                countdown.IsRecurrent          = isRecurrent;
                countdown.FinishedNotification = finishedNotification;
                countdown.PinnedToStart        = pinnedToStart;

                if (imageData != null)
                {
                    if (imageData.Length > 0)
                    {
                        countdown.ImageData = imageData;
                        countdown.HasImage  = true;

                        await countdown.CreateImageFile();
                    }
                    else if (countdown.HasImage)
                    {
                        countdown.ImageData = null;
                        countdown.HasImage  = false;

                        await countdown.DeleteImageFile();
                    }
                }

                if (countdown.PinnedToStart)
                {
                    countdown.PinnedToStart = await TileManager.RefreshCountdown(countdown);
                }
                else
                {
                    await TileManager.UnpinCountdown(countdown);
                }

                if (countdown.FinishedNotification)
                {
                    countdown.FinishedNotification = NotificationManager.RefreshCountdown(countdown);
                }
                else
                {
                    NotificationManager.RemoveCountdown(countdown);
                }

                await database.SaveChangesAsync();

                return(countdown);
            }
        }