Пример #1
0
 public void Send(AndroidNotification msg, string googleLoginAuthorizationToken, string senderID, string applicationID)
 {
     try
     {
         send(msg, googleLoginAuthorizationToken, senderID, applicationID);
     }
     catch (Exception ex)
     {
         if (UnhandledException != null)
             UnhandledException(msg, ex);
         else
             throw ex;
     }
 }
Пример #2
0
 void transport_UnhandledException(AndroidNotification notification, Exception exception)
 {
     this.Events.RaiseChannelException(exception);
 }
Пример #3
0
        void responseCallback(IAsyncResult result)
        {
            var msg = new AndroidNotification();

            try
            {
                var asyncParam = result.AsyncState as C2dmAsyncParameters;
                msg = asyncParam.Message;

                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)
            {
                if (UnhandledException != null)
                    UnhandledException(msg, ex);
                else
                    throw ex;
            }
        }
Пример #4
0
        void send(AndroidNotification msg, string googleLoginAuthorizationToken, string senderID, string applicationID)
        {
            C2dmMessageTransportResponse result = new C2dmMessageTransportResponse();
            result.Message = msg;

            var postData = msg.GetPostData();

            var webReq = (HttpWebRequest)WebRequest.Create(C2DM_SEND_URL);
            //webReq.ContentLength = postData.Length;
            webReq.Method = "POST";
            webReq.ContentType = "application/x-www-form-urlencoded";
            webReq.UserAgent = "PushSharp (version: 1.0)";
            webReq.Headers.Add("Authorization: GoogleLogin auth=" + googleLoginAuthorizationToken);

            webReq.BeginGetRequestStream(new AsyncCallback(requestStreamCallback), new C2dmAsyncParameters()
            {
                WebRequest = webReq,
                WebResponse = null,
                Message = msg,
                GoogleAuthToken = googleLoginAuthorizationToken,
                SenderId = senderID,
                ApplicationId = applicationID
            });
        }
Пример #5
0
        void requestStreamCallback(IAsyncResult result)
        {
            var msg = new AndroidNotification();

            try
            {
                var asyncParam = result.AsyncState as C2dmAsyncParameters;
                msg = asyncParam.Message;

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

                    using (var webReqStream = new StreamWriter(wrStream))
                    {
                        var data = asyncParam.Message.GetPostData();
                        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)
            {
                if (UnhandledException != null)
                    UnhandledException(msg, ex);
                else
                    throw ex;
            }
        }