Esempio n. 1
0
        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)
                {
                }
            }
        }
Esempio n. 2
0
        /// <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}");
        }
Esempio n. 3
0
        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)
                {
                }
            }
        }