private void EnqueueAndroidNotification(Device device, PushNotification notification) { var config = PushServiceConfiguration.GetSection(); string json = string.Format(@"{{""message"":""{0}"",""msgcnt"":""{1}"",""regid"":""{2}""", notification.Message, device.Badge, device.RegistrationID); if (notification.Module != PushModule.Unknown && notification.Item != null) { var itemType = notification.Item.Type; var itemId = notification.Item.ID; if (notification.Item.Type == PushItemType.Subtask && notification.ParentItem != null) { itemType = notification.ParentItem.Type; itemId = notification.ParentItem.ID; } json += string.Format(@",""itemid"":""{0}"",""itemtype"":""{1}""", itemId, itemType.ToString().ToLower()); } json += "}"; var gcmNotification = new GcmNotification() .ForDeviceRegistrationId(device.Token) .WithJson(json); if (config.IsDebug || !config.Gcm.ElementInformation.IsPresent) { _log.DebugFormat("notification ({0}) prevented from sending to device {1}", gcmNotification, device.ID); return; } PushBrokerProvider.Instance.QueueNotification(gcmNotification); }
public void Start() { XmlConfigurator.Configure(); _notificationCleaner = new NotificationCleaner(PushServiceConfiguration.GetSection().FeedLifetime); _notificationCleaner.Start(); _serviceHost = new ServiceHost(typeof(PushService)); _serviceHost.Open(); }
private static PushBroker CreateInstance() { Log.Info("initializing PushBroker instance"); var config = PushServiceConfiguration.GetSection(); var pushBroker = new PushBroker(); SubscribeOnEvents(pushBroker, config); RegisterApnsService(pushBroker, config); RegisterGcmService(pushBroker, config); return(pushBroker); }
private void EnqueueApnsNotification(Device device, PushNotification notification) { var config = PushServiceConfiguration.GetSection(); string message = notification.Message; if (message != null && message.Length > config.Apns.MaxMessageLength) { message = notification.ShortMessage ?? notification.Message; } if (message != null && message.Length > config.Apns.MaxMessageLength) { _log.WarnFormat("message is larger than maximum allowed length of {0}", config.Apns.MaxMessageLength); return; } var apnsNotification = new AppleNotification() .ForDeviceToken(device.Token) .WithAlert(message) .WithBadge(device.Badge) .WithCustomItem("regid", device.RegistrationID); if (notification.Module != PushModule.Unknown && notification.Item != null) { var itemType = notification.Item.Type; var itemId = notification.Item.ID; if (notification.Item.Type == PushItemType.Subtask && notification.ParentItem != null) { itemType = notification.ParentItem.Type; itemId = notification.ParentItem.ID; } apnsNotification.WithCustomItem("itemid", itemId); apnsNotification.WithCustomItem("itemtype", itemType.ToString().ToLower()); } if (config.IsDebug || !config.Apns.ElementInformation.IsPresent) { _log.DebugFormat("notification ({0}) prevented from sending to device {1}", apnsNotification, device.ID); return; } PushBrokerProvider.Instance.QueueNotification(apnsNotification); }