Пример #1
0
        public void Blackberry_Simple_Test()
        {
            var waitCallback = new ManualResetEvent(false);

            var settings = new BlackberryPushChannelSettings("APPID", "PWD");

            var c = new BlackberryPushChannel(settings);

            var n = new BlackberryNotification();

            n.Content = new BlackberryMessageContent("text/plain", "66");

            n.QualityOfService       = QualityOfServiceLevel.Unconfirmed;
            n.SourceReference        = "3682-8s4B97Rc2388i46I8M08769D005ra6286o4";
            n.DeliverBeforeTimestamp = DateTime.UtcNow.AddMinutes(1);
            var r = new BlackberryRecipient("push_all");

            n.Recipients.Add(r);

            c.SendNotification(n, (sender, resp) => {
                waitCallback.Set();
            });

            waitCallback.WaitOne();
        }
        private void EnsureBlackberryStarted()
        {
            if (_blackberryStarted)
            {
                return;
            }

            _blackberryStarted = true;

            string appId = _serverSettings.ServerData.BBNotificationSettings.AppId;

            BlackberryConfiguration configuration = new BlackberryConfiguration(
                appId,
                _serverSettings.ServerData.BBNotificationSettings.Password);

            configuration.OverrideSendUrl(_serverSettings.ServerData.BBNotificationSettings.Url);

            _apps.Add(appId, new AppPushBrokers {
                Bb = new BlackberryServiceBroker(configuration)
            });

            _apps[appId].Bb.OnNotificationSucceeded += OnBlackBeryNotificationSucceeded;
            _apps[appId].Bb.OnNotificationFailed    += (notification, aggregateEx) => {
                aggregateEx.Handle(ex => {
                    // See what kind of exception it was to further diagnose
                    if (ex is BlackberryNotificationException)
                    {
                        var x = ex as BlackberryNotificationException;

                        // Deal with the failed notification
                        BlackberryNotification n = x.Notification;
                        string description       = "Message: " + x.Message + " Data:" + x.Data.ToString();
                        _logger.LogMessage("Notification Failed: ID={0}, Desc={1}", n.PushId, description);
                    }
                    else if (ex is DeviceSubscriptionExpiredException)
                    {
                        LogDeviceSubscriptionExpiredException((DeviceSubscriptionExpiredException)ex);
                    }
                    else if (ex is RetryAfterException)
                    {
                        LogRetryAfterException((RetryAfterException)ex);
                    }
                    else
                    {
                        _logger.LogMessage("Notification Failed for some (Unknown Reason)");
                    }

                    // Mark it as handled
                    return(true);
                });
            };

            _apps[appId].Bb.Start();
        }
        private void SendBBNotification(string alert, IDictionary <string, object> data, string registrationId)
        {
            var payload = new Dictionary <string, object>(data);

            payload["alert"] = alert;

            var notif = new BlackberryNotification();

            notif.Recipients.Add(new BlackberryRecipient(registrationId));
            notif.Content         = new BlackberryMessageContent(JsonConvert.SerializeObject(payload));
            notif.SourceReference = _serverSettings.ServerData.BBNotificationSettings.AppId;

            _apps[_serverSettings.ServerData.BBNotificationSettings.AppId].Bb.QueueNotification(notif);
        }
 private void OnBlackBeryNotificationSucceeded(BlackberryNotification notification)
 {
     _logger.LogMessage("Sent: " + (notification.Content != null ? notification.Content.ToString() : String.Empty));
 }