Example #1
0
        public virtual async Task SendNotificationsAsync(PusherQueue queueToProcess)
        {
            bool success = false;

            try
            {
                await Task.Delay(TimeSpan.FromMinutes((double)queueToProcess.FailureCount));

                this.IncrementInTransit();
                PusherQueuePayload[] payloads   = queueToProcess.GetPayloads();
                HttpWebRequest       webRequest = (HttpWebRequest)WebRequest.Create(new Uri(queueToProcess.DestinationUrl));
                webRequest.PreAuthenticate = true;
                CertificateValidationManager.SetComponentId(webRequest, "RemoteNotification");
                webRequest.ContentType = "text/plain";
                webRequest.Method      = "POST";
                DateTime pushTime = DateTime.UtcNow;
                await RemoteNotificationRequester.SendRequest(webRequest, RemoteNotificationRequester.GeneratePayload(payloads), queueToProcess.DestinationUrl, payloads.Length);

                await RemoteNotificationRequester.ReceiveResponseAsync(webRequest);

                success = true;
                IEnumerable <NotificationPayloadBase> payloadsToBePushed = from p in payloads
                                                                           select p.Payload;
                NotificationStatisticsManager.Instance.NotificationPushed(queueToProcess.DestinationUrl, payloadsToBePushed, pushTime);
            }
            catch (WebException webException)
            {
                RemoteNotificationRequester.HandleWebException(webException, queueToProcess);
            }
            finally
            {
                queueToProcess.SendComplete(success);
                this.DecrementInTransit();
            }
        }
Example #2
0
        private static async Task ReceiveResponseAsync(HttpWebRequest webRequest)
        {
            StringBuilder responseBuilder;

            using (WebResponse webResponse = await webRequest.GetResponseAsync())
            {
                using (Stream responseStream = webResponse.GetResponseStream())
                {
                    responseBuilder = await BufferedStreamReader.ReadAsync(responseStream);

                    responseStream.Close();
                    webResponse.Close();
                }
            }
            RemoteNotificationRequester.ProcessResponse(responseBuilder.ToString());
        }