Skip to content

Commit 592a815

Browse files
committed
Fixed an issue where silent flag didn't work for an unhandled exception. This resolves #13, resolves #18 and resolves #22.
1 parent 798e1b1 commit 592a815

File tree

13 files changed

+78
-50
lines changed

13 files changed

+78
-50
lines changed

CrashReporter.NET/DrDump/DrDumpService.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,43 @@ public void SendAnonymousReportAsync(Exception exception, string toEmail, Guid?
5151
_sendRequestState.GetExceptionDescription(true), _sendRequestState);
5252
}
5353

54+
public string SendReportSilently(Exception exception, string toEmail, Guid? applicationId, string developerMessage, string from,
55+
string userMessage, byte[] screenshot)
56+
{
57+
_sendRequestState = new SendRequestState
58+
{
59+
AnonymousData = new AnonymousData
60+
{
61+
Exception = exception,
62+
ToEmail = toEmail,
63+
ApplicationID = applicationId
64+
},
65+
PrivateData = new PrivateData
66+
{
67+
UserEmail = from,
68+
UserMessage = userMessage,
69+
DeveloperMessage = developerMessage,
70+
Screenshot = screenshot
71+
}
72+
};
73+
74+
var response = _uploader.SendAnonymousReport(SendRequestState.GetClientLib(), _sendRequestState.GetApplication(),
75+
_sendRequestState.GetExceptionDescription(true));
76+
if (response is ErrorResponse errorResponse)
77+
throw new Exception(errorResponse.Error);
78+
79+
if (response is NeedReportResponse)
80+
{
81+
var additionalDataResponse = _uploader.SendAdditionalData(response.Context,
82+
_sendRequestState.GetDetailedExceptionDescription());
83+
if (additionalDataResponse is ErrorResponse errorAdditionalDataResponse)
84+
throw new Exception(errorAdditionalDataResponse.Error);
85+
return additionalDataResponse.UrlToProblem;
86+
}
87+
88+
return response.UrlToProblem;
89+
}
90+
5491
public void SendAdditionalDataAsync(Control control, string developerMessage, string userEmail,
5592
string userMessage, byte[] screenshot)
5693
{

CrashReporter.NET/Properties/AssemblyInfo.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
[assembly: AssemblyConfiguration("")]
1212
[assembly: AssemblyCompany("RBSoft")]
1313
[assembly: AssemblyProduct("CrashReporter.NET")]
14-
[assembly: AssemblyCopyright("Copyright © 2012-2018 RBSoft")]
14+
[assembly: AssemblyCopyright("Copyright © 2012-2019 RBSoft")]
1515
[assembly: AssemblyTrademark("")]
1616
[assembly: AssemblyCulture("")]
1717

@@ -36,6 +36,6 @@
3636
// by using the '*' as shown below:
3737
// [assembly: AssemblyVersion("1.0.*")]
3838

39-
[assembly: AssemblyVersion("1.5.6.0")]
40-
[assembly: AssemblyFileVersion("1.5.6.0")]
39+
[assembly: AssemblyVersion("1.5.7.0")]
40+
[assembly: AssemblyFileVersion("1.5.7.0")]
4141
[assembly: NeutralResourcesLanguageAttribute("en")]

CrashReporter.NET/ReportCrash.cs

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -426,10 +426,8 @@ private string CreateReport(Exception exception)
426426
internal void SendAnonymousReport(DrDumpService.SendRequestCompletedEventHandler sendRequestCompleted)
427427
{
428428
_doctorDumpService = new DrDumpService();
429-
if (sendRequestCompleted != null)
430-
{
431-
_doctorDumpService.SendRequestCompleted += sendRequestCompleted;
432-
}
429+
430+
_doctorDumpService.SendRequestCompleted += sendRequestCompleted;
433431

434432
_doctorDumpService.SendAnonymousReportAsync(
435433
Exception,
@@ -444,13 +442,26 @@ private void SendFullReport(bool includeScreenshot,
444442
var sendScreenshot = File.Exists(ScreenShot) && includeScreenshot;
445443
var screenshot = sendScreenshot ? File.ReadAllBytes(ScreenShot) : null;
446444

447-
if (_doctorDumpService == null)
445+
if (sendRequestCompleted != null)
448446
{
449-
SendAnonymousReport(sendRequestCompleted);
450-
}
447+
if (_doctorDumpService == null)
448+
{
449+
SendAnonymousReport(sendRequestCompleted);
450+
}
451451

452-
_doctorDumpService.SendAdditionalDataAsync(form, DeveloperMessage, from,
453-
userMessage, screenshot);
452+
_doctorDumpService.SendAdditionalDataAsync(form, DeveloperMessage, from,
453+
userMessage, screenshot);
454+
}
455+
else
456+
{
457+
_doctorDumpService = new DrDumpService();
458+
var reportUrl =_doctorDumpService.SendReportSilently(Exception, ToEmail, DoctorDumpSettings?.ApplicationID, DeveloperMessage, from, userMessage, screenshot);
459+
if (DoctorDumpSettings != null && DoctorDumpSettings.OpenReportInBrowser)
460+
{
461+
if (!string.IsNullOrEmpty(reportUrl))
462+
Process.Start(reportUrl);
463+
}
464+
}
454465
}
455466

456467
#endregion

CrashReporter.NET/build/CrashReporter.NET.Official.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
33
<metadata>
44
<id>CrashReporter.NET.Official</id>
5-
<version>1.5.6</version>
5+
<version>1.5.7</version>
66
<title>CrashReporter.NET</title>
77
<authors>RBSoft</authors>
88
<owners>rbsoft</owners>

CrashReporterTest/FormMain.cs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,11 @@ private void ThrowException()
3232
catch (ArgumentException argumentException)
3333
{
3434
const string path = "test.txt";
35-
try
36-
{
37-
if (!File.Exists(path))
38-
{
39-
throw new FileNotFoundException(
40-
"File Not found when trying to write argument exception to the file", argumentException);
41-
}
42-
}
43-
catch (Exception exception)
35+
36+
if (!File.Exists(path))
4437
{
45-
Program.SendReport(exception, "Value of path variable is " + path);
38+
throw new FileNotFoundException(
39+
"File Not found when trying to write argument exception to the file", argumentException);
4640
}
4741
}
4842
}

CrashReporterTest/Program.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ static void Main()
1616
AppDomain.CurrentDomain.UnhandledException += (sender, args) =>
1717
{
1818
SendReport((Exception) args.ExceptionObject);
19-
Environment.Exit(0);
2019
};
2120
Application.EnableVisualStyles();
2221
Application.SetCompatibleTextRenderingDefault(false);

CrashReporterTest/Properties/AssemblyInfo.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
[assembly: AssemblyConfiguration("")]
1010
[assembly: AssemblyCompany("RBSoft")]
1111
[assembly: AssemblyProduct("CrashReporterTest")]
12-
[assembly: AssemblyCopyright("Copyright © 2012-2018 RBSoft")]
12+
[assembly: AssemblyCopyright("Copyright © 2012-2019 RBSoft")]
1313
[assembly: AssemblyTrademark("")]
1414
[assembly: AssemblyCulture("")]
1515

@@ -31,5 +31,5 @@
3131
// You can specify all the values or you can default the Build and Revision Numbers
3232
// by using the '*' as shown below:
3333
// [assembly: AssemblyVersion("1.0.*")]
34-
[assembly: AssemblyVersion("1.5.6.0")]
35-
[assembly: AssemblyFileVersion("1.5.6.0")]
34+
[assembly: AssemblyVersion("1.0.0.0")]
35+
[assembly: AssemblyFileVersion("1.0.0.0")]

CrashReporterWPFTest/App.xaml.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,21 @@ protected override void OnStartup(StartupEventArgs e)
2222
private void TaskSchedulerOnUnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs unobservedTaskExceptionEventArgs)
2323
{
2424
SendReport(unobservedTaskExceptionEventArgs.Exception);
25-
Environment.Exit(0);
2625
}
2726

2827
private void DispatcherOnUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs dispatcherUnhandledExceptionEventArgs)
2928
{
3029
SendReport(dispatcherUnhandledExceptionEventArgs.Exception);
31-
Environment.Exit(0);
3230
}
3331

3432
private static void CurrentDomainOnUnhandledException(object sender, UnhandledExceptionEventArgs unhandledExceptionEventArgs)
3533
{
3634
SendReport((Exception)unhandledExceptionEventArgs.ExceptionObject);
37-
Environment.Exit(0);
3835
}
3936

40-
public static void SendReport(Exception exception, string developerMessage = "", bool silent = false)
37+
public static void SendReport(Exception exception, string developerMessage = "", bool silent = true)
4138
{
42-
var reportCrash = new ReportCrash("Email where you want to receive crash reports.")
39+
var reportCrash = new ReportCrash("[email protected]")
4340
{
4441
DeveloperMessage = developerMessage,
4542
Silent = silent

CrashReporterWPFTest/MainWindow.xaml.cs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,11 @@ private void ThrowException()
3030
catch (ArgumentException argumentException)
3131
{
3232
const string path = "test.txt";
33-
try
34-
{
35-
if (!File.Exists(path))
36-
{
37-
throw new FileNotFoundException(
38-
"File Not found when trying to write argument exception to the file", argumentException);
39-
}
40-
}
41-
catch (Exception exception)
33+
34+
if (!File.Exists(path))
4235
{
43-
App.SendReport(exception, "Value of path variable is " + path);
36+
throw new FileNotFoundException(
37+
"File Not found when trying to write argument exception to the file", argumentException);
4438
}
4539
}
4640
}

CrashReporterWPFTest/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
[assembly: AssemblyConfiguration("")]
1313
[assembly: AssemblyCompany("RBSoft")]
1414
[assembly: AssemblyProduct("CrashReporterWPFTest")]
15-
[assembly: AssemblyCopyright("Copyright © 2017-2018 RBSoft")]
15+
[assembly: AssemblyCopyright("Copyright © 2017-2019 RBSoft")]
1616
[assembly: AssemblyTrademark("")]
1717
[assembly: AssemblyCulture("")]
1818

0 commit comments

Comments
 (0)