Esempio n. 1
0
        /// <summary>
        /// Cancels a scheduled notification with the specified id.
        /// </summary>
        /// <param name="notificationId">The id of the notification to cancel.</param>
        /// <returns>True if the scheduled notification was canceled, otherwise false if the notification was not currently scheduled.</returns>
        public bool Cancel(Guid notificationId)
        {
            ScheduledNotification <TKey> notification = this.repository.DeleteScheduledNotification(notificationId);

            if (notification != null)
            {
                this.eventPublisher.Publish(new ScheduledNotificationCanceled(notification.Notification));
                return(true);
            }

            return(false);
        }
Esempio n. 2
0
        /// <summary>
        /// Schedules a notification for delivery.
        /// </summary>
        /// <param name="account">The account the notification will be sent to.</param>
        /// <param name="notification">A notification to schedule.</param>
        /// <param name="deliveryDateTime">The date and time the notification should be delivered.</param>
        public void Schedule(NotificationAccount <TKey> account, Notification notification, DateTime deliveryDateTime)
        {
            Throw.IfArgumentNull(account, nameof(account));
            Throw.IfArgumentNull(notification, nameof(notification));

            string timeZone =
                string.IsNullOrWhiteSpace(account.TimeZone)
                ? Constants.EasternTimeZone
                : account.TimeZone;

            ScheduledNotification <TKey> scheduledNotification =
                new ScheduledNotification <TKey>(
                    account.AccountId,
                    notification,
                    deliveryDateTime.ToDateTimeOffset(timeZone));

            this.repository.SaveScheduledNotification(scheduledNotification);

            this.eventPublisher.Publish(
                new NotificationScheduled(
                    scheduledNotification.AccountId.ToString(),
                    scheduledNotification.Notification,
                    scheduledNotification.DeliveryDateTime));
        }