1 |
william |
4 |
using System; |
2 |
|
|
using System.Collections.Generic; |
3 |
|
|
using System.Windows.Forms; |
4 |
william |
52 |
using System.Data.SqlClient; |
5 |
william |
66 |
using System.Collections; |
6 |
|
|
using System.Text; |
7 |
william |
4 |
|
8 |
|
|
namespace AnywhereTS |
9 |
|
|
{ |
10 |
|
|
static class Program |
11 |
|
|
{ |
12 |
|
|
/// <summary> |
13 |
|
|
/// The main entry point for the application. |
14 |
|
|
/// </summary> |
15 |
|
|
[STAThread] |
16 |
|
|
static void Main() |
17 |
william |
61 |
{ |
18 |
|
|
AppDomain currentDomain = AppDomain.CurrentDomain; |
19 |
|
|
currentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); |
20 |
|
|
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException, true); |
21 |
|
|
|
22 |
william |
65 |
Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException); |
23 |
|
|
|
24 |
william |
4 |
Application.EnableVisualStyles(); |
25 |
|
|
Application.SetCompatibleTextRenderingDefault(false); |
26 |
|
|
|
27 |
|
|
frmClientProperties objCustomDialogBox = new frmClientProperties(); |
28 |
|
|
objCustomDialogBox.dialogMode = frmClientProperties.ATSClientMode.CONTROL_PANEL; // Select the mode to run the form in. |
29 |
|
|
Application.Run(objCustomDialogBox); |
30 |
|
|
} |
31 |
william |
65 |
|
32 |
|
|
static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e) |
33 |
|
|
{ |
34 |
|
|
CurrentDomain_UnhandledException(sender, new UnhandledExceptionEventArgs(e.Exception, false)); |
35 |
|
|
} |
36 |
william |
61 |
static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs args) |
37 |
|
|
{ |
38 |
william |
68 |
DialogResult result = DialogResult.Cancel; |
39 |
william |
61 |
Exception e = (Exception)args.ExceptionObject; |
40 |
|
|
if (e == null) |
41 |
|
|
{ |
42 |
william |
66 |
Logging.TSControlPanelLog.Error("Encountered unhandled Exception, but the exception was null"); |
43 |
william |
61 |
return; |
44 |
|
|
} |
45 |
|
|
if (e.GetType() == typeof(SqlException)) |
46 |
|
|
{ |
47 |
|
|
SqlException sql_ex = (e as SqlException); |
48 |
william |
69 |
List<object> strs = new List<object>(); |
49 |
|
|
using (log4net.NDC.Push(string.Format("{0}: ID={1} MESSAGE={2}{3}Diagnostics:{3}{4}", sql_ex.GetType().Name, sql_ex.Number.ToString(), sql_ex.Message, System.Environment.NewLine, sql_ex.ToString()))) |
50 |
william |
61 |
{ |
51 |
william |
69 |
Stack stack = log4net.NDC.CloneStack(); |
52 |
|
|
strs = new List<object>(stack.ToArray()); |
53 |
|
|
strs.Reverse(); |
54 |
|
|
Logging.TSControlPanelLog.Error("Encountered unhandled Exception"); |
55 |
william |
61 |
} |
56 |
william |
66 |
StringBuilder builder = new StringBuilder(); |
57 |
|
|
foreach (object str in strs) { builder.AppendLine(str.ToString()); } |
58 |
william |
68 |
result = ShowAbortRetryIgnoreDialog("Encountered unhandled Exception", builder.ToString()); |
59 |
|
|
if (result == DialogResult.Abort) |
60 |
|
|
Application.Exit(); |
61 |
william |
61 |
} |
62 |
|
|
else |
63 |
|
|
{ |
64 |
william |
69 |
List<object> strs = new List<object>(); |
65 |
|
|
using (log4net.NDC.Push(string.Format("{0}: MESSAGE={1}{2}Diagnostics:{2}{3}", e.GetType().Name, e.Message, System.Environment.NewLine, e.ToString()))) |
66 |
william |
61 |
{ |
67 |
william |
69 |
Stack stack = log4net.NDC.CloneStack(); |
68 |
|
|
strs = new List<object>(stack.ToArray()); |
69 |
|
|
strs.Reverse(); |
70 |
william |
66 |
Logging.TSControlPanelLog.Error("Encountered unhandled Exception"); |
71 |
william |
69 |
} |
72 |
william |
66 |
StringBuilder builder = new StringBuilder(); |
73 |
|
|
foreach (object str in strs) { builder.AppendLine(str.ToString()); } |
74 |
william |
68 |
result = ShowAbortRetryIgnoreDialog("Encountered unhandled Exception", builder.ToString()); |
75 |
|
|
if (result == DialogResult.Abort) |
76 |
|
|
Application.Exit(); |
77 |
william |
61 |
} |
78 |
|
|
} |
79 |
william |
68 |
// Creates the error message and displays it. |
80 |
|
|
private static DialogResult ShowAbortRetryIgnoreDialog(string title, string message) |
81 |
|
|
{ |
82 |
|
|
return MessageBox.Show(message, title, MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button1); |
83 |
|
|
} |
84 |
william |
4 |
} |
85 |
|
|
} |