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)); } } }