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

Annotation of /trunk/TSControlPanel/Program.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 97 - (hide annotations) (download)
Sat Jul 14 03:02:06 2012 UTC (9 years, 2 months ago) by william
File size: 6213 byte(s)
+ alter context for Program.cs

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 70 using log4net;
8 william 4
9     namespace AnywhereTS
10     {
11     static class Program
12     {
13     /// <summary>
14     /// The main entry point for the application.
15     /// </summary>
16     [STAThread]
17     static void Main()
18 william 61 {
19 william 96 Logging.Initialize();
20 william 97 using (log4net.NDC.Push("Logged from TSControlPanel.exe"))
21 william 94 {
22     AppDomain currentDomain = AppDomain.CurrentDomain;
23     currentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
24     Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException, true);
25 william 61
26 william 94 Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
27 william 65
28 william 94 Application.EnableVisualStyles();
29     Application.SetCompatibleTextRenderingDefault(false);
30 william 4
31 william 94 frmClientProperties objCustomDialogBox = new frmClientProperties();
32     objCustomDialogBox.dialogMode = frmClientProperties.ATSClientMode.CONTROL_PANEL; // Select the mode to run the form in.
33     Application.Run(objCustomDialogBox);
34     }
35 william 4 }
36 william 65
37     static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
38     {
39     CurrentDomain_UnhandledException(sender, new UnhandledExceptionEventArgs(e.Exception, false));
40     }
41 william 61 static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs args)
42     {
43 william 68 DialogResult result = DialogResult.Cancel;
44 william 61 Exception e = (Exception)args.ExceptionObject;
45     if (e == null)
46     {
47 william 73 Logging.ATSAdminLog.Error("Encountered unhandled Exception, but the exception was null");
48 william 61 return;
49     }
50     if (e.GetType() == typeof(SqlException))
51     {
52     SqlException sql_ex = (e as SqlException);
53 william 70 List<string> strs = new List<string>();
54 william 69 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())))
55 william 61 {
56 william 73 Exception inner = sql_ex.InnerException;
57     if (inner != null)
58     {
59    
60     if (inner.GetType() == typeof(SqlException))
61     {
62     SqlException sql_inner = inner as SqlException;
63     using (log4net.NDC.Push(string.Format("{0}: ID={1} MESSAGE={2}{3}Diagnostics:{3}{4}", sql_inner.GetType().Name, sql_inner.Number.ToString(), sql_inner.Message, System.Environment.NewLine, sql_inner.ToString())))
64     {
65     strs = Logging.GetMessagesFromThreadContextStack("NDC");
66     Logging.ATSAdminLog.Error("Encountered unhandled Exception");
67     }
68     }
69     else
70     {
71     using (log4net.NDC.Push(string.Format("{0}: MESSAGE={1}{2}Diagnostics:{2}{3}", inner.GetType().Name, inner.Message, System.Environment.NewLine, inner.ToString())))
72     {
73     strs = Logging.GetMessagesFromThreadContextStack("NDC");
74     Logging.ATSAdminLog.Error("Encountered unhandled Exception");
75     }
76     }
77     }
78     else
79     {
80     strs = Logging.GetMessagesFromThreadContextStack("NDC");
81     Logging.ATSAdminLog.Error("Encountered unhandled Exception");
82     }
83 william 61 }
84 william 66 StringBuilder builder = new StringBuilder();
85 william 70 foreach (string str in strs) { builder.AppendLine(str); }
86 william 68 result = ShowAbortRetryIgnoreDialog("Encountered unhandled Exception", builder.ToString());
87     if (result == DialogResult.Abort)
88     Application.Exit();
89 william 61 }
90     else
91     {
92 william 70 List<string> strs = new List<string>();
93 william 69 using (log4net.NDC.Push(string.Format("{0}: MESSAGE={1}{2}Diagnostics:{2}{3}", e.GetType().Name, e.Message, System.Environment.NewLine, e.ToString())))
94 william 61 {
95 william 73 Exception inner = e.InnerException;
96     if (inner != null)
97     {
98     using (log4net.NDC.Push(string.Format("{0}: MESSAGE={1}{2}Diagnostics:{2}{3}", inner.GetType().Name, inner.Message, System.Environment.NewLine, inner.ToString())))
99     {
100     strs = Logging.GetMessagesFromThreadContextStack("NDC");
101     Logging.ATSAdminLog.Error("Encountered unhandled Exception");
102     }
103     }
104     else
105     {
106     strs = Logging.GetMessagesFromThreadContextStack("NDC");
107     Logging.ATSAdminLog.Error("Encountered unhandled Exception");
108     }
109 william 70 }
110 william 66 StringBuilder builder = new StringBuilder();
111 william 70 foreach (string str in strs) { builder.AppendLine(str); }
112 william 68 result = ShowAbortRetryIgnoreDialog("Encountered unhandled Exception", builder.ToString());
113     if (result == DialogResult.Abort)
114     Application.Exit();
115 william 61 }
116     }
117 william 68 // Creates the error message and displays it.
118     private static DialogResult ShowAbortRetryIgnoreDialog(string title, string message)
119     {
120     return MessageBox.Show(message, title, MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button1);
121     }
122 william 4 }
123     }

  ViewVC Help
Powered by ViewVC 1.1.22