public BisNotificationSendFailureException(BlackberryMessageStatus msgStatus, string desc)
 {
     _data.Add("HttpStatus", msgStatus.HttpStatus);
     _data.Add("Code", (Int32)msgStatus.NotificationStatus);
     _data.Add("Notification", msgStatus.Notification);
     _data.Add("Description", desc);
     _message = desc;
 }
		public BisNotificationSendFailureException(BlackberryMessageStatus msgStatus, string desc)
		{
            _data.Add("HttpStatus", msgStatus.HttpStatus);
            _data.Add("Code", (Int32) msgStatus.NotificationStatus);
            _data.Add("Notification", msgStatus.Notification);
            _data.Add("Description",desc);
            _message = desc;
		}
Exemple #3
0
        public async Task Send(BlackberryNotification notification)
        {
            var response = await http.PostNotification(notification);

            var description = string.Empty;

            var status = new BlackberryMessageStatus
            {
                Notification = notification,
                HttpStatus   = HttpStatusCode.ServiceUnavailable
            };

            var bbNotStatus = string.Empty;

            status.HttpStatus = response.StatusCode;

            var xmlContent = await response.Content.ReadAsStreamAsync();

            var doc = XDocument.Load(xmlContent);

            XElement result = doc.Descendants().FirstOrDefault(desc =>
                                                               desc.Name == "response-result" ||
                                                               desc.Name == "badmessage-response");

            if (result != null)
            {
                bbNotStatus = result.Attribute("code").Value;
                description = result.Attribute("desc").Value;
            }

            BlackberryNotificationStatus notStatus;

            Enum.TryParse(bbNotStatus, true, out notStatus);
            status.NotificationStatus = notStatus;

            if (status.NotificationStatus == BlackberryNotificationStatus.NoAppReceivePush)
            {
                throw new DeviceSubscriptionExpiredException(notification);
            }

            if (status.HttpStatus == HttpStatusCode.OK &&
                status.NotificationStatus == BlackberryNotificationStatus.RequestAcceptedForProcessing)
            {
                return;
            }

            throw new BlackberryNotificationException(status, description, notification);
        }
        public void SendNotification(INotification notification, SendNotificationCallbackDelegate callback)
        {
            var n = notification as BlackberryNotification;

            try
            {
                var response = http.PostNotification(bisChannelSettings, n).Result;
                var description = string.Empty;

                var status = new BlackberryMessageStatus
                    {
                        Notification = n,
                        HttpStatus = HttpStatusCode.ServiceUnavailable
                    };

                var bbNotStatus = string.Empty;
                status.HttpStatus = response.StatusCode;

                var doc = XDocument.Load(response.Content.ReadAsStreamAsync().Result);

                var result = doc.Descendants("response-result").SingleOrDefault();
                if (result != null)
                {
                    bbNotStatus = result.Attribute("code").Value;
                    description = result.Attribute("desc").Value;
                }
                else
                {
                    result = doc.Descendants("badmessage-response").SingleOrDefault();
                    if (result != null)
                    {
                        bbNotStatus = result.Attribute("code").Value;
                        description = result.Attribute("desc").Value;
                    }
                }

                BlackberryNotificationStatus notStatus;
                Enum.TryParse(bbNotStatus, true, out notStatus);
                status.NotificationStatus = notStatus;

                if (status.NotificationStatus == BlackberryNotificationStatus.NoAppReceivePush)
                {
                    if (callback != null)
                        callback(this,
                                 new SendNotificationResult(notification, false, new Exception("Device Subscription Expired"))
                                     {
                                         IsSubscriptionExpired = true
                                     });

                    return;
                }

                if (status.HttpStatus == HttpStatusCode.OK
                    && status.NotificationStatus == BlackberryNotificationStatus.RequestAcceptedForProcessing)
                {
                    if (callback != null)
                        callback(this, new SendNotificationResult(notification));
                    return;
                }

                if (callback != null)
                    callback(this,
                             new SendNotificationResult(status.Notification, false,
                                                        new BisNotificationSendFailureException(status, description)));
            }
            catch (Exception ex)
            {
                if (callback != null)
                    callback(this, new SendNotificationResult(notification, false, ex));
            }
        }
 public BlackberryNotificationException(BlackberryMessageStatus msgStatus, string desc, BlackberryNotification notification)
     : base(desc + " - " + msgStatus, notification)
 {
     Notification  = notification;
     MessageStatus = msgStatus;
 }
Exemple #6
0
        public void SendNotification(INotification notification, SendNotificationCallbackDelegate callback)
        {
            var n = notification as BlackberryNotification;

            try
            {
                var response    = http.PostNotification(bisChannelSettings, n).Result;
                var description = string.Empty;

                var status = new BlackberryMessageStatus
                {
                    Notification = n,
                    HttpStatus   = HttpStatusCode.ServiceUnavailable
                };

                var bbNotStatus = string.Empty;
                status.HttpStatus = response.StatusCode;

                var doc = XDocument.Load(response.Content.ReadAsStreamAsync().Result);

                var result = doc.Descendants("response-result").SingleOrDefault();
                if (result != null)
                {
                    bbNotStatus = result.Attribute("code").Value;
                    description = result.Attribute("desc").Value;
                }
                else
                {
                    result = doc.Descendants("badmessage-response").SingleOrDefault();
                    if (result != null)
                    {
                        bbNotStatus = result.Attribute("code").Value;
                        description = result.Attribute("desc").Value;
                    }
                }

                BlackberryNotificationStatus notStatus;
                Enum.TryParse(bbNotStatus, true, out notStatus);
                status.NotificationStatus = notStatus;

                if (status.NotificationStatus == BlackberryNotificationStatus.NoAppReceivePush)
                {
                    if (callback != null)
                    {
                        callback(this,
                                 new SendNotificationResult(notification, false, new Exception("Device Subscription Expired"))
                        {
                            IsSubscriptionExpired = true
                        });
                    }

                    return;
                }

                if (status.HttpStatus == HttpStatusCode.OK &&
                    status.NotificationStatus == BlackberryNotificationStatus.RequestAcceptedForProcessing)
                {
                    if (callback != null)
                    {
                        callback(this, new SendNotificationResult(notification));
                    }
                    return;
                }

                if (callback != null)
                {
                    callback(this,
                             new SendNotificationResult(status.Notification, false,
                                                        new BisNotificationSendFailureException(status, description)));
                }
            }
            catch (Exception ex)
            {
                if (callback != null)
                {
                    callback(this, new SendNotificationResult(notification, false, ex));
                }
            }
        }
Exemple #7
0
 public BlackberryNotificationException (BlackberryMessageStatus msgStatus, string desc, BlackberryNotification notification) 
     :base (desc + " - " + msgStatus, notification)
 {
     Notification = notification;
     MessageStatus = msgStatus;
 }