Exemplo n.º 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);
            }
        }
Exemplo n.º 2
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);
            }
        }