Exemplo n.º 1
0
        void ParseStatus(HttpWebResponse resp, BISNotification notification, ref BISMessageStatus status, ref string desc)
        {
            status = new BISMessageStatus
            {
                Notification = notification,
                HttpStatus   = HttpStatusCode.ServiceUnavailable
            };

            var bbNotStatus = string.Empty;

            if (resp != null)
            {
                status.HttpStatus = resp.StatusCode;

                using (var responseStream = resp.GetResponseStream())
                {
                    var doc    = XDocument.Load(responseStream);
                    var result = doc.Descendants("response-result").SingleOrDefault();
                    if (result != null)
                    {
                        bbNotStatus = result.Attribute("code").Value;
                        desc        = result.Attribute("desc").Value;
                    }
                    else
                    {
                        result = doc.Descendants("badmessage-response").SingleOrDefault();
                        if (result != null)
                        {
                            bbNotStatus = result.Attribute("code").Value;
                            desc        = result.Attribute("desc").Value;
                        }
                    }
                }
            }

            BISNotificationStatus notStatus;

            Enum.TryParse(bbNotStatus, true, out notStatus);
            status.NotificationStatus = notStatus;
        }
Exemplo n.º 2
0
        void HandleStatus(SendNotificationCallbackDelegate callback, BISMessageStatus status, string desc, BISNotification notification = null)
        {
            if (status.NotificationStatus == BISNotificationStatus.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 == BISNotificationStatus.RequestAcceptedForProcessing)
            {
                if (callback != null)
                {
                    callback(this, new SendNotificationResult(notification));
                }
                return;
            }

            if (callback != null)
            {
                callback(this, new SendNotificationResult(status.Notification, false, new BISNotificationSendFailureException(status, desc)));
            }
        }