/// <summary>
        ///     Schedule a notification on the scheduled date.  If there is extra
        ///     notification info then include that in the notification.
        /// </summary>
        /// <param name="scheduledDate">The date and time you want the notification to appear.</param>
        private void ScheduleNotification(DateTime scheduledDate)
        {
            string notificationId;

            // Setup the date and the messages.
            const string title   = "Scheduled Now";
            var          message = $"Created: {DateTime.Now:G}, Scheduled: {scheduledDate:G}";

            // Check if the extra info should be included when sending the notification
            // then schedule the notification.
            if (IncludeExtraInfo)
            {
                var extraInfo = new Dictionary <string, string> {
                    { "ExtraInfoOne", ExtraInfoOne }, { "ExtraInfoTwo", ExtraInfoTwo }
                };
                notificationId = _notificationScheduler.Create(title, message, scheduledDate, extraInfo);
            }
            else
            {
                notificationId = _notificationScheduler.Create(title, message, scheduledDate);
            }

            // Keep track of this scheduled notification.
            ScheduledNotificationRepository.NotificationScheduled(notificationId, title, message, scheduledDate, ExtraInfoOne, ExtraInfoTwo);

            // Add to the list of notifications.
            ScheduledNotifications.Add(new MainPageViewModelScheduledNotification {
                Text = notificationId
            });
        }
        /// <summary>
        ///     When a notification is recieved update the repository and show
        ///     the recieved notification to the user.
        /// </summary>
        /// <param name="notification"></param>
        public void NotificationReceived(Notification notification)
        {
            // Copy the notification values to the view model
            var viewModel = new NotificationRecievedViewModel
            {
                Id      = notification.Id,
                Title   = notification.Title,
                Message = notification.Message
            };

            // Only copy the extra info if it exists.
            if (notification.ExtraInfo.ContainsKey("ExtraInfoOne"))
            {
                viewModel.ExtraInfoOne = notification.ExtraInfo["ExtraInfoOne"];
            }

            if (notification.ExtraInfo.ContainsKey("ExtraInfoTwo"))
            {
                viewModel.ExtraInfoTwo = notification.ExtraInfo["ExtraInfoTwo"];
            }


            // Save the recieved view model.
            ScheduledNotificationRepository.NotificationRecieved(notification.Id, viewModel.Title, viewModel.Message, viewModel.ExtraInfoOne, viewModel.ExtraInfoTwo);


            // Show the notifcation page.
            var notificationPage = new NotificationRecievedPage(viewModel);

            Application.Current.MainPage.Navigation.PushAsync(notificationPage);
        }
Exemple #3
0
        /// <summary>
        ///     Cancels an existing notification.
        /// </summary>
        private void CancelNotification()
        {
            try
            {
                _notificationScheduler.Cancel(Id);

                var canceledTime = DateTime.Now;
                ScheduledNotificationRepository.NotificationCancled(Id, canceledTime);
                CanceledOn = canceledTime.ToString("G");
            }
            catch (Exception ex)
            {
                Application.Current.MainPage.DisplayAlert("Error Trying to Cancel Notification", $"{ex.Message}", "OK");
            }
        }
Exemple #4
0
        /// <summary>
        ///     Creates a new page with the scheduled notification loaded.
        /// </summary>
        /// <param name="scheduledNotificationId"></param>
        public ScheduledNotificationPage(string scheduledNotificationId) : this()
        {
            var scheduledNotification = ScheduledNotificationRepository.FindNotification(scheduledNotificationId);

            BindingContext = new ScheduledNotificationViewModel
            {
                Id = scheduledNotification.Id,
                NumberOfTimesRecieved = scheduledNotification.NumberTimesRecieved,
                CreatedOn             = scheduledNotification.CreatedOn.ToString("G"),
                ScheduledFor          = scheduledNotification.ScheduledFor.ToString("G"),
                RecievedOn            = scheduledNotification.LastRecievedOn?.ToString("G") ?? "",
                ScheduledTitle        = scheduledNotification.ScheduledDetails?.Title ?? "",
                RecievedTitle         = scheduledNotification.RecievedDetails?.Title ?? "",
                ScheduledMessage      = scheduledNotification.ScheduledDetails?.Message ?? "",
                RecivedMessage        = scheduledNotification.RecievedDetails?.Message ?? "",
                ScheduledExtraInfoOne = scheduledNotification.ScheduledDetails?.ExtraInfoOne ?? "",
                RecivedExtraInfoOne   = scheduledNotification.RecievedDetails?.ExtraInfoOne ?? "",
                ScheduledExtraInfoTwo = scheduledNotification.ScheduledDetails?.ExtraInfoTwo ?? "",
                RecivedExtraInfoTwo   = scheduledNotification.RecievedDetails?.ExtraInfoTwo ?? "",
                CanceledOn            = scheduledNotification.CanceledOn?.ToString("G") ?? ""
            };
        }