mirror of
https://github.com/farcasclaudiu/myfriendsaround.git
synced 2026-06-28 23:01:53 +03:00
00f97e41d6
http://windowsteamblog.com/windows_phone/b/wpdev/archive/2011/01/14/windows-push-notification-server-side-helper-library.aspx http://create.msdn.com/en-us/education/catalog/article/pnhelp-wp7
59 lines
2.4 KiB
C#
59 lines
2.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Net;
|
|
|
|
namespace WindowsPhone.Recipes.Push.Messasges
|
|
{
|
|
/// <summary>
|
|
/// Extends the <see cref="HttpWebResponse"/> type with methods for translating push notification specific status codes strings to strong typed enumeration.
|
|
/// </summary>
|
|
internal static class HttpWebResponseExtensions
|
|
{
|
|
/// <summary>
|
|
/// Gets the Notification Status code as <see cref="NotificationStatus"/> enumeration.
|
|
/// </summary>
|
|
/// <param name="response">The http web response instance.</param>
|
|
/// <returns>Correlate enumeration value.</returns>
|
|
public static NotificationStatus GetNotificationStatus(this HttpWebResponse response)
|
|
{
|
|
return response.GetStatus(
|
|
NotificationStatus.NotApplicable,
|
|
PushNotificationMessage.Headers.NotificationStatus);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the Device Connection Status code as <see cref="NotificationStatus"/> enumeration.
|
|
/// </summary>
|
|
/// <param name="response">The http web response instance.</param>
|
|
/// <returns>Correlate enumeration value.</returns>
|
|
public static DeviceConnectionStatus GetDeviceConnectionStatus(this HttpWebResponse response)
|
|
{
|
|
return response.GetStatus(
|
|
DeviceConnectionStatus.NotApplicable,
|
|
PushNotificationMessage.Headers.DeviceConnectionStatus);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the Subscription Status code as <see cref="NotificationStatus"/> enumeration.
|
|
/// </summary>
|
|
/// <param name="response">The http web response instance.</param>
|
|
/// <returns>Correlate enumeration value.</returns>
|
|
public static SubscriptionStatus GetSubscriptionStatus(this HttpWebResponse response)
|
|
{
|
|
return response.GetStatus(
|
|
SubscriptionStatus.NotApplicable,
|
|
PushNotificationMessage.Headers.SubscriptionStatus);
|
|
}
|
|
|
|
private static T GetStatus<T>(this HttpWebResponse response, T def, string header) where T : struct
|
|
{
|
|
string statusString = response.Headers[header];
|
|
T status = def;
|
|
Enum.TryParse<T>(statusString, out status);
|
|
return status;
|
|
}
|
|
}
|
|
}
|