using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Net; using System.Runtime.Serialization; namespace WindowsPhone.Recipes.Push.Messasges { /// /// Push notification message send operation result. /// public class MessageSendResult { #region Properties /// /// Gets the original exception or null. /// public Exception Exception { get; private set; } /// /// Gets the response time offset. /// public DateTimeOffset Timestamp { get; private set; } /// /// Gets the associated message. /// public PushNotificationMessage AssociatedMessage { get; private set; } /// /// Gets the channel URI. /// public Uri ChannelUri { get; private set; } /// /// Gets the web request status. /// public HttpStatusCode StatusCode { get; private set; } /// /// Gets the push notification status. /// public NotificationStatus NotificationStatus { get; private set; } /// /// Gets the device connection status. /// public DeviceConnectionStatus DeviceConnectionStatus { get; private set; } /// /// Gets the subscription status. /// public SubscriptionStatus SubscriptionStatus { get; private set; } #endregion #region Ctor /// /// Initializes a new instance of this type. /// internal MessageSendResult(PushNotificationMessage associatedMessage, Uri channelUri, WebResponse response) { Timestamp = DateTimeOffset.Now; AssociatedMessage = associatedMessage; ChannelUri = channelUri; InitializeStatusCodes(response as HttpWebResponse); } /// /// Initializes a new instance of this type. /// internal MessageSendResult(PushNotificationMessage associatedMessage, Uri channelUri, WebException exception) : this(associatedMessage, channelUri, response: exception.Response) { Exception = exception; } /// /// Initializes a new instance of this type. /// internal MessageSendResult(PushNotificationMessage associatedMessage, Uri channelUri, Exception exception) : this(associatedMessage, channelUri, response: null) { Exception = exception; } #endregion #region Privates private void InitializeStatusCodes(HttpWebResponse response) { if (response == null) { StatusCode = HttpStatusCode.InternalServerError; NotificationStatus = NotificationStatus.NotApplicable; DeviceConnectionStatus = DeviceConnectionStatus.NotApplicable; SubscriptionStatus = SubscriptionStatus.NotApplicable; } else { StatusCode = response.StatusCode; NotificationStatus = response.GetNotificationStatus(); DeviceConnectionStatus = response.GetDeviceConnectionStatus(); SubscriptionStatus = response.GetSubscriptionStatus(); } } #endregion } }