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

Annotation of /trunk/TSControlPanel/Program.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 113 - (hide annotations) (download)
Sat Jul 14 07:18:30 2012 UTC (9 years ago) by william
File size: 6189 byte(s)
remove all calls to Logging.Initialize() outsite of the Logging class

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

  ViewVC Help
Powered by ViewVC 1.1.22