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

Annotation of /trunk/TSControlPanel/Program.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 109 - (hide annotations) (download)
Sat Jul 14 06:25:57 2012 UTC (9 years ago) by william
File size: 6252 byte(s)

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 109 //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 109 //Logging.Initialize();
44 william 68 DialogResult result = DialogResult.Cancel;
45 william 61 Exception e = (Exception)args.ExceptionObject;
46     if (e == null)
47     {
48 william 73 Logging.ATSAdminLog.Error("Encountered unhandled Exception, but the exception was null");
49 william 61 return;
50     }
51     if (e.GetType() == typeof(SqlException))
52     {
53     SqlException sql_ex = (e as SqlException);
54 william 70 List<string> strs = new List<string>();
55 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())))
56 william 61 {
57 william 73 Exception inner = sql_ex.InnerException;
58     if (inner != null)
59     {
60    
61     if (inner.GetType() == typeof(SqlException))
62     {
63     SqlException sql_inner = inner as SqlException;
64     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())))
65     {
66     strs = Logging.GetMessagesFromThreadContextStack("NDC");
67     Logging.ATSAdminLog.Error("Encountered unhandled Exception");
68     }
69     }
70     else
71     {
72     using (log4net.NDC.Push(string.Format("{0}: MESSAGE={1}{2}Diagnostics:{2}{3}", inner.GetType().Name, inner.Message, System.Environment.NewLine, inner.ToString())))
73     {
74     strs = Logging.GetMessagesFromThreadContextStack("NDC");
75     Logging.ATSAdminLog.Error("Encountered unhandled Exception");
76     }
77     }
78     }
79     else
80     {
81     strs = Logging.GetMessagesFromThreadContextStack("NDC");
82     Logging.ATSAdminLog.Error("Encountered unhandled Exception");
83     }
84 william 61 }
85 william 66 StringBuilder builder = new StringBuilder();
86 william 70 foreach (string str in strs) { builder.AppendLine(str); }
87 william 68 result = ShowAbortRetryIgnoreDialog("Encountered unhandled Exception", builder.ToString());
88     if (result == DialogResult.Abort)
89     Application.Exit();
90 william 61 }
91     else
92     {
93 william 70 List<string> strs = new List<string>();
94 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())))
95 william 61 {
96 william 73 Exception inner = e.InnerException;
97     if (inner != null)
98     {
99     using (log4net.NDC.Push(string.Format("{0}: MESSAGE={1}{2}Diagnostics:{2}{3}", inner.GetType().Name, inner.Message, System.Environment.NewLine, inner.ToString())))
100     {
101     strs = Logging.GetMessagesFromThreadContextStack("NDC");
102     Logging.ATSAdminLog.Error("Encountered unhandled Exception");
103     }
104     }
105     else
106     {
107     strs = Logging.GetMessagesFromThreadContextStack("NDC");
108     Logging.ATSAdminLog.Error("Encountered unhandled Exception");
109     }
110 william 70 }
111 william 66 StringBuilder builder = new StringBuilder();
112 william 70 foreach (string str in strs) { builder.AppendLine(str); }
113 william 68 result = ShowAbortRetryIgnoreDialog("Encountered unhandled Exception", builder.ToString());
114     if (result == DialogResult.Abort)
115     Application.Exit();
116 william 61 }
117     }
118 william 68 // Creates the error message and displays it.
119     private static DialogResult ShowAbortRetryIgnoreDialog(string title, string message)
120     {
121     return MessageBox.Show(message, title, MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button1);
122     }
123 william 4 }
124     }

  ViewVC Help
Powered by ViewVC 1.1.22