public static void ReportCrash(Exception ex, string appplicationTitle, IntPtr?handleToScreenShot = new IntPtr?(), Size?screenShotSize = new Size?(), bool messageBox = true) { lock (ReportingLock) { System.Globalization.CultureInfo TCurrent = Thread.CurrentThread.CurrentCulture; System.Globalization.CultureInfo UICurrent = Thread.CurrentThread.CurrentUICulture; System.Globalization.CultureInfo enUS = new System.Globalization.CultureInfo("en-US"); Thread.CurrentThread.CurrentCulture = enUS; Thread.CurrentThread.CurrentUICulture = enUS; ReportCrashToGitHub(ex, appplicationTitle, handleToScreenShot, screenShotSize, messageBox); Thread.CurrentThread.CurrentCulture = TCurrent; Thread.CurrentThread.CurrentUICulture = UICurrent; return; } Func <string, bool> predicate = null; Attachment attachment = null; if (handleToScreenShot.HasValue) { Bitmap windowImage = CaptureScreen.GetWindowImage(handleToScreenShot.Value); Bitmap bitmap2 = PixelTools.FixedSize(windowImage, screenShotSize.Value.Width, screenShotSize.Value.Height); MemoryStream stream = new MemoryStream(); bitmap2.Save(stream, ImageFormat.Jpeg); stream.Position = 0L; bitmap2.Dispose(); windowImage.Dispose(); attachment = new Attachment(stream, "snapshot.jpg"); } string dns = Dns.GetHostName(); string body = ((("Computer: " + dns) + "\n\n" + ex.Message) + "\n\n" + "Main Exception") + "\n" + ex.StackTrace; Exception innerException = ex.InnerException; for (int i = 1; innerException != null; i++) { body = ((body + "\n\n") + "Inner Exception #" + i) + "\n" + innerException.StackTrace; innerException = innerException.InnerException; } if (messageBox) { DialogResult result = MessageBox.Show("An unexpected error has occurred. This problem has been reported. Would you like to help debug this problem?", "Unexpected Crash", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2); if (predicate == null) { predicate = f => f.ToLower() == dns.ToLower(); } if (blacklistedHosts.FirstOrDefault <string>(predicate) != null) { return; } if (result == DialogResult.Yes) { string str2 = ""; if (InputBox(appplicationTitle + ": Crash Report", "Enter an email where you can be contacted at.", ref str2) == DialogResult.OK) { body = "Contact Email: " + str2 + "\n\n" + body; } } } SendEmail(appplicationTitle + ": Crash Report", body, attachment); }
public static void ReportCrash(Exception ex, string appplicationTitle, IntPtr?handleToScreenShot = null, Size?screenShotSize = null, bool messageBox = true) { Attachment attachment = null; if (handleToScreenShot != null) { Bitmap snapshotOriginal = CaptureScreen.GetWindowImage(handleToScreenShot.Value); Bitmap snapshot = PixelTools.FixedSize(snapshotOriginal, screenShotSize.Value.Width, screenShotSize.Value.Height); MemoryStream ms = new MemoryStream(); snapshot.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); ms.Position = 0; snapshot.Dispose(); snapshotOriginal.Dispose(); attachment = new Attachment(ms, "snapshot.jpg"); } string dns = Dns.GetHostName(); string crashReport = "Computer: " + dns; crashReport += "\n\n"; crashReport += ex.Message; crashReport += "\n\n"; crashReport += "Main Exception"; crashReport += "\n"; crashReport += ex.StackTrace; Exception innerException = ex.InnerException; for (int i = 1; innerException != null; i++) { crashReport += "\n\n"; crashReport += "Inner Exception #" + i; crashReport += "\n"; crashReport += innerException.StackTrace; innerException = innerException.InnerException; } if (messageBox == true) { DialogResult result = MessageBox.Show("An unexpected error has occursed. This problem has been reported. Would you like to help debug this problem?", "Unexpected Crash", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2); bool isBlackedListed = blacklistedHosts.FirstOrDefault(f => f.ToLower() == dns.ToLower()) != null; if (isBlackedListed == true) { return; } if (result == DialogResult.Yes) { string email = ""; result = InputBox(appplicationTitle + ": Crash Report", "Enter an email where you can be contacted at.", ref email); if (result == DialogResult.OK) { crashReport = "Contact Email: " + email + "\n\n" + crashReport; } } } SendEmail(appplicationTitle + ": Crash Report", crashReport, attachment); }