Skip to content

Commit

Permalink
Refactoring error report
Browse files Browse the repository at this point in the history
1. fix #627
2. fix #646
3. remove exceptionless
  • Loading branch information
bao-qian committed May 20, 2016
1 parent 7767539 commit b9145aa
Show file tree
Hide file tree
Showing 11 changed files with 143 additions and 139 deletions.
7 changes: 4 additions & 3 deletions Wox.Infrastructure/Logger/Log.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ namespace Wox.Infrastructure.Logger
{
public static class Log
{
public const string DirectoryName = "Logs";

static Log()
{
var directoryName = "Logs";
var path = Path.Combine(Constant.DataDirectory, directoryName, Constant.Version);
var path = Path.Combine(Constant.DataDirectory, DirectoryName, Constant.Version);
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
Expand All @@ -21,7 +22,7 @@ static Log()
var configuration = new LoggingConfiguration();
var target = new FileTarget();
configuration.AddTarget("file", target);
target.FileName = "${specialfolder:folder=ApplicationData}/" + Constant.Wox + "/" + directoryName + "/" + Constant.Version + "/${shortdate}.log";
target.FileName = "${specialfolder:folder=ApplicationData}/" + Constant.Wox + "/" + DirectoryName + "/" + Constant.Version + "/${shortdate}.log";
var rule = new LoggingRule("*", LogLevel.Info, target);
configuration.LoggingRules.Add(rule);
LogManager.Configuration = configuration;
Expand Down
1 change: 1 addition & 0 deletions Wox.Infrastructure/Wox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public static class Constant
public static readonly string PreinstalledDirectory = Path.Combine(ProgramDirectory, Plugins);
public static readonly string SettingsPath = Path.Combine(DataDirectory, Settings);
public const string Github = "https://github.com/Wox-launcher/Wox";
public const string Issue = "https://github.com/Wox-launcher/Wox/issues/new";
public static readonly string Version = FileVersionInfo.GetVersionInfo(Assembly.Location).ProductVersion;
}
}
14 changes: 0 additions & 14 deletions Wox.sln
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wox.Plugin.Url", "Plugins\W
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wox.Plugin.Color", "Plugins\Wox.Plugin.Color\Wox.Plugin.Color.csproj", "{F35190AA-4758-4D9E-A193-E3BDF6AD3567}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wox.CrashReporter", "Wox.CrashReporter\Wox.CrashReporter.csproj", "{2FEB2298-7653-4009-B1EA-FFFB1A768BCC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wox.Plugin.Everything", "Plugins\Wox.Plugin.Everything\Wox.Plugin.Everything.csproj", "{230AE83F-E92E-4E69-8355-426B305DA9C0}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{FFD651C7-0546-441F-BC8C-D4EE8FD01EA7}"
Expand Down Expand Up @@ -262,18 +260,6 @@ Global
{F35190AA-4758-4D9E-A193-E3BDF6AD3567}.Release|x64.Build.0 = Release|Any CPU
{F35190AA-4758-4D9E-A193-E3BDF6AD3567}.Release|x86.ActiveCfg = Release|Any CPU
{F35190AA-4758-4D9E-A193-E3BDF6AD3567}.Release|x86.Build.0 = Release|Any CPU
{2FEB2298-7653-4009-B1EA-FFFB1A768BCC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2FEB2298-7653-4009-B1EA-FFFB1A768BCC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2FEB2298-7653-4009-B1EA-FFFB1A768BCC}.Debug|x64.ActiveCfg = Debug|Any CPU
{2FEB2298-7653-4009-B1EA-FFFB1A768BCC}.Debug|x64.Build.0 = Debug|Any CPU
{2FEB2298-7653-4009-B1EA-FFFB1A768BCC}.Debug|x86.ActiveCfg = Debug|Any CPU
{2FEB2298-7653-4009-B1EA-FFFB1A768BCC}.Debug|x86.Build.0 = Debug|Any CPU
{2FEB2298-7653-4009-B1EA-FFFB1A768BCC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2FEB2298-7653-4009-B1EA-FFFB1A768BCC}.Release|Any CPU.Build.0 = Release|Any CPU
{2FEB2298-7653-4009-B1EA-FFFB1A768BCC}.Release|x64.ActiveCfg = Release|Any CPU
{2FEB2298-7653-4009-B1EA-FFFB1A768BCC}.Release|x64.Build.0 = Release|Any CPU
{2FEB2298-7653-4009-B1EA-FFFB1A768BCC}.Release|x86.ActiveCfg = Release|Any CPU
{2FEB2298-7653-4009-B1EA-FFFB1A768BCC}.Release|x86.Build.0 = Release|Any CPU
{230AE83F-E92E-4E69-8355-426B305DA9C0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{230AE83F-E92E-4E69-8355-426B305DA9C0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{230AE83F-E92E-4E69-8355-426B305DA9C0}.Debug|x64.ActiveCfg = Debug|Any CPU
Expand Down
2 changes: 1 addition & 1 deletion Wox/CrashReporter.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;

namespace Wox.CrashReporter
namespace Wox
{
public class CrashReporter
{
Expand Down
2 changes: 1 addition & 1 deletion Wox/Helper/ErrorReporting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public static class ErrorReporting
public static void Report(Exception e)
{
Log.Fatal(e);
new CrashReporter.CrashReporter(e).Show();
new CrashReporter(e).Show();
}

public static void UnhandledExceptionHandle(object sender, UnhandledExceptionEventArgs e)
Expand Down
4 changes: 1 addition & 3 deletions Wox/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
using System.Reflection;
using System.Windows;
using Exceptionless.Configuration;

[assembly: AssemblyTitle("Wox")]
[assembly: ThemeInfo(
ResourceDictionaryLocation.None,
ResourceDictionaryLocation.SourceAssembly
)]
[assembly: Exceptionless("e0b256fbe9384498ba89aae2a6b7f8ab")]
)]
74 changes: 9 additions & 65 deletions Wox/ReportWindow.xaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Window x:Class="Wox.CrashReporter.ReportWindow"
<Window x:Class="Wox.ReportWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Expand All @@ -12,68 +12,12 @@
Height="455"
Title="{DynamicResource reportWindow_wox_got_an_error}"
d:DesignHeight="300" d:DesignWidth="600" x:ClassModifier="internal">
<StackPanel>
<TabControl >
<TabItem Header="{DynamicResource reportWindow_general}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition Width="40"></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="80"></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition Height="200"></RowDefinition>
</Grid.RowDefinitions>
<Image Source="Images/crash_warning.png" Width="64"></Image>
<RichTextBox Grid.Row="0" Grid.ColumnSpan="3" Grid.Column="1" IsReadOnly="True" x:Name="tbSummary"></RichTextBox>
<TextBlock Padding="0 5 0 0" Grid.Row="1" Grid.Column="0" Text="{DynamicResource reportWindow_version}"></TextBlock>
<TextBlock Padding="0 5 0 0" Grid.Row="1" Grid.Column="1" Text="Version" x:Name="tbVersion"></TextBlock>
<TextBlock Padding="0 5 0 0" Grid.Row="1" Grid.Column="2" Text="{DynamicResource reportWindow_time}"></TextBlock>
<TextBlock Padding="0 5 0 0" Grid.Row="1" Grid.Column="3" Text="10201211-21-21" x:Name="tbDatetime"></TextBlock>
<TextBlock Padding="0 5 0 5" Grid.ColumnSpan="4" Grid.Row="2" Grid.Column="0" Text="{DynamicResource reportWindow_reproduce}"></TextBlock>
<RichTextBox Grid.Row="3" Grid.ColumnSpan="4" Grid.Column="0" Background="#FFFFE1" x:Name="tbReproduceSteps"></RichTextBox>
</Grid>
</TabItem>
<TabItem Header="{DynamicResource reportWindow_exceptions}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="37*"/>
<ColumnDefinition Width="547*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Text="{DynamicResource reportWindow_exception_type}" Padding="5" Grid.ColumnSpan="2"></TextBlock>
<TextBox IsReadOnly="True" Grid.Row="1" Padding="5" x:Name="tbType" Grid.ColumnSpan="2"></TextBox>
<TextBlock Grid.Row="2" Text="{DynamicResource reportWindow_source}" Padding="5" Grid.ColumnSpan="2"></TextBlock>
<TextBox IsReadOnly="True" Grid.Row="3" Padding="5" x:Name="tbSource" Grid.ColumnSpan="2"></TextBox>
<TextBlock Grid.Row="4" Text="{DynamicResource reportWindow_stack_trace}" Padding="5" Grid.ColumnSpan="2"></TextBlock>
<RichTextBox Grid.Row="5" x:Name="tbStackTrace" Height="190" Grid.ColumnSpan="2" Margin="0,0,0,-0.001"></RichTextBox>
</Grid>
</TabItem>
</TabControl>
<StackPanel HorizontalAlignment="Right" Orientation="Horizontal">
<Button x:Name="btnSend" Padding="8 3" Margin="8" Click="btnSend_Click">
<StackPanel Orientation="Horizontal">
<Image Source="Images/crash_go.png" Margin="0 5 5 0"/>
<Label Padding="0" Margin="0 10 0 0" x:Name="tbSendReport" Content="{DynamicResource reportWindow_send_report}"></Label>
</StackPanel>
</Button>
<Button x:Name="btnCancel" Padding="8 3" Margin="8" Click="btnCancel_Click">
<StackPanel Orientation="Horizontal">
<Image Source="Images/crash_stop.png" Margin="0 5 5 0"/>
<Label Padding="0" Margin="0 10 0 0" Content="{DynamicResource reportWindow_cancel}"></Label>
</StackPanel>
</Button>
</StackPanel>
</StackPanel>
<RichTextBox x:Name="ErrorTextbox"
IsDocumentEnabled="True"
VerticalScrollBarVisibility="Auto"
HorizontalScrollBarVisibility="Auto"
FontSize="14"
Margin="10"
BorderThickness="0"/>

</Window>
81 changes: 42 additions & 39 deletions Wox/ReportWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,63 +1,66 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Text;
using System.Linq;
using System.Windows;
using System.Windows.Documents;
using Exceptionless;
using Wox.Core.Resource;
using Wox.Infrastructure;
using Wox.Infrastructure.Logger;

namespace Wox.CrashReporter
namespace Wox
{
internal partial class ReportWindow
{
private Exception exception;

public ReportWindow(Exception exception)
{
this.exception = exception;
InitializeComponent();
ErrorTextbox.Document.Blocks.FirstBlock.Margin = new Thickness(0);
SetException(exception);
}

private void SetException(Exception exception)
{
tbSummary.AppendText(exception.Message);
tbVersion.Text = Infrastructure.Constant.Version;
tbDatetime.Text = DateTime.Now.ToString();
tbStackTrace.AppendText(exception.StackTrace);
tbSource.Text = exception.Source;
tbType.Text = exception.GetType().ToString();
}
string path = Path.Combine(Constant.DataDirectory, Log.DirectoryName, Constant.Version);
var directory = new DirectoryInfo(path);
var log = directory.GetFiles().OrderByDescending(f => f.LastWriteTime).First();

private void btnSend_Click(object sender, RoutedEventArgs e)
{
string sendingMsg = InternationalizationManager.Instance.GetTranslation("reportWindow_sending");
tbSendReport.Content = sendingMsg;
btnSend.IsEnabled = false;
SendReport();
}
var paragraph = Hyperlink("Please open new issue in: " , Constant.Issue);
paragraph.Inlines.Add($"1. upload log file: {log.FullName}\n");
paragraph.Inlines.Add($"2. copy below exception message");
ErrorTextbox.Document.Blocks.Add(paragraph);

private void SendReport()
{
Hide();
Task.Run(() =>
{
string reproduceSteps = new TextRange(tbReproduceSteps.Document.ContentStart, tbReproduceSteps.Document.ContentEnd).Text;
exception.ToExceptionless()
.SetUserDescription(reproduceSteps)
.Submit();
ExceptionlessClient.Current.ProcessQueue();
Dispatcher.Invoke(() =>
{
Close();
});
});
StringBuilder content = new StringBuilder();
content.AppendLine($"Wox version: {Constant.Version}");
content.AppendLine($"OS Version: {Environment.OSVersion.VersionString}");
content.AppendLine($"Date: {DateTime.Now.ToString(CultureInfo.InvariantCulture)}");
content.AppendLine("Exception:");
content.AppendLine(exception.Source);
content.AppendLine(exception.GetType().ToString());
content.AppendLine(exception.Message);
content.AppendLine(exception.StackTrace);
paragraph = new Paragraph();
paragraph.Inlines.Add(content.ToString());
ErrorTextbox.Document.Blocks.Add(paragraph);
}

private void btnCancel_Click(object sender, RoutedEventArgs e)
private Paragraph Hyperlink(string textBeforeUrl, string url)
{
Close();
var paragraph = new Paragraph();
paragraph.Margin = new Thickness(0);

var link = new Hyperlink {IsEnabled = true};
link.Inlines.Add(url);
link.NavigateUri = new Uri(url);
link.RequestNavigate += (s, e) => Process.Start(e.Uri.ToString());
link.Click += (s, e) => Process.Start(url);

paragraph.Inlines.Add(textBeforeUrl);
paragraph.Inlines.Add(link);
paragraph.Inlines.Add("\n");

return paragraph;
}
}
}
22 changes: 10 additions & 12 deletions Wox/Wox.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@
<PropertyGroup>
<StartupObject>Wox.App</StartupObject>
</PropertyGroup>
<PropertyGroup>
<ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>
<ItemGroup>
<Reference Include="DeltaCompressionDotNet, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1d14d6e5194e7f4a, processorArchitecture=MSIL">
<HintPath>..\packages\DeltaCompressionDotNet.1.0.0\lib\net45\DeltaCompressionDotNet.dll</HintPath>
Expand All @@ -72,14 +75,6 @@
<HintPath>..\packages\DeltaCompressionDotNet.1.0.0\lib\net45\DeltaCompressionDotNet.PatchApi.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Exceptionless, Version=1.5.2121.0, Culture=neutral, PublicKeyToken=fc181f0a46f65747, processorArchitecture=MSIL">
<HintPath>..\packages\Exceptionless.1.5.2121\lib\net45\Exceptionless.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Exceptionless.Models, Version=1.5.2121.0, Culture=neutral, PublicKeyToken=fc181f0a46f65747, processorArchitecture=MSIL">
<HintPath>..\packages\Exceptionless.1.5.2121\lib\net45\Exceptionless.Models.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="ICSharpCode.SharpZipLib, Version=0.86.0.518, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\squirrel.windows.1.4.0\lib\Net45\ICSharpCode.SharpZipLib.dll</HintPath>
<Private>True</Private>
Expand Down Expand Up @@ -157,9 +152,11 @@
<Compile Include="..\SolutionAssemblyInfo.cs">
<Link>Properties\SolutionAssemblyInfo.cs</Link>
</Compile>
<Compile Include="CrashReporter.cs" />
<Compile Include="Helper\VisibilityExtensions.cs" />
<Compile Include="Helper\SingletonWindowOpener.cs" />
<Compile Include="PublicAPIInstance.cs" />
<Compile Include="ReportWindow.xaml.cs" />
<Compile Include="ResultListBox.xaml.cs">
<DependentUpon>ResultListBox.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -209,6 +206,7 @@
<Generator>MSBuild:Compile</Generator>
</Page>
<None Include="App.config" />
<None Include="app.manifest" />
<None Include="Languages\zh-cn.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand Down Expand Up @@ -273,6 +271,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="ReportWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="ResultListBox.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand Down Expand Up @@ -352,10 +354,6 @@
<Project>{B749F0DB-8E75-47DB-9E5E-265D16D0C0D2}</Project>
<Name>Wox.Core</Name>
</ProjectReference>
<ProjectReference Include="..\Wox.CrashReporter\Wox.CrashReporter.csproj">
<Project>{2FEB2298-7653-4009-B1EA-FFFB1A768BCC}</Project>
<Name>Wox.CrashReporter</Name>
</ProjectReference>
<ProjectReference Include="..\Wox.Infrastructure\Wox.Infrastructure.csproj">
<Project>{4fd29318-a8ab-4d8f-aa47-60bc241b8da3}</Project>
<Name>Wox.Infrastructure</Name>
Expand Down
Loading

0 comments on commit b9145aa

Please sign in to comment.