Skip to content

Commit da365ce

Browse files
committed
Fixed an issue preventing messages from being send using Doctor Dump service from Non UI thread.
1 parent 068df88 commit da365ce

12 files changed

Lines changed: 365 additions & 307 deletions

File tree

CrashReporter.NET/CaptureScreenshot.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public static void CaptureWindow(Form currentWindow, string location, ImageForma
3535
{
3636
graphics.CopyFromScreen(new Point(bounds.Left, bounds.Top), Point.Empty, bounds.Size);
3737
}
38+
3839
bitmap.Save(location, imageFormat);
3940
}
4041
}
@@ -66,6 +67,7 @@ public static void CaptureActiveWindow(string location, ImageFormat imageFormat)
6667
{
6768
graphics.CopyFromScreen(new Point(bounds.Left, bounds.Top), Point.Empty, bounds.Size);
6869
}
70+
6971
bitmap.Save(location, imageFormat);
7072
}
7173
}

CrashReporter.NET/CrashReport.cs

Lines changed: 25 additions & 257 deletions
Large diffs are not rendered by default.

CrashReporter.NET/DrDump/AnonymousData.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ internal class AnonymousData
88
public string ToEmail { get; set; }
99
public Guid? ApplicationID { get; set; }
1010
}
11-
}
11+
}

CrashReporter.NET/DrDump/DrDumpService.cs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,20 @@ internal class DrDumpService
1818
public DrDumpService()
1919
{
2020
_uploader = new HttpsCrashReporterReportUploader();
21-
var configOverride = Microsoft.Win32.Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Idol Software\DumpUploader", "ServiceURL", null) as string;
21+
var configOverride =
22+
Microsoft.Win32.Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Idol Software\DumpUploader",
23+
"ServiceURL", null) as string;
2224
if (!string.IsNullOrEmpty(configOverride))
2325
{
2426
var t = new Uri(configOverride);
2527
var newUrl = new UriBuilder(_uploader.Url)
2628
{
27-
Scheme = t.Scheme,
28-
Host = t.Host,
29+
Scheme = t.Scheme,
30+
Host = t.Host,
2931
Port = t.Port
3032
};
3133
_uploader.Url = newUrl.ToString();
32-
}
34+
}
3335
}
3436

3537
public void SendAnonymousReportAsync(Exception exception, string toEmail, Guid? applicationId)
@@ -45,10 +47,12 @@ public void SendAnonymousReportAsync(Exception exception, string toEmail, Guid?
4547
};
4648

4749
_uploader.SendAnonymousReportCompleted += OnSendAnonymousReportCompleted;
48-
_uploader.SendAnonymousReportAsync(SendRequestState.GetClientLib(), _sendRequestState.GetApplication(), _sendRequestState.GetExceptionDescription(anonymous: true), _sendRequestState);
50+
_uploader.SendAnonymousReportAsync(SendRequestState.GetClientLib(), _sendRequestState.GetApplication(),
51+
_sendRequestState.GetExceptionDescription(true), _sendRequestState);
4952
}
5053

51-
public void SendAdditionalDataAsync(Control control, string developerMessage, string userEmail, string userMessage, byte[] screenshot)
54+
public void SendAdditionalDataAsync(Control control, string developerMessage, string userEmail,
55+
string userMessage, byte[] screenshot)
5256
{
5357
bool needToSend;
5458
lock (_sendRequestState)
@@ -88,7 +92,8 @@ private void SendAdditionalDataAsync(Control control, SendRequestState sendReque
8892
if (response is NeedReportResponse)
8993
{
9094
_uploader.SendAdditionalDataCompleted += OnSendAdditionalDataCompleted;
91-
_uploader.SendAdditionalDataAsync(response.Context, sendRequestState.GetDetailedExceptionDescription(), sendRequestState);
95+
_uploader.SendAdditionalDataAsync(response.Context,
96+
sendRequestState.GetDetailedExceptionDescription(), sendRequestState);
9297
return;
9398
}
9499

@@ -99,11 +104,12 @@ private void SendAdditionalDataAsync(Control control, SendRequestState sendReque
99104
{
100105
e = new SendRequestCompletedEventArgs(null, ex, false);
101106
}
107+
102108
if (SendRequestCompleted != null)
103109
{
104110
if (control != null)
105111
{
106-
control.BeginInvoke(SendRequestCompleted, new object[] { this, e });
112+
control.BeginInvoke(SendRequestCompleted, new object[] {this, e});
107113
}
108114
else
109115
{
@@ -114,14 +120,14 @@ private void SendAdditionalDataAsync(Control control, SendRequestState sendReque
114120

115121
private void OnSendAnonymousReportCompleted(object sender, SendAnonymousReportCompletedEventArgs e)
116122
{
117-
var state = (SendRequestState)e.UserState;
123+
var state = (SendRequestState) e.UserState;
118124

119125
bool needToSend;
120126

121127
lock (state)
122128
{
123129
state.SendAnonymousReportResult = e;
124-
130+
125131
needToSend = state.PrivateData != null;
126132
}
127133

@@ -171,4 +177,4 @@ public Response Result
171177
}
172178
}
173179
}
174-
}
180+
}

CrashReporter.NET/DrDump/PrivateData.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ class PrivateData
77
public string DeveloperMessage { get; set; }
88
public byte[] Screenshot { get; set; }
99
}
10-
}
10+
}

CrashReporter.NET/DrDump/SendRequestState.cs

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ private static ExceptionInfo ConvertToExceptionInfo(Exception e, bool anonymous)
3131
private static System.Net.NetworkInformation.PhysicalAddress GetMacAddress()
3232
{
3333
var googleDns = new System.Net.Sockets.UdpClient("8.8.8.8", 53);
34-
IPAddress localAddress = ((IPEndPoint)googleDns.Client.LocalEndPoint).Address;
34+
IPAddress localAddress = ((IPEndPoint) googleDns.Client.LocalEndPoint).Address;
3535

3636
foreach (var netInterface in System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces())
3737
{
@@ -41,13 +41,16 @@ private static System.Net.NetworkInformation.PhysicalAddress GetMacAddress()
4141
return netInterface.GetPhysicalAddress();
4242
}
4343
}
44+
4445
return null;
4546
}
4647

4748
private int GetAnonymousMachineID()
4849
{
4950
System.Net.NetworkInformation.PhysicalAddress mac = GetMacAddress();
50-
return mac != null ? BitConverter.ToInt32(System.Security.Cryptography.MD5.Create().ComputeHash(mac.GetAddressBytes()), 0) : 0;
51+
return mac != null
52+
? BitConverter.ToInt32(System.Security.Cryptography.MD5.Create().ComputeHash(mac.GetAddressBytes()), 0)
53+
: 0;
5154
}
5255

5356
internal DetailedExceptionDescription GetDetailedExceptionDescription()
@@ -61,9 +64,7 @@ internal DetailedExceptionDescription GetDetailedExceptionDescription()
6164
PngScreenShot = PrivateData.Screenshot
6265
};
6366
}
64-
65-
66-
67+
6768
internal ExceptionDescription GetExceptionDescription(bool anonymous)
6869
{
6970
var oldCulture = System.Threading.Thread.CurrentThread.CurrentCulture;
@@ -97,10 +98,14 @@ internal Application GetApplication()
9798
string moduleName = mainAssembly.GetName().Name;
9899

99100
var attributes = mainAssembly.GetCustomAttributes(typeof(System.Reflection.AssemblyCompanyAttribute), true);
100-
string appCompany = (attributes.Length > 0) ? ((System.Reflection.AssemblyCompanyAttribute)attributes[0]).Company : AnonymousData.ToEmail;
101+
string appCompany = attributes.Length > 0
102+
? ((System.Reflection.AssemblyCompanyAttribute) attributes[0]).Company
103+
: AnonymousData.ToEmail;
101104

102105
var attributes2 = mainAssembly.GetCustomAttributes(typeof(System.Reflection.AssemblyTitleAttribute), true);
103-
string appTitle = (attributes2.Length > 0) ? ((System.Reflection.AssemblyTitleAttribute)attributes2[0]).Title : moduleName;
106+
string appTitle = attributes2.Length > 0
107+
? ((System.Reflection.AssemblyTitleAttribute) attributes2[0]).Title
108+
: moduleName;
104109

105110
var appVersion = mainAssembly.GetName().Version;
106111

@@ -110,10 +115,10 @@ internal Application GetApplication()
110115
AppName = appTitle,
111116
CompanyName = appCompany,
112117
Email = AnonymousData.ToEmail,
113-
V1 = (ushort)appVersion.Major,
114-
V2 = (ushort)appVersion.Minor,
115-
V3 = (ushort)appVersion.Build,
116-
V4 = (ushort)appVersion.Revision,
118+
V1 = (ushort) appVersion.Major,
119+
V2 = (ushort) appVersion.Minor,
120+
V3 = (ushort) appVersion.Build,
121+
V4 = (ushort) appVersion.Revision,
117122
MainModule = moduleName
118123
};
119124
}
@@ -123,11 +128,11 @@ internal static ClientLib GetClientLib()
123128
var clientVersion = typeof(CrashReport).Assembly.GetName().Version;
124129
return new ClientLib
125130
{
126-
V1 = (ushort)clientVersion.Major,
127-
V2 = (ushort)clientVersion.Minor,
128-
V3 = (ushort)clientVersion.Build,
129-
V4 = (ushort)clientVersion.Revision
131+
V1 = (ushort) clientVersion.Major,
132+
V2 = (ushort) clientVersion.Minor,
133+
V3 = (ushort) clientVersion.Build,
134+
V4 = (ushort) clientVersion.Revision
130135
};
131136
}
132137
}
133-
}
138+
}

CrashReporter.NET/HelperMethods.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ private static bool Is64BitOperatingSystem()
3434
return true;
3535
}
3636
}
37+
3738
// The environment must be an x86 environment.
3839
return false;
3940
}
@@ -53,12 +54,15 @@ private static string HKLM_GetString(string key, string value)
5354

5455
public static string GetOSVersion()
5556
{
56-
if (!string.IsNullOrEmpty(HKLM_GetString(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion", "CurrentMajorVersionNumber")))
57+
if (!string.IsNullOrEmpty(HKLM_GetString(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion",
58+
"CurrentMajorVersionNumber")))
5759
{
5860
return
5961
$"{HKLM_GetString(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion", "CurrentMajorVersionNumber")}.{HKLM_GetString(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion", "CurrentMinorVersionNumber")}.{HKLM_GetString(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion", "CurrentBuildNumber")}.0";
6062
}
61-
return $"{HKLM_GetString(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion", "CurrentVersion")}.{HKLM_GetString(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion", "CurrentBuildNumber")}.0";
63+
64+
return
65+
$"{HKLM_GetString(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion", "CurrentVersion")}.{HKLM_GetString(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion", "CurrentBuildNumber")}.0";
6266
}
6367

6468
public static string GetWindowsVersion()
@@ -72,6 +76,7 @@ public static string GetWindowsVersion()
7276
{
7377
osArchitecture = "32/64-bit (Undetermined)";
7478
}
79+
7580
string productName = HKLM_GetString(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion", "ProductName");
7681
string csdVersion = HKLM_GetString(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion", "CSDVersion");
7782
string currentBuild = HKLM_GetString(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion", "CurrentBuildNumber");
@@ -80,7 +85,8 @@ public static string GetWindowsVersion()
8085
return
8186
$"{(productName.StartsWith("Microsoft") ? "" : "Microsoft ")}{productName}{(!string.IsNullOrEmpty(csdVersion) ? " " + csdVersion : String.Empty)} {osArchitecture} (OS Build {currentBuild})";
8287
}
88+
8389
return String.Empty;
8490
}
8591
}
86-
}
92+
}

0 commit comments

Comments
 (0)