private static void DispatchNotification(int travelerId, ToastNotificationBase notification) { string clientURL; if (_subscribersMap.TryGetValue(travelerId, out clientURL)) { var url = clientURL; try { using (var client = new HttpClient()) { var request = (HttpWebRequest)WebRequest.Create(url); request.Method = "POST"; request.ContentType = "text/xml"; request.Headers = new WebHeaderCollection(); request.Headers.Add("X-WNS-Type", "wns/toast"); request.Headers.Add("Authorization", "Bearer " + _accessToken.AccessToken); string data = notification.GetNotificationXML(); byte[] notificationMessage = Encoding.Default.GetBytes(data); request.ContentLength = notificationMessage.Length; using (Stream requestStream = request.GetRequestStream()) { requestStream.Write(notificationMessage, 0, notificationMessage.Length); } var response = (HttpWebResponse)request.GetResponse(); } } catch (Exception) { } } }
/// <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}"); }
public async Task ToastNotificationManagerTest_GetToastById_KnowId_ShouldReturnNotifcation() { await Deployment.Current.Dispatcher.InvokeAsync(() => { // Arrange Grid rootGrid = new Grid(); ToastNotificationManager manager = new ToastNotificationManager(rootGrid); ToastNotificationBase notification1 = new SimpleToastNotification(); manager.Enqueue(notification1); manager.Enqueue(new SimpleToastNotification() { Id = "TestId", Title = "success" }); // Act ToastNotificationBase toast = manager.GetToastById("TestId"); // Assert Assert.IsNotNull(toast); Assert.IsInstanceOfType(toast, typeof(SimpleToastNotification)); SimpleToastNotification notification = toast as SimpleToastNotification; Assert.AreSame("success", notification.Title); return(null); }); }
/// <summary> /// dispatch the notifications to the subscribers. /// </summary> private static void DispatchNotifications() { while (true) { _waitHandle.WaitOne(); ToastNotificationBase notification = _notificationsQueue.Take(); Parallel.ForEach <string> (notification.TargetClientDevices, (deviceID) => DispatchNotification(deviceID, notification)); } }
public async Task ToastNotificationManagerTest_GetToastById_UnknownId_ShouldReturnNull() { await Deployment.Current.Dispatcher.InvokeAsync(() => { // Arrange Grid rootGrid = new Grid(); ToastNotificationManager manager = new ToastNotificationManager(rootGrid); ToastNotificationBase notification1 = new SimpleToastNotification(); manager.Enqueue(notification1); // Act ToastNotificationBase toast = manager.GetToastById("newTag"); // Assert Assert.IsNull(toast); return(null); }); }
private static void DispatchNotification(string deviceID, ToastNotificationBase notification) { string clientURL; if (_subscribersMap.TryGetValue(deviceID, out clientURL)) { string response; try { using (var client = new WebClient()) { client.Headers.Add("Content-Type", "text/xml"); client.Headers.Add("X-WNS-Type", "wns/toast"); client.Headers[HttpRequestHeader.Authorization] = string.Format("Bearer {0}", HttpUtility.UrlEncode(_accessToken.AccessToken)); response = client.UploadString(clientURL, notification.GetNotificationXML()); } } catch (Exception) { } } }
/// <summary> /// dispatch the notifications to the subscribers. /// </summary> public static void DispatchNotification(ToastNotificationBase notification) { Parallel.ForEach <int> (notification.TargetClientDevices, (travelerId) => DispatchNotification(travelerId, notification)); }
public static void EnqueueNotifications(ToastNotificationBase notification) { _notificationsQueue.Add(notification); }