// SendRequest #if WINDOWS_PHONE_APP private bool SendRequest(MessageReport messageReport) { //Debug.WriteLine("SendRequest: " + messageReport.GetType().Name); bool sendCompleted = false; Debug.WriteLine("SendRequest: ENTER"); try { HttpWebRequest request = messageReport.WebRequest(); if (request != null) { string postBody = messageReport.PostBody(); Task <Stream> writerTask = request.GetRequestStreamAsync(); using (Stream stream = writerTask.Result) { SendRequestWritePostBody(stream, postBody); } Task <WebResponse> responseTask = request.GetResponseAsync(); using (HttpWebResponse response = (HttpWebResponse)responseTask.Result) { sendCompleted = DidReceiveResult(messageReport, response); } } } catch (Exception ie) { Crittercism.LogInternalException(ie); } Debug.WriteLine("SendRequest: EXIT ---> " + sendCompleted); return(sendCompleted); }
private bool SendRequest(MessageReport messageReport) { //////////////////////////////////////////////////////////////// // NOTE: sendCompleted is reported as "true" if we get back // an HTTP status code from the platform web server. It is // independent of whether or not the HTTP status code is an // HTTP status code we like. Therefore, a 500 internal server // error WILL count as sendCompleted == "true" . OTOH, if // there is no network connectivity at all (e.g. airplane mode // or out of network coverage), there is no HTTP status code, // only some WebException . We will report "false" in that case // and schedule a future retry. //////////////////////////////////////////////////////////////// //Debug.WriteLine("SendRequest: " + messageReport.GetType().Name); bool sendCompleted = true; Debug.WriteLine("SendRequest: ENTER"); try { HttpWebRequest request = messageReport.WebRequest(); if (request != null) { string postBody = messageReport.PostBody(); ManualResetEvent resetEvent = new ManualResetEvent(false); request.BeginGetRequestStream( (result) => { //Debug.WriteLine("SendRequest: BeginGetRequestStream"); try { using (Stream stream = request.EndGetRequestStream(result)) { SendRequestWritePostBody(stream, postBody); } request.BeginGetResponse( (asyncResponse) => { sendCompleted = DidReceiveResult(messageReport, request, asyncResponse); resetEvent.Set(); }, null); } catch { resetEvent.Set(); } }, null); { #if DEBUG Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); #endif resetEvent.WaitOne(); #if DEBUG stopWatch.Stop(); Debug.WriteLine("SendRequest: TOTAL SECONDS == " + stopWatch.Elapsed.TotalSeconds); #endif } } } catch (Exception ie) { Crittercism.LogInternalException(ie); } Debug.WriteLine("SendRequest: EXIT ---> " + sendCompleted); return(sendCompleted); }