Пример #1
0
        void responseCallback(IAsyncResult result)
        {
            var asyncParam = result.AsyncState as GcmAsyncParameters;

            try
            {
                try
                {
                    asyncParam.WebResponse = asyncParam.WebRequest.EndGetResponse(result) as HttpWebResponse;
                    processResponseOk(asyncParam);
                }
                catch (WebException wex)
                {
                    asyncParam.WebResponse = wex.Response as HttpWebResponse;
                    processResponseError(asyncParam);
                }
            }
            catch (Exception ex)
            {
                //Raise individual failures for each registration id for the notification
                foreach (var r in asyncParam.Message.RegistrationIds)
                {
                    asyncParam.Callback(this, new SendNotificationResult(GcmNotification.ForSingleRegistrationId(asyncParam.Message, r), false, ex));
                }

                Interlocked.Decrement(ref waitCounter);
            }
        }
Пример #2
0
        void transport_UnhandledException(GcmNotification notification, Exception exception)
        {
            //Raise individual failures for each registration id for the notification
            foreach (var r in notification.RegistrationIds)
            {
                this.Events.RaiseNotificationSendFailure(GcmNotification.ForSingleRegistrationId(notification, r),
                                                         exception);
            }

            this.Events.RaiseChannelException(exception, PlatformType.AndroidGcm, notification);

            Interlocked.Decrement(ref waitCounter);
        }
Пример #3
0
        void requestStreamCallback(IAsyncResult result)
        {
            var asyncParam = result.AsyncState as GcmAsyncParameters;

            try
            {
                if (asyncParam != null)
                {
                    var wrStream = asyncParam.WebRequest.EndGetRequestStream(result);

                    using (var webReqStream = new StreamWriter(wrStream))
                    {
                        var data = asyncParam.Message.GetJson();
                        webReqStream.Write(data);
                        webReqStream.Close();
                    }

                    try
                    {
                        asyncParam.WebRequest.BeginGetResponse(new AsyncCallback(responseCallback), asyncParam);
                    }
                    catch (WebException wex)
                    {
                        asyncParam.WebResponse = wex.Response as HttpWebResponse;
                        processResponseError(asyncParam);
                    }
                }
            }
            catch (Exception ex)
            {
                //Raise individual failures for each registration id for the notification
                foreach (var r in asyncParam.Message.RegistrationIds)
                {
                    asyncParam.Callback(this, new SendNotificationResult(GcmNotification.ForSingleRegistrationId(asyncParam.Message, r), false, ex));
                }

                Interlocked.Decrement(ref waitCounter);
            }
        }