/// /// <summary> /// Send push notification to specific platform (Android, iOS or Windows) /// </summary> /// <param name="newNotification"></param> /// <returns></returns> public async Task <HubResponse <NotificationOutcome> > SendNotification(Notification newNotification) { try { NotificationOutcome outcome = null; switch (newNotification.Platform) { case MobilePlatform.wns: if (newNotification.Tags == null) { outcome = await _hubClient.SendWindowsNativeNotificationAsync(newNotification.Content); } else { outcome = await _hubClient.SendWindowsNativeNotificationAsync(newNotification.Content, newNotification.Tags); } break; case MobilePlatform.apns: if (newNotification.Tags == null) { outcome = await _hubClient.SendAppleNativeNotificationAsync(newNotification.Content); } else { outcome = await _hubClient.SendAppleNativeNotificationAsync(newNotification.Content, newNotification.Tags); } break; /*case MobilePlatform.gcm: * if (newNotification.Tags == null) * outcome = await _hubClient.SendGcmNativeNotificationAsync(newNotification.Content); * else * outcome = await _hubClient.SendGcmNativeNotificationAsync(newNotification.Content, newNotification.Tags); * break;*/ } if (outcome != null) { if (!((outcome.State == NotificationOutcomeState.Abandoned) || (outcome.State == NotificationOutcomeState.Unknown))) { return(new HubResponse <NotificationOutcome>()); } } return(new HubResponse <NotificationOutcome>().SetAsFailureResponse().AddErrorMessage("Notification was not sent due to issue. Please send again.")); } catch (MessagingException ex) { return(new HubResponse <NotificationOutcome>().SetAsFailureResponse().AddErrorMessage(ex.Message)); } catch (ArgumentException ex) { return(new HubResponse <NotificationOutcome>().SetAsFailureResponse().AddErrorMessage(ex.Message)); } }
public async Task <bool> SendToastNotificationAsync(string toast, string xmlTemplate, string notificationTag) { string payLoad = String.Format(xmlTemplate, toast); await _NotificationHubClient.SendWindowsNativeNotificationAsync(payLoad, notificationTag); return(true); }
protected void Button1_Click(object sender, EventArgs e) { // This call essentialy broadcasts a push notification to ALL Windows 8 devices that are registered with the service // and registered to that tag var payload = string.Format(toastTemplate, "Breaking World News!"); hub.SendWindowsNativeNotificationAsync(payload, "worldnews"); }
public async void SendNotificationAsync(string mySbMsg) { var e = DeserializeMessage(mySbMsg); var toast = WindowsTemplateMaker(e); var windowsResult = await _hub.SendWindowsNativeNotificationAsync(toast, e.deviceId); Debug.WriteLine(windowsResult); }
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 async Task <bool> SendNotificationAsync(string platform, string message, string to_tag) { var user = "******"; string[] userTag = new string[1]; userTag[0] = to_tag; NotificationOutcome outcome = null; switch (platform.ToLower()) { case "wns": // Windows 8.1 / Windows Phone 8.1 var toast = @"<toast><visual><binding template=""ToastText01""><text id=""1"">" + "From " + user + ": " + message + "</text></binding></visual></toast>"; outcome = await _hub.SendWindowsNativeNotificationAsync(toast, userTag); // Windows 10 specific Action Center support toast = @"<toast><visual><binding template=""ToastGeneric""><text id=""1"">" + "From " + user + ": " + message + "</text></binding></visual></toast>"; outcome = await _hub.SendWindowsNativeNotificationAsync(toast, userTag); break; case "apns": // iOS var alert = "{\"aps\":{\"alert\":\"" + "From " + user + ": " + message + "\"}}"; outcome = await _hub.SendAppleNativeNotificationAsync(alert, userTag); break; case "gcm": // Android var notif = "{ \"data\" : {\"message\":\"" + "From " + user + ": " + message + "\"}}"; outcome = await _hub.SendGcmNativeNotificationAsync(notif, userTag); break; } if (outcome != null) { if (!((outcome.State == NotificationOutcomeState.Abandoned) || (outcome.State == NotificationOutcomeState.Unknown))) { return(true); } } return(false); }
private static async Task PushMessagesToHub() { while (true) { while (msgSendQueue.Count > 0) { try { PushMessage msgObject = null; lock (syncObject) { msgObject = msgSendQueue.Dequeue(); } if (msgObject == null) { continue; } string message = msgObject.ToString(); switch (msgObject.Type) { case PushMessage.PushType.Android: await pushHub.SendGcmNativeNotificationAsync(message); break; case PushMessage.PushType.Apple: await pushHub.SendAppleNativeNotificationAsync(message); break; case PushMessage.PushType.Windows: await pushHub.SendWindowsNativeNotificationAsync(message); break; case PushMessage.PushType.WindowsPhone: await pushHub.SendWindowsNativeNotificationAsync(message); break; } } catch (Exception ex) { } } } }
static async Task MainAsync(string[] args) { char direction = '-'; try { IMobileServiceTable <NightScoutReading> table = MobileService.GetTable <NightScoutReading>(); //NightScoutReading reading = await table.LookupAsync("5484f78529b19f32387ffa07"); //Console.WriteLine(reading.sgv); //Console.Read(); List <NightScoutReading> items = await table.Where(O => O.type == "sgv").OrderByDescending(O => O.date).ToListAsync(); if (items[0].direction.ToLower().Contains("up")) { direction = '\x25B2'; } else if (items[0].direction.ToLower().Contains("down")) { direction = '\x25BC'; } string notification = String.Format("Current bg: {0} Trend: {1}", items[0].sgv, direction.ToString()); NotificationHubClient hub = NotificationHubClient.CreateClientFromConnectionString("Endpoint=sb://nightscoutmobilehub-ns.servicebus.windows.net/;SharedAccessKeyName=DefaultFullSharedAccessSignature;SharedAccessKey=xl1zRhF0EKmoZdkHdvzGT+RCx7YpzGopDnRjrDpp6QA=", "nightscoutmobilehub"); var toast = @"<toast><visual><binding template=""ToastText01""><text id=""1"">" + notification + "</text></binding></visual></toast>"; await hub.SendWindowsNativeNotificationAsync(toast); } catch (MobileServiceInvalidOperationException ex) { Console.WriteLine(ex.Request); Console.WriteLine(ex.Response); } Console.Read(); }
// POST tables/TodoItem public async Task <IHttpActionResult> PostTodoItem(TodoItem item) { var asparams = new AzureStorageParams { ContainerName = item.ContainerName, ResourceName = item.ResourceName }; await SetTodoItemForImageUpload(asparams); item.SasQueryString = asparams.SasQueryString; item.AzureImageUri = asparams.AzureImageUri; item.ImageUploadPending = false; // Complete the insert operation. TodoItem current = await InsertAsync(item); // get Notification Hubs credentials associated with this Mobile App MobileAppSettingsDictionary settings = this.Configuration.GetMobileAppSettingsProvider().GetMobileAppSettings(); string notificationHubName = settings.NotificationHubName; string notificationHubConnection = settings.Connections[MobileAppSettingsKeys.NotificationHubConnectionString].ConnectionString; // connect to notification hub NotificationHubClient Hub = NotificationHubClient.CreateClientFromConnectionString(notificationHubConnection, notificationHubName); // windows payload var windowsToastPayload = @"<toast><visual><binding template=""ToastText01""><text id=""1"">" + item.Title + @"</text></binding></visual></toast>"; await Hub.SendWindowsNativeNotificationAsync(windowsToastPayload); return(CreatedAtRoute("Tables", new { id = current.Id }, current)); }
// POST api/notification public async Task <HttpResponseMessage> Get([FromUri] string message) { // below format is used for only plain message. //string payloadMessage = String.Format(@"<toast><visual><binding template=""ToastText01""><text id=""1"">{0}</text></binding></visual></toast>", message); // below format is used for toast with action buttons. string payloadMessage = String.Format(@"<toast launch=""1""><visual><binding template=""ToastGeneric""> <text id=""1"">Dear customer, Get {0} if you come visit us today ! Best Regards from our team.</text> </binding></visual> <actions> <action activationType=""foreground"" content=""Yes I will !"" arguments=""Yes""/> <action activationType=""background"" content=""No thanks."" arguments=""No""/> </actions> </toast>", message); var connectionString = ConfigurationManager.AppSettings["NotificationHubConnectionString"]; var notificationHubName = ConfigurationManager.AppSettings["NotificationHubName"]; NotificationHubClient hub = NotificationHubClient.CreateClientFromConnectionString(connectionString, notificationHubName); var result = await hub.SendWindowsNativeNotificationAsync(payloadMessage); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK); response.Content = new StringContent("Success"); return(response); }
public async Task <W8PushTestEntity> PostW8PushTestEntity(W8PushTestEntity item) { var settings = this.Configuration.GetServiceSettingsProvider().GetServiceSettings(); string notificationHubName = settings.NotificationHubName; string notificationHubConnection = settings.Connections[ServiceSettingsKeys.NotificationHubConnectionString].ConnectionString; NotificationHubClient nhClient = NotificationHubClient.CreateClientFromConnectionString(notificationHubConnection, notificationHubName); NotificationOutcome pushResponse = null; switch (item.NHNotificationType) { case "wns": pushResponse = await nhClient.SendWindowsNativeNotificationAsync(item.Payload); break; case "apns": pushResponse = await nhClient.SendAppleNativeNotificationAsync(item.Payload); break; default: throw new NotImplementedException("Push is not supported on this platform"); } this.Configuration.Services.GetTraceWriter().Info("Push sent: " + pushResponse, this.Request); return(new W8PushTestEntity() { Id = "1", PushResponse = pushResponse.State.ToString() + "-" + pushResponse.TrackingId, }); }
/// <summary> /// dispatch the notifications to the subscribers. /// The NotificationHub takes care of all the plumbing that has to do with authenticating the client, managing subscriptions and so on. /// </summary> public static void DispatchNotification(ToastNotificationBase notification) { Parallel.ForEach<int> (notification.TargetClientDevices, (travelerId) => client.SendWindowsNativeNotificationAsync(notification.GetNotificationXML(), $"user-{travelerId}"); }
private static async Task SendWindowsNotificationAsync(string msg) { NotificationHubClient hub = NotificationHubClient .CreateClientFromConnectionString(nhConnectionString, hubName); var toast = $"<toast launch=\"launch_arguments\"><visual><binding template=\"ToastText01\"><text id=\"1\">{msg}</text></binding></visual></toast>"; var results = await hub.SendWindowsNativeNotificationAsync(toast); }
private static async void SendNotificationAsync(string BlobName) { NotificationHubClient hub = NotificationHubClient .CreateClientFromConnectionString("Endpoint=sb://smarthomenamespace.servicebus.windows.net/;SharedAccessKeyName=DefaultFullSharedAccessSignature;SharedAccessKey=+nY8fngDiGjuWma5CTi3KxEUV/jwyE9GAxv7Nrf4FW0=", "SmartHomeNotificationHub"); var toast = @"<toast><visual><binding template=""ToastText01""><text id=""1"">New Visitor at your House!! Please Check " + BlobName + "</text></binding></visual></toast>"; await hub.SendWindowsNativeNotificationAsync(toast); }
public static async void SendNotification(string message, List <NotificationType> types) { NotificationHubClient hub = NotificationHubClient.CreateClientFromConnectionString(Setting.HUB_Path, Setting.HUB_Name); foreach (var t in types) { var notification = NotificationMessage.SetNotification(t, message); switch (t) { case NotificationType.FCM: await hub.SendFcmNativeNotificationAsync(notification); break; case NotificationType.WND: await hub.SendWindowsNativeNotificationAsync(notification); break; default: await hub.SendFcmNativeNotificationAsync(notification); break; } } }
private static async void SendNotificationAsync() { NotificationHubClient hub = NotificationHubClient .CreateClientFromConnectionString("<connection string with full access>", "<hub name>"); var toast = @"<toast><visual><binding template=""ToastText01""><text id=""1"">Hello from a .NET App!</text></binding></visual></toast>"; await hub.SendWindowsNativeNotificationAsync(toast); }
private static async void SendNotificationAsync() { NotificationHubClient hub = NotificationHubClient .CreateClientFromConnectionString("Endpoint=sb://fitness30.servicebus.windows.net/;SharedAccessKeyName=DefaultFullSharedAccessSignature;SharedAccessKey=AgLQYes5cAlieEvcJLlGYxt2wLDGbJh5vksTmAZqZNc=", "Fitness30"); var toast = @"<toast><visual><binding template=""ToastText01""><text id=""1"">Testing Fitness30 Notifications!</text></binding></visual></toast>"; await hub.SendWindowsNativeNotificationAsync(toast); }
private static async void SendNotificationAsync() { NotificationHubClient hub = NotificationHubClient.CreateClientFromConnectionString(connectionstring, path); var toast = @"<toast><visual><binding template=""ToastText01""><text id=""1"">Hello, World</text></binding></visual></toast>"; await hub.SendWindowsNativeNotificationAsync(toast); }
public async Task <IActionResult> Send(NotificationRequest request) { if (request.Message is SimpleNotificationMessage simpleMessage) { foreach (var message in simpleMessage.GetPlatformMessages()) { switch (message.Item1) { case "wns": await _hub.SendWindowsNativeNotificationAsync(message.Item2, $"username:{request.Destination}"); break; case "aps": await _hub.SendAppleNativeNotificationAsync(message.Item2, $"username:{request.Destination}"); break; case "fcm": await _hub.SendFcmNativeNotificationAsync(message.Item2, $"username:{request.Destination}"); break;; } } } else if (request.Message is TemplateNotificationMessage templateMessage) { await _hub.SendTemplateNotificationAsync(templateMessage.Parameters, $"username:{request.Destination}"); } return(Ok()); }
private static async Task PushMessagesToHub(CancellationToken ct) { while (true) { if (ct.IsCancellationRequested) { break; } try { PushMessage msgObject = msgSendQueue.Take(); if (msgObject == null) { continue; } string message = msgObject.ToString(); switch (msgObject.Type) { case PushMessage.PushType.Android: await _client.SendGcmNativeNotificationAsync(message); break; case PushMessage.PushType.Apple: await _client.SendAppleNativeNotificationAsync(message); break; case PushMessage.PushType.Windows: await _client.SendWindowsNativeNotificationAsync(message); break; case PushMessage.PushType.WindowsPhone: await _client.SendWindowsNativeNotificationAsync(message); break; } } catch (Exception ex) { } } }
private static async void aSendNotificationAsync(string tag) { string conf = ConfigurationManager.AppSettings["Microsoft.Azure.NotificationHubs.ConnectionString"]; NotificationHubClient hub = NotificationHubClient.CreateClientFromConnectionString("Endpoint=sb://hmihub.servicebus.windows.net/;SharedAccessKeyName=DefaultFullSharedAccessSignature;SharedAccessKey=YiwRli3oMZ8kPnd/U6PranONOG/uXaQSF0aqnRZncPM=", "emeahminofificationhub"); var toast = @"<toast><visual><binding template=""ToastText01""><text id=""1"">Hello from a .NET App!</text></binding></visual></toast>"; //await hub.SendWindowsNativeNotificationAsync(toast,"myTag"); await hub.SendWindowsNativeNotificationAsync(toast, tag); }
private static async void SendNotificationsAsync() { NotificationHubClient hub = NotificationHubClient.CreateClientFromConnectionString("Endpoint=sb://notificationhub-namespace.servicebus.windows.net/;SharedAccessKeyName=DefaultFullSharedAccessSignature;SharedAccessKey=LUFP4WKE4y7TRR/r8BJpuWjOARzd2t8w2FGb7KYIpl8=", "notificationhub"); var toast = @"<toast><visual><binding template=""ToastText01""><text id=""1"">Hello from a .NET App!</text></binding></visual></toast>"; await hub.SendWindowsNativeNotificationAsync(toast); }
private async Task SendPushNotification(string notification) { string NHConnection = this.Services.Settings.Connections["NHConnectionString"].ConnectionString; string NHPath = this.Services.Settings["NHPath"].ToString(); NotificationHubClient hub = NotificationHubClient.CreateClientFromConnectionString(NHConnection, NHPath); var toast = @"<toast><visual><binding template=""ToastText01""><text id=""1"">" + notification + "</text></binding></visual></toast>"; await hub.SendWindowsNativeNotificationAsync(toast); }
static async Task SendNotificationAsync(SimpleModel model) { NotificationHubClient hub = NotificationHubClient .CreateClientFromConnectionString("Endpoint=sb://cincyazure.servicebus.windows.net/;SharedAccessKeyName=DefaultFullSharedAccessSignature;SharedAccessKey=HDCgcWXf9CLsdmgvnNzfSqy66ZRLC++E07yzG1BRxkg=", "CincyAzure"); var toast = @"<toast><visual><binding template=""ToastText01""><text id=""1"">The report you requested has been processed and is now available for viewing!</text></binding></visual></toast>"; await hub.SendWindowsNativeNotificationAsync(toast, "Azure"); }
private static async void SendNotificationasync(string str) { NotificationHubClient hub = NotificationHubClient .CreateClientFromConnectionString( "Endpoint=sb://rpi-notification.servicebus.windows.net/;SharedAccessKeyName=DefaultFullSharedAccessSignature;SharedAccessKey=ab0WkZXESky6bjp8CI+1XtlYTQFxWNQOPOoTd1Uks7A=" , "Windows-iot"); var toast = $@"<toast><visual><binding template=""ToastText01""><text id=""1"">{str}</text></binding></visual></toast>"; await hub.SendWindowsNativeNotificationAsync(toast); }
private static async void SendNotificationAsync() { NotificationHubClient hub = NotificationHubClient.CreateClientFromConnectionString( "Endpoint=sb://chinesenotificationhub-ns.servicebus.windows.net/;SharedAccessKeyName=DefaultFullSharedAccessSignature;SharedAccessKey=jsuZEDY9/7isT/pCdJTEYNEiTQXd4MCy6yY912xyMF4=", "chinesenotificationhub"); var toast = @"<toast><visual><binding template=""ToastImageAndText01""><image id=""1"" src=""http://kiewic.com/Content/Home/Icons/favicon.png"" alt=""image1""/><text id=""1"">你聞起來像醬油</text></binding></visual></toast>"; await hub.SendWindowsNativeNotificationAsync(toast); autoResetEvent.Set(); }
static async Task MainAsync(string hubConnectionString, string hubName) { NotificationHubClient hub = NotificationHubClient.CreateClientFromConnectionString(hubConnectionString, hubName); string toast = @"<toast><visual><binding template=""ToastText01""><text id=""1"">Hello from a .NET App!</text></binding></visual></toast>"; await hub.SendWindowsNativeNotificationAsync(toast); //hub.SendAdmNativeNotificationAsync; //hub.SendAppleNativeNotificationAsync; //hub.SendBaiduNativeNotificationAsync; //hub.SendMpnsNativeNotificationAsync; }
private static void SendTaggedToast() { _hub = NotificationHubClient.CreateClientFromConnectionString(_ep, _notHubPath); string tag = Console.ReadLine(); do { _hub.SendWindowsNativeNotificationAsync(_toast,tag).Wait(); tag = Console.ReadLine(); } while (tag.CompareTo("q") != 0); }
private static async void SendNotificationAsync() { string hubName = "tlvnotificationhub"; string DefaultFullSharedAccessSignature = "Endpoint=sb://tlvnotificationnamespace.servicebus.windows.net/;SharedAccessKeyName=DefaultFullSharedAccessSignature;SharedAccessKey=kNKB0R5+nDJMgXOt6BLN5UgAorNEqc2Ax5hTJqdJVEg="; string DefaultListenSharedAccessSignature = "Endpoint=sb://tlvnotificationnamespace.servicebus.windows.net/;SharedAccessKeyName=DefaultListenSharedAccessSignature;SharedAccessKey=k/JsAgjfA8lmySBlMU4kgXAqdzMevmDRDQPA7Qs/5A0="; NotificationHubClient hub = NotificationHubClient.CreateClientFromConnectionString(DefaultFullSharedAccessSignature, hubName); var toast = @"<toast><visual><binding template=""ToastText01""><text id=""1"">Hello Gilad from a .NET App!</text></binding></visual></toast>"; await hub.SendWindowsNativeNotificationAsync(toast); }
public List <NotificationResponse> SendNotification(NotificationRequest request) { List <NotificationResponse> response = new List <NotificationResponse>(); if (request.Types != null) { foreach (var type in request.Types) { NotificationOutcome send = new NotificationOutcome(); string notification = NotificationMessage.SetNotification(type, request.Message, request.WindowsNotificationId); Exception e = null; try { switch (type) { case NotificationType.FCM: send = _hub.SendFcmNativeNotificationAsync(notification).Result; break; case NotificationType.WND: send = _hub.SendWindowsNativeNotificationAsync(notification).Result; break; default: send = _hub.SendFcmNativeNotificationAsync(notification).Result; break; } } catch (Exception ex) { e = ex; continue; } finally { response.Add(new NotificationResponse { Type = type, Success = (e == null), Error = e?.Message }); } } } return(response); }
private async Task SendNotificationAsync(string headline, string body) { NotificationHubClient hub = NotificationHubClient .CreateClientFromConnectionString(ConnectionString, HubName); var toast = string.Format(@" <toast><visual> <binding template=""ToastText02""> <text id=""1"">{0}</text> <text id=""2"">{1}</text> </binding> </visual></toast>", headline, body); await hub.SendWindowsNativeNotificationAsync(toast); }
private static void SendSimpleToast() { _hub = NotificationHubClient.CreateClientFromConnectionString(_ep, _notHubPath); _hub.SendWindowsNativeNotificationAsync(_toast).Wait(); Console.ReadLine(); }