internal IEnumerable<TicketPushNotificationItem> ToPushNotificationItems(
            ApplicationPushNotificationSetting appSettings, SubscriberNotificationSetting userSettings)
        {
            var now = DateTimeOffset.Now;
            return userSettings.PushNotificationDestinations.Select(dest =>
            new TicketPushNotificationItem()
                {
                    PushNotificationItem = new PushNotificationItem
                    {
                        ContentSourceId = TicketId,
                        ContentSourceType = "ticket",
                        SubscriberId = SubscriberId,
                        Destination = dest,
                        DestinationId = dest.DestinationId,
                        DeliveryStatus = userSettings.IsEnabled ? (CancelNotification) ? PushNotificationItemStatus.Canceled : PushNotificationItemStatus.Scheduled : PushNotificationItemStatus.Disabled,
                        RetryCount = 0,
                        CreatedDate = now,
                        ScheduledSendDate = CancelNotification ? null : GetSendDate(now, appSettings, userSettings),
                        MessageContent = MessageContent

                    },
                    TicketEvents = CancelNotification ? new Collection<int>() : new Collection<int>(new[] { EventId }),
                    CanceledEvents = CancelNotification ? new Collection<int>(new[] { EventId }) : new Collection<int>()
                }
            ).ToList();
        }
        internal IEnumerable<TicketPushNotificationItem> ToPushNotificationItems(
            ApplicationPushNotificationSetting appSettings, SubscriberNotificationSetting userSettings)
        {
            var now = DateTimeOffset.Now;
            return userSettings.PushNotificationDestinations.Select(dest =>
            new TicketPushNotificationItem()
                {
                    PushNotificationItem = new PushNotificationItem
                    {
                        ContentSourceId = TicketId,
                        ContentSourceType = "ticket",
                        SubscriberId = SubscriberId,
                        Destination = dest,
                        DestinationId = dest.DestinationId,
                        DeliveryStatus = userSettings.IsEnabled ? (CancelNotification) ? PushNotificationItemStatus.Canceled : PushNotificationItemStatus.Scheduled : PushNotificationItemStatus.Disabled,
                        RetryCount = 0,
                        CreatedDate = now,
                        ScheduledSendDate = CancelNotification ? null : GetSendDate(now, appSettings, userSettings),
                        MessageContent = MessageContent

                    },
                    TicketEvents = CancelNotification ? new Collection<int>() : new Collection<int>(new[] { EventId }),
                    CanceledEvents = CancelNotification ? new Collection<int>(new[] { EventId }) : new Collection<int>()
                }
            ).ToList();
        }
 public ActionResult Index(ApplicationPushNotificationSetting settings, string siteRootUrl)
 {
     var dbSetting = NoteContext.TicketDeskPushNotificationSettings;
     if (ModelState.IsValid && TryUpdateModel(dbSetting))
     {
         NoteContext.SaveChanges();
         DomainContext.TicketDeskSettings.ClientSettings.Settings["DefaultSiteRootUrl"] = siteRootUrl.TrimEnd('/');
         DomainContext.SaveChanges();
     }
     ViewBag.CurrentRootUrl = GetCurrentRootUrl();
     ViewBag.SiteRootUrl = GetRootUrlSetting();
     return View(dbSetting);
 }
        private static DateTimeOffset? GetSendDate(DateTimeOffset now, ApplicationPushNotificationSetting appSettings, SubscriberNotificationSetting userNoteSettings)
        {
            DateTimeOffset? send = null;
            if (userNoteSettings.IsEnabled)
            {
                var addMinutes = appSettings.AntiNoiseSettings.IsConsolidationEnabled
                    ? appSettings.AntiNoiseSettings.InitialConsolidationDelayMinutes
                    : 0;
                send = now.AddMinutes(addMinutes);
            }
            return send;

        }
        private static DateTimeOffset? GetSendDate(DateTimeOffset now, ApplicationPushNotificationSetting appSettings, SubscriberNotificationSetting userNoteSettings)
        {
            DateTimeOffset? send = null;
            if (userNoteSettings.IsEnabled)
            {
                var addMinutes = appSettings.AntiNoiseSettings.IsConsolidationEnabled
                    ? appSettings.AntiNoiseSettings.InitialConsolidationDelayMinutes
                    : 0;
                send = now.AddMinutes(addMinutes);
            }
            return send;

        }
 public static IPushNotificationDeliveryProvider CreateDeliveryProviderInstance(ApplicationPushNotificationSetting.PushNotificationDeliveryProviderSetting settings)
 {
     var provType = Type.GetType(settings.ProviderAssemblyQualifiedName);
     if (provType != null)
     {
         var ci = provType.GetConstructor(new[] {typeof (JObject)});
         if (ci != null)
         {
            return (IPushNotificationDeliveryProvider) ci.Invoke(new object[] {settings.ProviderConfigurationData});
         }
     }
     return null;
 }
        internal DateTimeOffset?GetSendDate(ApplicationPushNotificationSetting appSettings, SubscriberNotificationSetting userNoteSettings)
        {
            var send = ScheduledSendDate;//we'll leave this alone if consolidation isn't used

            if (userNoteSettings.IsEnabled && appSettings.AntiNoiseSettings.IsConsolidationEnabled && ScheduledSendDate.HasValue)
            {
                var now = DateTime.Now;

                var currentDelayMinutes = (now - CreatedDate).Minutes;

                var maxDelayMinutes = appSettings.AntiNoiseSettings.MaxConsolidationDelayMinutes;

                var delay = appSettings.AntiNoiseSettings.InitialConsolidationDelayMinutes;

                //ensure we don't bump thing over the max wait
                if (delay + currentDelayMinutes > maxDelayMinutes)
                {
                    delay = maxDelayMinutes - currentDelayMinutes;
                }

                send = now.AddMinutes(delay);
            }
            return(send);
        }
        internal DateTimeOffset? GetSendDate(ApplicationPushNotificationSetting appSettings, SubscriberNotificationSetting userNoteSettings)
        {
            var send = ScheduledSendDate;//we'll leave this alone if consolidation isn't used

            if (userNoteSettings.IsEnabled && appSettings.AntiNoiseSettings.IsConsolidationEnabled && ScheduledSendDate.HasValue)
            {
                var now = DateTime.Now;

                var currentDelayMinutes = (now - CreatedDate).Minutes;

                var maxDelayMinutes = appSettings.AntiNoiseSettings.MaxConsolidationDelayMinutes;

                var delay = appSettings.AntiNoiseSettings.InitialConsolidationDelayMinutes;

                //ensure we don't bump thing over the max wait
                if (delay + currentDelayMinutes > maxDelayMinutes)
                {
                    delay = maxDelayMinutes - currentDelayMinutes;
                }

                send = now.AddMinutes(delay);
            }
            return send;
        }
        public void AddNewEvent(TicketPushNotificationEventInfo eventInfo, ApplicationPushNotificationSetting appSettings, SubscriberNotificationSetting userSetting)
        {
            //no matter what, update to the current message content
            PushNotificationItem.MessageContent = eventInfo.MessageContent;

            if (eventInfo.CancelNotification)
            {
                //remove event
                TicketEvents.Remove(eventInfo.EventId);
                CanceledEvents.Add(eventInfo.EventId);
                if (!TicketEvents.Any())//no events left, scrap entire notification
                {
                    PushNotificationItem.DeliveryStatus = PushNotificationItemStatus.Canceled;
                    PushNotificationItem.ScheduledSendDate = null;
                }
            }
            else
            {
                //add this event
                TicketEvents.Add(eventInfo.EventId);
                //kick the schedule out if consolidation enabled
                PushNotificationItem.ScheduledSendDate = PushNotificationItem.GetSendDate(appSettings, userSetting);
            }
        }
        public void AddNewEvent(TicketPushNotificationEventInfo eventInfo, ApplicationPushNotificationSetting appSettings, SubscriberNotificationSetting userSetting)
        {
            //no matter what, update to the current message content
            PushNotificationItem.MessageContent = eventInfo.MessageContent;

            if (eventInfo.CancelNotification)
            {
                //remove event
                TicketEvents.Remove(eventInfo.EventId);
                CanceledEvents.Add(eventInfo.EventId);
                if (!TicketEvents.Any())//no events left, scrap entire notification
                {
                    PushNotificationItem.DeliveryStatus    = PushNotificationItemStatus.Canceled;
                    PushNotificationItem.ScheduledSendDate = null;
                }
            }
            else
            {
                //add this event
                TicketEvents.Add(eventInfo.EventId);
                //kick the schedule out if consolidation enabled
                PushNotificationItem.ScheduledSendDate = PushNotificationItem.GetSendDate(appSettings, userSetting);
            }
        }