/[AnywhereTS-MSSQL]/trunk/TSControlPanel/Program.cs
ViewVC logotype

Contents of /trunk/TSControlPanel/Program.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 69 - (show annotations) (download)
Thu Jul 12 20:06:53 2012 UTC (8 years, 6 months ago) by william
File size: 4157 byte(s)
+ fix retrievale of NDC stack
+ get exception type name

1 using System;
2 using System.Collections.Generic;
3 using System.Windows.Forms;
4 using System.Data.SqlClient;
5 using System.Collections;
6 using System.Text;
7
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 {
18 AppDomain currentDomain = AppDomain.CurrentDomain;
19 currentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
20 Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException, true);
21
22 Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
23
24 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
32 static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
33 {
34 CurrentDomain_UnhandledException(sender, new UnhandledExceptionEventArgs(e.Exception, false));
35 }
36 static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs args)
37 {
38 DialogResult result = DialogResult.Cancel;
39 Exception e = (Exception)args.ExceptionObject;
40 if (e == null)
41 {
42 Logging.TSControlPanelLog.Error("Encountered unhandled Exception, but the exception was null");
43 return;
44 }
45 if (e.GetType() == typeof(SqlException))
46 {
47 SqlException sql_ex = (e as SqlException);
48 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 {
51 Stack stack = log4net.NDC.CloneStack();
52 strs = new List<object>(stack.ToArray());
53 strs.Reverse();
54 Logging.TSControlPanelLog.Error("Encountered unhandled Exception");
55 }
56 StringBuilder builder = new StringBuilder();
57 foreach (object str in strs) { builder.AppendLine(str.ToString()); }
58 result = ShowAbortRetryIgnoreDialog("Encountered unhandled Exception", builder.ToString());
59 if (result == DialogResult.Abort)
60 Application.Exit();
61 }
62 else
63 {
64 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 {
67 Stack stack = log4net.NDC.CloneStack();
68 strs = new List<object>(stack.ToArray());
69 strs.Reverse();
70 Logging.TSControlPanelLog.Error("Encountered unhandled Exception");
71 }
72 StringBuilder builder = new StringBuilder();
73 foreach (object str in strs) { builder.AppendLine(str.ToString()); }
74 result = ShowAbortRetryIgnoreDialog("Encountered unhandled Exception", builder.ToString());
75 if (result == DialogResult.Abort)
76 Application.Exit();
77 }
78 }
79 // 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 }
85 }

  ViewVC Help
Powered by ViewVC 1.1.22