/// <summary> /// Call the web service function with an Xml payload to add a crash to the database. /// </summary> /// <param name="Payload">Xml representation of a new crash to upload.</param> /// <returns>The database id of the newly added row.</returns> private int UploadCrash(string Payload) { int NewID = -1; try { // Simple suppression by blanking out the URL for local testing if (Config.Default.CrashReportWebSite.Length > 0) { bool bDebug = false; string RequestString; if (!bDebug) { RequestString = "http://" + Config.Default.CrashReportWebSite + ":80/Crashes/AddCrash/-1"; } else { RequestString = "http://localhost:80/Crashes/AddCrash/-1"; } string ErrorMessage = string.Empty; for (int Retry = 0; Retry < 3; ++Retry) { string ResponseString = SimpleWebRequest.GetWebServiceResponse(RequestString, Payload); if (ResponseString.Length > 0) { // Convert response into a string CrashReporterResult Result = XmlHandler.FromXmlString <CrashReporterResult>(ResponseString); if (Result.ID > 0) { NewID = Result.ID; break; } ErrorMessage = Result.Message; } Thread.Sleep(200); } if (NewID == -1) { CrashReporterProcessServicer.WriteFailure(string.Format("PROC-{0} ", ProcessorIndex) + "UploadCrash: " + ErrorMessage); } } } catch (Exception Ex) { CrashReporterProcessServicer.WriteException(string.Format("PROC-{0} ", ProcessorIndex) + "UploadCrash: " + Ex.ToString()); } return(NewID); }
static private void Main(string[] Arguments) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); // Create a new instance of the window (which may not be shown) RegisterPII Instance = new RegisterPII(); // Check to see if we should hide the window bool bShowWindow = true; if (Arguments.Length > 0) { if (Arguments[0].ToLower() == "/silent") { bShowWindow = false; } } // Display the window if it isn't hidden if (bShowWindow) { // Show the dialog Instance.Show(); Application.DoEvents(); } // Send the info to the server string WebRequest = "http://" + Properties.Settings.Default.CrashReportWebSite + ":80/Crashes/RegisterPII/" + Environment.UserName + "/" + Environment.MachineName + "/" + Instance.MachineIDString; SimpleWebRequest.GetWebServiceResponse(WebRequest, null); // Display the window for 5 seconds DateTime StartTime = DateTime.UtcNow; while (DateTime.UtcNow < StartTime.AddSeconds(5)) { Application.DoEvents(); Thread.Sleep(50); } Instance.Close(); }
/// <summary> /// Call the web service function with an Xml payload to add a crash to the database. /// </summary> /// <param name="Payload">Xml representation of a new crash to upload.</param> /// <returns>The database id of the newly added row.</returns> private int UploadCrash(string Payload) { int NewID = -1; try { // Simple suppression by blanking out the URL for local testing if (Properties.Settings.Default.CrashReportWebSite.Length > 0) { bool bDebug = false; string RequestString; if (!bDebug) { RequestString = "http://" + Properties.Settings.Default.CrashReportWebSite + ":80/Crashes/AddCrash/-1"; } else { RequestString = "http://localhost:80/Crashes/AddCrash/-1"; } string ResponseString = SimpleWebRequest.GetWebServiceResponse(RequestString, Payload); if (ResponseString.Length > 0) { // Convert response into a string CrashReporterResult Result = XmlHandler.FromXmlString <CrashReporterResult>(ResponseString); if (Result.ID > 0) { NewID = Result.ID; } else { CrashReporterProcessServicer.WriteFailure("UploadCrash: " + Result.Message); } } } } catch (Exception Ex) { CrashReporterProcessServicer.WriteException("UploadCrash: " + Ex.ToString()); } return(NewID); }
/// <summary> /// Call the web service function with an Xml payload to add a crash to the database. /// </summary> /// <param name="Payload">Xml representation of a new crash to upload.</param> /// <returns>The database id of the newly added row.</returns> private int UploadCrash(string Payload) { int NewID = -1; try { // Simple suppression by blanking out the URL for local testing if (Config.Default.CrashReportWebSite.Length > 0) { bool bDebug = false; string RequestString; if (!bDebug) { RequestString = "http://" + Config.Default.CrashReportWebSite + ":80/Crashes/AddCrash/-1"; } else { RequestString = "http://localhost:80/Crashes/AddCrash/-1"; } Action <UploadRetryState> TryUpload = InRetryState => { string ResponseString = SimpleWebRequest.GetWebServiceResponse(RequestString, Payload, Config.Default.AddCrashRequestTimeoutSeconds * 1000); if (ResponseString.Length > 0) { // Convert response into a string CrashReporterResult Result = XmlHandler.FromXmlString <CrashReporterResult>(ResponseString); if (!Result.bSuccess || Result.ID <= 0) { if (Result.bTimeout) { // Website responded - website->DB connection timeout InRetryState.Timeouts++; } else { // Website responded - fail condition InRetryState.BadResponses++; CrashReporterProcessServicer.WriteEvent(string.Format("PROC-{0} UploadCrash response invalid. FailedResponses={1} Response={2}", ProcessorIndex, InRetryState.BadResponses, Result.Message)); if (InRetryState.BadResponses > Config.Default.AddCrashRejectedRetries) { InRetryState.bShouldRetry = false; CrashReporterProcessServicer.WriteEvent(string.Format("PROC-{0} UploadCrash abandoned. FailedResponses={1}", ProcessorIndex, InRetryState.BadResponses)); } } } else { // Website responded - success NewID = Result.ID; InRetryState.bUploaded = true; return; } } else { // No response InRetryState.Timeouts++; } InRetryState.bUploaded = false; }; Action <UploadRetryState> OnRetry = InRetryState => { if (!InRetryState.bUploaded) { Thread.Sleep(Config.Default.AddCrashRetryDelaySeconds * 1000); CrashReporterProcessServicer.WriteEvent(string.Format("PROC-{0} UploadCrash retrying upload. Timeouts={1} FailedResponses={2}", ProcessorIndex, InRetryState.Timeouts, InRetryState.BadResponses)); } }; UploadRetryState RetryState = new UploadRetryState(); for (; !RetryState.bUploaded && RetryState.bShouldRetry && !CancelSource.IsCancellationRequested; OnRetry(RetryState)) { TryUpload(RetryState); CrashReporterProcessServicer.StatusReporter.AlertOnConsecutiveFails("AddCrash", "Cannot contact CR website. CRP is paused!", "Contact with CR website restored.", TimeSpan.FromSeconds(Config.Default.FailedWebAddAlertTimeSeconds), RetryState.bUploaded); } } #if DEBUG else { // No website set - simulate successful upload var Rnd = new Random(); NewID = Rnd.Next(1, 99999999); } #endif } catch (Exception Ex) { CrashReporterProcessServicer.WriteException(string.Format("PROC-{0} ", ProcessorIndex) + "UploadCrash: " + Ex, Ex); } return(NewID); }
/// <summary> /// Call the web service function with an Xml payload to add a crash to the database. /// </summary> /// <param name="Payload">Xml representation of a new crash to upload.</param> /// <returns>The database id of the newly added row.</returns> private int UploadCrash(string Payload) { int NewID = -1; try { // Simple suppression by blanking out the URL for local testing if (Config.Default.CrashReportWebSite.Length > 0) { bool bDebug = false; string RequestString; if (!bDebug) { RequestString = "http://" + Config.Default.CrashReportWebSite + ":80/Crashes/AddCrash/-1"; } else { RequestString = "http://localhost:80/Crashes/AddCrash/-1"; } string ErrorMessage = string.Empty; const int MaxRetries = 1; for (int AddCrashTry = 0; AddCrashTry < MaxRetries + 1; ++AddCrashTry) { string ResponseString = SimpleWebRequest.GetWebServiceResponse(RequestString, Payload, Config.Default.AddCrashRequestTimeoutMillisec); if (ResponseString.Length > 0) { // Convert response into a string CrashReporterResult Result = XmlHandler.FromXmlString <CrashReporterResult>(ResponseString); if (Result.ID > 0) { NewID = Result.ID; break; } CrashReporterProcessServicer.WriteEvent(string.Format("PROC-{0} UploadCrash response timeout (attempt {1} of {2}): {3}", ProcessorIndex, AddCrashTry + 1, MaxRetries + 1, ErrorMessage)); ErrorMessage = Result.Message; } Thread.Sleep(Config.Default.AddCrashRetryDelayMillisec); } if (NewID == -1) { CrashReporterProcessServicer.WriteFailure(string.Format("PROC-{0} ", ProcessorIndex) + "UploadCrash failed: " + ErrorMessage); } } #if DEBUG else { // No website set - simulate successful upload var Rnd = new Random(); NewID = Rnd.Next(1, 99999999); } #endif } catch (Exception Ex) { CrashReporterProcessServicer.WriteException(string.Format("PROC-{0} ", ProcessorIndex) + "UploadCrash: " + Ex, Ex); } return(NewID); }
/// <summary> /// Call the web service function with an Xml payload to add a crash to the database. /// </summary> /// <param name="Payload">Xml representation of a new crash to upload.</param> /// <returns>The database id of the newly added row.</returns> private int UploadCrash(string Payload) { int NewID = -1; try { // Simple suppression by blanking out the URL for local testing if (Config.Default.CrashReportWebSite.Length > 0) { bool bDebug = false; string RequestString; if (!bDebug) { RequestString = "http://" + Config.Default.CrashReportWebSite + ":80/Crashes/AddCrash/-1"; } else { RequestString = "http://localhost:80/Crashes/AddCrash/-1"; } int Attempt = 1; Func <bool> TryUpload = () => { string ResponseString = SimpleWebRequest.GetWebServiceResponse(RequestString, Payload, Config.Default.AddCrashRequestTimeoutSeconds * 1000); if (ResponseString.Length > 0) { // Convert response into a string CrashReporterResult Result = XmlHandler.FromXmlString <CrashReporterResult>(ResponseString); if (Result.ID > 0) { NewID = Result.ID; return(true); } CrashReporterProcessServicer.WriteEvent(string.Format("PROC-{0} UploadCrash response invalid (upload attempt {1}): {2}", ProcessorIndex, Attempt, Result.Message)); } return(false); }; Action <bool> OnRetry = bUploaded => { if (!bUploaded) { Thread.Sleep(Config.Default.AddCrashRetryDelaySeconds * 1000); CrashReporterProcessServicer.WriteEvent(string.Format("PROC-{0} UploadCrash retrying upload attempt {1}", ProcessorIndex, Attempt)); Attempt++; } }; for (bool bUploaded = false; !bUploaded; OnRetry(bUploaded)) { bUploaded = TryUpload(); CrashReporterProcessServicer.StatusReporter.AlertOnConsecutiveFails("AddCrash", "Cannot contact CR website. CRP is paused!", "Contact with CR website restored.", TimeSpan.FromSeconds(Config.Default.FailedWebAddAlertTimeSeconds), bUploaded); } } #if DEBUG else { // No website set - simulate successful upload var Rnd = new Random(); NewID = Rnd.Next(1, 99999999); } #endif } catch (Exception Ex) { CrashReporterProcessServicer.WriteException(string.Format("PROC-{0} ", ProcessorIndex) + "UploadCrash: " + Ex, Ex); } return(NewID); }