Exemple #1
0
        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);
        }
        internal static MessageReport LoadMessage(string name)
        {
            // name is wrt MessagesPath "Crittercism\Messages", e.g "Crash_<guid>"
            // path is Crittercism\Messages\name
            MessageReport messageReport = null;

            try {
                string   path      = Path.Combine(MessagesPath, name);
                string[] nameSplit = name.Split('_');
                switch (nameSplit[0])
                {
                case "AppLoad":
                    messageReport = (AppLoad)StorageHelper.Load(path, typeof(AppLoad));
                    break;

                case "APMReport":
                    messageReport = (APMReport)StorageHelper.Load(path, typeof(APMReport));
                    break;

                case "HandledException":
                    messageReport = (HandledException)StorageHelper.Load(path, typeof(HandledException));
                    break;

                case "CrashReport":
                    messageReport = (CrashReport)StorageHelper.Load(path, typeof(CrashReport));
                    break;

                case "MetadataReport":
                    messageReport = (MetadataReport)StorageHelper.Load(path, typeof(MetadataReport));
                    break;

                default:
                    // Skip this file.
                    break;
                }
                if (messageReport == null)
                {
                    // Possibly file is still being written.  Skip file for
                    // now by returning null .
                }
                else
                {
                    messageReport.Name         = name;
                    messageReport.CreationTime = StorageHelper.GetCreationTime(path);
                    messageReport.Saved        = true;
                }
            } catch (Exception ie) {
                Crittercism.LogInternalException(ie);
            }
            return(messageReport);
        }
Exemple #3
0
        private bool DidReceiveResult(MessageReport messageReport, HttpWebRequest request, IAsyncResult asyncResponse)
        {
            bool sendCompleted = true;

            try {
                DidReceiveResponse(messageReport, request, asyncResponse);
            } catch (WebException webEx) {
                DidFailWithError(webEx);
                sendCompleted = (webEx.Status != WebExceptionStatus.Success);
            } catch (Exception ex) {
                Debug.WriteLine("SendRequest: ex == " + ex.Message);
                sendCompleted = false;
            }
            return(sendCompleted);
        }
Exemple #4
0
 internal void DidReceiveResponseShared(MessageReport messageReport, HttpWebResponse response)
 {
     try {
         //Debug.WriteLine("DidReceiveResponseShared: response.StatusCode == " + (int)response.StatusCode);
         if ((((long)response.StatusCode) / 100) == 2)
         {
             // 2xx Success
             using (StreamReader reader = (new StreamReader(response.GetResponseStream()))) {
                 string responseText = reader.ReadToEnd();
                 messageReport.DidReceiveResponse(responseText);
             }
         }
     } catch (Exception ie) {
         Crittercism.LogInternalException(ie);
     }
 }
        internal static List <MessageReport> LoadMessages()
        {
            List <MessageReport> answer = new List <MessageReport>();

            if (StorageHelper.FolderExists(MessagesPath))
            {
                string[] names = StorageHelper.GetFileNames(MessagesPath);
                foreach (string name in names)
                {
                    MessageReport messageReport = LoadMessage(name);
                    if (messageReport != null)
                    {
                        answer.Add(messageReport);
                    }
                }
                answer.Sort((m1, m2) => m1.CreationTime.CompareTo(m2.CreationTime));
            }
            return(answer);
        }
Exemple #6
0
        private bool SendMessage()
        {
            //Debug.WriteLine("SendMessage: ENTER");
            bool sendCompleted = false;

            try {
                if ((Crittercism.MessageQueue != null) && (Crittercism.MessageQueue.Count > 0))
                {
                    if ((Crittercism.TestNetwork != null) || NetworkInterface.GetIsNetworkAvailable())
                    {
                        MessageReport messageReport = Crittercism.MessageQueue.Peek();
                        Debug.WriteLine("SendMessage: " + messageReport.GetType().Name);
                        Crittercism.MessageQueue.Dequeue();
                        messageReport.Delete();
                        try {
                            if (Crittercism.TestNetwork != null)
                            {
                                // This case used by UnitTest .
                                sendCompleted = Crittercism.TestNetwork.SendRequest(messageReport);
                            }
                            else
                            {
                                sendCompleted = SendRequest(messageReport);
                            }
                        } catch (Exception ie) {
                            Crittercism.LogInternalException(ie);
                        }
                        if (!sendCompleted)
                        {
                            Crittercism.MessageQueue.Enqueue(messageReport);
                        }
                    }
                }
                ;
            } catch (Exception ie) {
                Crittercism.LogInternalException(ie);
            }
            //Debug.WriteLine("SendMessage: EXIT ---> "+sendCompleted);
            return(sendCompleted);
        }
Exemple #7
0
 private void DidReceiveResponse(MessageReport messageReport, HttpWebRequest request, IAsyncResult asyncResponse)
 {
     using (HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asyncResponse)) {
         DidReceiveResponseShared(messageReport, response);
     };
 }
Exemple #8
0
        // DidReceiveResponse
#if WINDOWS_PHONE_APP
        private void DidReceiveResponse(MessageReport messageReport, HttpWebResponse response)
        {
            DidReceiveResponseShared(messageReport, response);
        }
Exemple #9
0
 public AppLoad()
 {
     appLoads = MessageReport.ComputeAppState();
 }