Add Wox.CrashReporter

This commit is contained in:
qianlifeng
2015-01-11 21:52:30 +08:00
parent f20b4d570e
commit 5be6511529
33 changed files with 770 additions and 342 deletions

View File

@@ -0,0 +1,35 @@
using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Forms;
using System.Windows.Threading;
using Wox.Core.Exception;
using Wox.Infrastructure.Logger;
namespace Wox.Helper
{
public static class ErrorReporting
{
private static void Report(Exception e)
{
//if (Debugger.IsAttached) return;
Log.Error(ExceptionFormatter.FormatExcpetion(e));
new CrashReporter.CrashReporter(e).Show();
}
public static void UnhandledExceptionHandle(object sender, UnhandledExceptionEventArgs e)
{
Report((Exception)e.ExceptionObject);
}
public static void DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
Report(e.Exception);
}
public static void ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
{
Report(e.Exception);
}
}
}

View File

@@ -1,98 +0,0 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Forms;
using System.Windows.Threading;
using System.Xml;
using Microsoft.Win32;
using Wox.Core.Exception;
using Wox.Infrastructure.Logger;
namespace Wox.Helper.ErrorReporting
{
public static class ErrorReporting
{
public static void UnhandledExceptionHandle(object sender, System.UnhandledExceptionEventArgs e)
{
if (Debugger.IsAttached) return;
string error = ExceptionFormatter.FormatExcpetion(e.ExceptionObject);
//e.IsTerminating is always true in most times, so try to avoid use this property
//http://stackoverflow.com/questions/10982443/what-causes-the-unhandledexceptioneventargs-isterminating-flag-to-be-true-or-fal
Log.Error(error);
TryShowErrorMessageBox(error, e.ExceptionObject);
}
public static void DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
if (Debugger.IsAttached) return;
e.Handled = true;
string error = ExceptionFormatter.FormatExcpetion(e.Exception);
Log.Error(error);
TryShowErrorMessageBox(error, e.Exception);
}
public static void ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
{
if (Debugger.IsAttached) return;
string error = ExceptionFormatter.FormatExcpetion(e.Exception);
Log.Fatal(error);
TryShowErrorMessageBox(error, e.Exception);
}
public static bool TryShowErrorMessageBox(string error, object exceptionObject)
{
var title = "Wox - Unhandled Exception";
try
{
ShowWPFDialog(error, title, exceptionObject);
return true;
}
catch { }
error = "Wox has occured an error that can't be handled. " + Environment.NewLine + Environment.NewLine + error;
try
{
ShowWPFMessageBox(error, title);
return true;
}
catch { }
try
{
ShowWindowsFormsMessageBox(error, title);
return true;
}
catch { }
return true;
}
private static void ShowWPFDialog(string error, string title, object exceptionObject)
{
var dialog = new WPFErrorReportingDialog(error, title, exceptionObject);
dialog.ShowDialog();
}
private static void ShowWPFMessageBox(string error, string title)
{
System.Windows.MessageBox.Show(error, title, MessageBoxButton.OK, MessageBoxImage.Error,
MessageBoxResult.OK, System.Windows.MessageBoxOptions.None);
}
private static void ShowWindowsFormsMessageBox(string error, string title)
{
System.Windows.Forms.MessageBox.Show(error, title, MessageBoxButtons.OK,
MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
}
}
}

View File

@@ -1,9 +0,0 @@
<Window x:Class="Wox.Helper.ErrorReporting.WPFErrorReportingDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="ErrorReportingDialog" WindowStartupLocation="CenterScreen">
<DockPanel>
<TextBlock Margin="10" TextWrapping="Wrap" DockPanel.Dock="Top" Text="Wox has occured an error that can't be handled. "/>
<TextBox x:Name="tbErrorReport" IsReadOnly="True" IsUndoEnabled="False" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" />
</DockPanel>
</Window>

View File

@@ -1,32 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace Wox.Helper.ErrorReporting
{
/// <summary>
/// Interaction logic for WPFErrorReportingDialog.xaml
/// </summary>
public partial class WPFErrorReportingDialog : Window
{
private object exceptionObject;
public WPFErrorReportingDialog(string error, string title, object exceptionObject)
{
InitializeComponent();
this.tbErrorReport.Text = error;
this.Title = title;
this.exceptionObject = exceptionObject;
}
}
}

View File

@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace Wox.Helper
{
public class WoxLog4netPathConverter : log4net.Util.PatternConverter
{
protected override void Convert(TextWriter writer, object state)
{
string userProfilePath = Environment.GetEnvironmentVariable("USERPROFILE");
writer.Write(Path.Combine(userProfilePath, ".Wox"));
}
}
}