using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Net; namespace WindowsPhone.Recipes.Push.Messasges { /// /// Extends the type with methods for translating push notification specific status codes strings to strong typed enumeration. /// internal static class HttpWebResponseExtensions { /// /// Gets the Notification Status code as enumeration. /// /// The http web response instance. /// Correlate enumeration value. public static NotificationStatus GetNotificationStatus(this HttpWebResponse response) { return response.GetStatus( NotificationStatus.NotApplicable, PushNotificationMessage.Headers.NotificationStatus); } /// /// Gets the Device Connection Status code as enumeration. /// /// The http web response instance. /// Correlate enumeration value. public static DeviceConnectionStatus GetDeviceConnectionStatus(this HttpWebResponse response) { return response.GetStatus( DeviceConnectionStatus.NotApplicable, PushNotificationMessage.Headers.DeviceConnectionStatus); } /// /// Gets the Subscription Status code as enumeration. /// /// The http web response instance. /// Correlate enumeration value. public static SubscriptionStatus GetSubscriptionStatus(this HttpWebResponse response) { return response.GetStatus( SubscriptionStatus.NotApplicable, PushNotificationMessage.Headers.SubscriptionStatus); } private static T GetStatus(this HttpWebResponse response, T def, string header) where T : struct { string statusString = response.Headers[header]; T status = def; Enum.TryParse(statusString, out status); return status; } } }