Created
July 2, 2014 11:20
-
-
Save Cheesebaron/d0c3f408b11b548a84af to your computer and use it in GitHub Desktop.
NotificationHub extensions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
using System.Threading.Tasks; | |
using Microsoft.ServiceBus.Notifications; | |
namespace Cheesebaron.Extensions | |
{ | |
public static class NotificationHubClientExtensions | |
{ | |
public static async Task<NotificationOutcome> SendNotificationAsync(this NotificationHubClient client, NotificationHubClientPlatform platform, | |
string payload, string tagExpression) | |
{ | |
switch (platform) | |
{ | |
case NotificationHubClientPlatform.Adm: | |
return await client.SendAdmNativeNotificationAsync(payload, tagExpression); | |
case NotificationHubClientPlatform.Apple: | |
return await client.SendAppleNativeNotificationAsync(payload, tagExpression); | |
case NotificationHubClientPlatform.Gcm: | |
return await client.SendGcmNativeNotificationAsync(payload, tagExpression); | |
case NotificationHubClientPlatform.Windows: | |
return await client.SendWindowsNativeNotificationAsync(payload, tagExpression); | |
case NotificationHubClientPlatform.Mpns: | |
return await client.SendMpnsNativeNotificationAsync(payload, tagExpression); | |
default: | |
return null; | |
} | |
} | |
public static async Task<NotificationOutcome> SendNotificationAsync(this NotificationHubClient client, NotificationHubClientPlatform platform, | |
string payload, IEnumerable<string> tags) | |
{ | |
switch (platform) | |
{ | |
case NotificationHubClientPlatform.Adm: | |
return await client.SendAdmNativeNotificationAsync(payload, tags); | |
case NotificationHubClientPlatform.Apple: | |
return await client.SendAppleNativeNotificationAsync(payload, tags); | |
case NotificationHubClientPlatform.Gcm: | |
return await client.SendGcmNativeNotificationAsync(payload, tags); | |
case NotificationHubClientPlatform.Windows: | |
return await client.SendWindowsNativeNotificationAsync(payload, tags); | |
case NotificationHubClientPlatform.Mpns: | |
return await client.SendMpnsNativeNotificationAsync(payload, tags); | |
default: | |
return null; | |
} | |
} | |
public static async Task<NotificationOutcome> SendNotificationAsync(this NotificationHubClient client, string platform, | |
string payload, IEnumerable<string> tags) | |
{ | |
switch (platform.ToLower()) | |
{ | |
case "adm": | |
return await client.SendAdmNativeNotificationAsync(payload, tags); | |
case "apple": | |
case "ios": | |
return await client.SendAppleNativeNotificationAsync(payload, tags); | |
case "android": | |
case "gcm": | |
return await client.SendGcmNativeNotificationAsync(payload, tags); | |
case "windows": | |
return await client.SendWindowsNativeNotificationAsync(payload, tags); | |
case "windowsphone": | |
case "wp": | |
case "mpns": | |
return await client.SendMpnsNativeNotificationAsync(payload, tags); | |
default: | |
return null; | |
} | |
} | |
public static async Task<NotificationOutcome> SendNotificationAsync(this NotificationHubClient client, string platform, | |
string payload, string tagExpression) | |
{ | |
switch (platform.ToLower()) | |
{ | |
case "adm": | |
return await client.SendAdmNativeNotificationAsync(payload, tagExpression); | |
case "apple": | |
case "ios": | |
return await client.SendAppleNativeNotificationAsync(payload, tagExpression); | |
case "android": | |
case "gcm": | |
return await client.SendGcmNativeNotificationAsync(payload, tagExpression); | |
case "windows": | |
return await client.SendWindowsNativeNotificationAsync(payload, tagExpression); | |
case "windowsphone": | |
case "wp": | |
case "mpns": | |
return await client.SendMpnsNativeNotificationAsync(payload, tagExpression); | |
default: | |
return null; | |
} | |
} | |
} | |
public enum NotificationHubClientPlatform | |
{ | |
Adm, | |
Gcm, | |
Apple, | |
Windows, | |
Mpns | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment