forked from hpavlov/tangra3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfrmUnhandledException.cs
181 lines (153 loc) · 6.45 KB
/
frmUnhandledException.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.ServiceModel;
using System.Text;
using System.Windows.Forms;
using System.Xml.Serialization;
using Tangra.Model.Config;
using Tangra.Model.Context;
using Tangra.TangraService;
using System.Diagnostics;
namespace Tangra
{
public partial class frmUnhandledException : Form
{
private Exception m_Error;
private static bool m_RestartRequest = true;
private static object m_SyncRoot = new object();
public frmUnhandledException(Exception error)
{
InitializeComponent();
m_Error = error;
tbxEmailAddress.Text = TangraConfig.Settings.LastUsed.EmailAddressForErrorReporting;
}
internal static void HandleException(object sender, Exception error)
{
lock (m_SyncRoot)
{
if (TangraContext.Current.HasRestartRequest())
return;
}
if (error != null)
{
var frm = new frmUnhandledException(error);
frm.StartPosition = FormStartPosition.CenterParent;
frm.ShowDialog(sender as IWin32Window);
}
}
internal static void HandleExceptionNoRestart(object sender, Exception error)
{
m_RestartRequest = false;
HandleException(sender, error);
}
private void lblDetails_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
string errorReport = GetErrorReport();
Clipboard.SetText(errorReport);
MessageBox.Show("The error report has been copied to the clipboard.\r\nPaste it in a text editor (for example Notepad) to review it.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
private string GetErrorReport()
{
return "Tangra 3 Error Report\r\n\r\n" +
m_Error.ToString() + "\r\n\r\nUser Comments:\r\n" +
"User Email: " + (tbxEmailAddress.Text.Trim().Length == 0 ? "[UNSPECIFIED]" : tbxEmailAddress.Text) + "\r\n\r\n" +
tbxUserComments.Text + "\r\n\r\n" +
GetExtendedTangraInfo();
}
private string GetExtendedTangraInfo()
{
var ser = new XmlSerializer(typeof (CrashReportInfo));
var crashReportInfo = new StringBuilder();
if (TangraContext.Current.CrashReportInfo != null)
{
try
{
TangraContext.Current.CrashReportInfo.WorkingSet64 = Process.GetCurrentProcess().WorkingSet64;
TangraContext.Current.CrashReportInfo.VirtualMemorySize64 = Process.GetCurrentProcess().VirtualMemorySize64;
TangraContext.Current.CrashReportInfo.PrivateMemorySize64 = Process.GetCurrentProcess().PrivateMemorySize64;
TangraContext.Current.CrashReportInfo.PeakWorkingSet64 = Process.GetCurrentProcess().PeakWorkingSet64;
TangraContext.Current.CrashReportInfo.MinWorkingSet = Process.GetCurrentProcess().MinWorkingSet.ToInt64();
TangraContext.Current.CrashReportInfo.MaxWorkingSet = Process.GetCurrentProcess().MaxWorkingSet.ToInt64();
}
catch
{ }
using(TextWriter wrt = new StringWriter(crashReportInfo))
{
ser.Serialize(wrt, TangraContext.Current.CrashReportInfo);
wrt.Flush();
}
if (TangraContext.Current.CrashReportInfo.ReductionContext != null)
crashReportInfo.Append("\r\n\r\n" + TangraContext.Current.CrashReportInfo.ReductionContext + "\r\n\r\n");
}
var moduleInfo = new StringBuilder("\r\n\r\nLoaded modules:\r\n\r\n");
foreach (ProcessModule module in Process.GetCurrentProcess().Modules)
{
try
{
moduleInfo.AppendFormat("{0} v{1}, {2}\r\n", module.ModuleName, module.FileVersionInfo.FileVersion, module.FileName);
}
catch
{ }
}
return
frmSystemInfo.GetFullVersionInfo() + "\r\n" +
string.Format("Tangra Install Location: {0}\r\n", AppDomain.CurrentDomain.BaseDirectory) +
crashReportInfo.ToString() +
moduleInfo.ToString();
}
private void btnSubmit_Click(object sender, EventArgs e)
{
string errorReport = GetErrorReport();
Cursor = Cursors.WaitCursor;
try
{
var binding = new BasicHttpBinding();
var address = new EndpointAddress("http://www.tangra-observatory.org/TangraErrors/ErrorReports.asmx");
var client = new TangraService.ServiceSoapClient(binding, address);
client.ReportError(errorReport);
TangraConfig.Settings.LastUsed.EmailAddressForErrorReporting = tbxEmailAddress.Text;
TangraConfig.Settings.Save();
if (MessageBox.Show(
"The error report was sent successfully. Press 'Retry' to try to continue or 'Cancel' to restart Tangra.",
"Question",
MessageBoxButtons.RetryCancel,
MessageBoxIcon.Question,
MessageBoxDefaultButton.Button1) == DialogResult.Cancel)
{
Application.Restart();
}
}
finally
{
Cursor = Cursors.Default;
Close();
}
}
private void frmUnhandledException_FormClosed(object sender, FormClosedEventArgs e)
{
lock (m_SyncRoot)
{
if (TangraContext.Current.HasRestartRequest())
return;
if (m_RestartRequest)
{
MessageBox.Show("Tangra will now restart", "Restart", MessageBoxButtons.OK, MessageBoxIcon.Information);
TangraContext.Current.RestartApplication();
}
}
}
private void btnCancel_Click(object sender, EventArgs e)
{
Application.Exit();
}
}
}