/// <summary> /// Configures the push notifications. /// </summary> public static void ConfigurePushNotifications() { var demoMode = ConfigurationManager.AppSettings["ticketdesk:DemoModeEnabled"] ?? "false"; if (!DatabaseConfig.IsDatabaseReady || demoMode.Equals("true", StringComparison.InvariantCultureIgnoreCase)) { //disable if database hasn't been created, of if running in demo mode return; } //configuration supplied by the IoC configuration var context = DependencyResolver.Current.GetService <TdPushNotificationContext>(); if (DatabaseConfig.IsFirstRunDemoRefreshEnabled()) { DemoPushNotificationDataManager.SetupDemoPushNotificationData(context); } if (context.TicketDeskPushNotificationSettings.IsEnabled) { EnsureBroadcastNotificaitonsConfiguration(context); //TODO: poor man's detection of appropriate scheduler var siteName = Environment.GetEnvironmentVariable("WEBSITE_SITE_NAME"); var isAzureWebSite = !string.IsNullOrEmpty(siteName); if (!isAzureWebSite) { InProcessPushNotificationScheduler.Start(context.TicketDeskPushNotificationSettings .DeliveryIntervalMinutes); } if (context.TicketDeskPushNotificationSettings.IsBackgroundQueueEnabled) { //register for static notifications created event handler TdDomainContext.NotificationsCreated += (sender, notifications) => { HostingEnvironment.QueueBackgroundWorkItem(CreateTicketEventNotifications(notifications)); }; TdDomainContext.TicketsCreated += (sender, tickets) => { HostingEnvironment.QueueBackgroundWorkItem(CreateNewTicketBroadcastNotification(tickets)); }; } else { TdDomainContext.NotificationsCreated += (sender, notifications) => { CreateTicketEventNotifications(notifications)(CancellationToken.None); }; TdDomainContext.TicketsCreated += (sender, tickets) => { CreateNewTicketBroadcastNotification(tickets)(CancellationToken.None); }; } } context.Dispose(); //ensure that no one accidentally holds a reference to this in closure }
public static void ConfigurePushNotifications() { var demoMode = ConfigurationManager.AppSettings["ticketdesk:DemoModeEnabled"] ?? "false"; if (!DatabaseConfig.IsDatabaseReady || demoMode.Equals("true", StringComparison.InvariantCultureIgnoreCase)) { //disable if database hasn't been created, of if running in demo mode return; } //configuration supplied by the IoC configuration var context = DependencyResolver.Current.GetService <TdPushNotificationContext>(); if (DatabaseConfig.IsFirstRunDemoRefreshEnabled()) { DemoPushNotificationDataManager.SetupDemoPushNotificationData(context); } if (context.TicketDeskPushNotificationSettings.IsEnabled) { //TODO: poor man's detection of appropriate scheduler var siteName = Environment.GetEnvironmentVariable("WEBSITE_SITE_NAME"); var isAzureWebSite = !string.IsNullOrEmpty(siteName); if (!isAzureWebSite) { InProcessPushNotificationScheduler.Start(context.TicketDeskPushNotificationSettings.DeliveryIntervalMinutes); } context.Dispose();//ensure that no one accidentally holds a reference to this in closure //register for static notifications created event handler TdDomainContext.NotificationsCreated += (sender, notifications) => { // ReSharper disable once EmptyGeneralCatchClause try { var notes = notifications as TicketEventNotification[] ?? notifications.ToArray(); if (notes.Any()) { HostingEnvironment.QueueBackgroundWorkItem( async ct => { var noteContext = DependencyResolver.Current.GetService <TdPushNotificationContext>(); var subscriberExclude = noteContext.TicketDeskPushNotificationSettings.AntiNoiseSettings.ExcludeSubscriberEvents; await noteContext.AddNotifications(notes.ToNotificationEventInfoCollection(subscriberExclude)); await noteContext.SaveChangesAsync(ct); }); } } catch { //TODO: Log this somewhere } }; } }
public ActionResult CreateDemoData() { using (var ctx = new TdDomainContext(null)) { DemoDataManager.SetupDemoData(ctx); } DemoIdentityDataManager.SetupDemoIdentityData(IdentityContext, User.Identity.GetUserId()); DemoPushNotificationDataManager.SetupDemoPushNotificationData(PushNotificationContext); ViewBag.DemoDataCreated = true; return(View("Demo")); }
public ActionResult RemoveDemoData() { using (var ctx = new TdDomainContext(null)) { DemoDataManager.RemoveAllData(ctx); } DemoIdentityDataManager.RemoveAllIdentity(IdentityContext); DemoPushNotificationDataManager.RemoveAllPushNotificationData(PushNotificationContext); ViewBag.DemoDataRemoved = true; return(View("Demo")); }
public ActionResult CreateDemoData() { using (var ctx = new TdDomainContext(null)) { DemoDataManager.SetupDemoData(ctx); } DemoIdentityDataManager.SetupDemoIdentityData(IdentityContext, User.Identity.GetUserId()); DemoPushNotificationDataManager.SetupDemoPushNotificationData(PushNotificationContext); ViewBag.DemoDataCreated = true; Task.Delay(500).ContinueWith(t => System.Web.HttpRuntime.UnloadAppDomain()).ConfigureAwait(false); return(View("Demo")); }