private static void SendWPNotificationAsync(string subject, string content, NotificationHubClient hub) { //NotificationHubClient hub = NotificationHubClient.CreateClientFromConnectionString(NOTIFICATION_HUB_FULL_ACCESS_CONNECTION_STRING, NOTIFICATION_HUB_NAME); string toast = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + "<wp:Notification xmlns:wp=\"WPNotification\">" + "<wp:Toast>" + "<wp:Text1>Playbook Notification</wp:Text1>" + "<wp:Text2>" + subject + " " + content + "</wp:Text2>" + "</wp:Toast> " + "</wp:Notification>"; var tile = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + "<wp:Notification xmlns:wp=\"WPNotification\" Version=\"2.0\">" + "<wp:Tile Template=\"FlipTile\">" + "<wp:Title>Playbook</wp:Title>" + "<wp:BackTitle>Playbook !</wp:BackTitle>" + "<wp:Count>!</wp:Count>" + "<wp:BackContent>" + subject + Environment.NewLine + content + "</wp:BackContent>" + "<wp:WideBackContent>" + subject + Environment.NewLine + content + "</wp:WideBackContent>" + "</wp:Tile> " + "</wp:Notification>"; try { tile.Trim().Trim(new char[] { '\uFEFF' }); } catch (Exception) { } try { toast.Trim().Trim(new char[] { '\uFEFF' }); } catch (Exception) { } try { hub.SendMpnsNativeNotificationAsync(tile).Wait(500); hub.SendMpnsNativeNotificationAsync(toast).Wait(500); } catch (Exception) { } try { hub.SendWindowsNativeNotificationAsync(tile).Wait(500); hub.SendWindowsNativeNotificationAsync(toast).Wait(500); } catch (Exception) { } }
public static async Task <bool> SendPush(PushMessage message) { try { Hub = NotificationHubClient.CreateClientFromConnectionString("Endpoint=sb://iot-tdc-2014hub-ns.servicebus.windows.net/;SharedAccessKeyName=DefaultFullSharedAccessSignature;SharedAccessKey=YOXL/NF+JPM+VERp2d6LU95mQ0T0YfTj7C8fZ+PcXUU=", "iot-tdc-2014hub"); var user = HttpContext.Current.User.Identity.Name; var userTag = "username:"******"<toast><visual><binding template=\"ToastText01\"><text id=\"1\">" + message.Mensagem + "</text></binding></visual></toast>"; //Encoding Utf8 = new UTF8Encoding(false); //byte[] bytes = Encoding.Default.GetBytes(toast); //toast = Utf8.GetString(bytes); var result = await Hub.SendMpnsNativeNotificationAsync(prepareToastPayload(message.Mensagem, ""), userTag); } //if (message.Android) //{ // await Hub.SendGcmNativeNotificationAsync("{ \"data\" : {\"msg\":\"" + message.Mensagem + "\"}}"); //} } catch (System.Exception ex) { var text = ex.Message; return(false); } return(true); }
private static async void SendNotificationAsync() { NotificationHubClient hub = NotificationHubClient .CreateClientFromConnectionString("Endpoint=sb://pipeli...", "NHPipelineManager"); string toast = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + "<wp:Notification xmlns:wp=\"WPNotification\">" + "<wp:Toast>" + "<wp:Text1>Hello from a .NET App!</wp:Text1>" + "</wp:Toast> " + "</wp:Notification>"; await hub.SendMpnsNativeNotificationAsync(toast); }
private static async void SendNotificationAsync() { NotificationHubClient hub = NotificationHubClient .CreateClientFromConnectionString("service bus connection string from azure portal", "ashwinnotificationhub"); string toast = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + "<wp:Notification xmlns:wp=\"WPNotification\">" + "<wp:Toast>" + "<wp:Text1>Hello From Ashwin's side</wp:Text1>" + "</wp:Toast> " + "</wp:Notification>"; await hub.SendMpnsNativeNotificationAsync(toast); }
// send notification private static async void SendNotificationToAzureHubAsync(string accountName) { NotificationHubClient hub = NotificationHubClient .CreateClientFromConnectionString(Environment.GetEnvironmentVariable("Azure_Notification_Hub"), "sudreddy"); string toast = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + "<wp:Notification xmlns:wp=\"WPNotification\">" + "<wp:Toast>" + "<wp:Text1>Hello to " + accountName + " from a CRM Plugin !!!</wp:Text1>" + "</wp:Toast> " + "</wp:Notification>"; await hub.SendMpnsNativeNotificationAsync(toast); }
public async System.Threading.Tasks.Task <HttpResponseMessage> SendMPNSNotification([Metadata("Connection String")] string connectionString, [Metadata("Hub Name")] string hubName, [Metadata("Toast XML")] string message, [Metadata("Toast Tags")] string tags = null) { try { NotificationHubClient hub = NotificationHubClient.CreateClientFromConnectionString(connectionString, hubName); NotificationOutcome result; if (!string.IsNullOrEmpty(tags)) { result = await hub.SendMpnsNativeNotificationAsync(message, tags); } else { result = await hub.SendMpnsNativeNotificationAsync(message); } return(Request.CreateResponse <NotificationOutcome>(HttpStatusCode.OK, result)); } catch (ConfigurationErrorsException ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.BareMessage)); } }
/// <summary> /// Basic implementation that sends a notification to Windows Store, Android and iOS app clients. /// </summary> /// <param name="notificationText">The notification text.</param> /// <param name="tag">The tag.</param> /// <returns>Task.</returns> private async Task SendNotificationAsync(string notificationText, string tag) { try { // Create notifications for both Windows Store and iOS platforms. XNamespace wp = "WPNotification"; XDocument doc = new XDocument(new XDeclaration("1.0", "utf-8", null), new XElement(wp + "Notification", new XAttribute(XNamespace.Xmlns + "wp", "WPNotification"), new XElement(wp + "Toast", new XElement(wp + "Text1", "Notification Hubs Sample"), new XElement(wp + "Text2", notificationText)))); var toastMpns = string.Concat(doc.Declaration, doc.ToString(SaveOptions.DisableFormatting)); var toast = new XElement("toast", new XElement("visual", new XElement("binding", new XAttribute("template", "ToastText01"), new XElement("text", new XAttribute("id", "1"), notificationText)))).ToString(SaveOptions.DisableFormatting); var alert = new JObject( new JProperty("aps", new JObject(new JProperty("alert", notificationText))), new JProperty("inAppMessage", notificationText)) .ToString(Newtonsoft.Json.Formatting.None); var payload = new JObject( new JProperty("data", new JObject(new JProperty("message", notificationText)))) .ToString(Newtonsoft.Json.Formatting.None); // Send a notification to the logged-in user on both platforms. var googleResult = await _notificationHubClient.SendGcmNativeNotificationAsync(payload, tag); var windowsResult = await _notificationHubClient.SendWindowsNativeNotificationAsync(toast, tag); var mpsnResult = await _notificationHubClient.SendMpnsNativeNotificationAsync(toastMpns, tag); var appleResult = await _notificationHubClient.SendAppleNativeNotificationAsync(alert, tag); } catch (ArgumentException ex) { // This is expected when an APNS registration doesn't exist. Debug.WriteLine(ex.Message); } }
/// TODO: Exercise 12.3: Pushing a message to a Service Bus Notification Hub public async Task SendNotification() { NotificationHubClient hub = NotificationHubClient.CreateClientFromConnectionString("Endpoint=sb://contosoevents.servicebus.windows.net/;SharedAccessKeyName=DefaultFullSharedAccessSignature;SharedAccessKey=j1toC1FXT/kECuAEzaBuKLOzYT9KXsWKmbXPiKWmddo=", "events"); String message = String.Format("Event: {0} has been updated.", this.Event.Title); string toastXml = GetXml(); toastXml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + "<wp:Notification xmlns:wp=\"WPNotification\">" + "<wp:Toast>" + "<wp:Text1>Hello from a .NET App!</wp:Text1>" + "</wp:Toast> " + "</wp:Notification>"; NotificationOutcome result = await hub.SendMpnsNativeNotificationAsync(toastXml); }
public async Task sendWPNotification(string message, IEnumerable <string> tags) { try { // Define a Windows Phone toast. var mpnsToast = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + "<wp:Notification xmlns:wp=\"WPNotification\">" + "<wp:Toast>" + "<wp:Text1>" + message + "</wp:Text1>" + "</wp:Toast> " + "</wp:Notification>"; await hub.SendMpnsNativeNotificationAsync(mpnsToast, tags); } catch (Exception ex) { Trace.TraceError("Error while sending Windows Phone toast: " + ex.Message); } }