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

Annotation of /trunk/TSControlPanel/Program.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 70 - (hide annotations) (download)
Thu Jul 12 20:47:35 2012 UTC (8 years, 11 months ago) by william
File size: 3972 byte(s)
+ get NDC ThreadContectStack using reflection

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     AppDomain currentDomain = AppDomain.CurrentDomain;
20     currentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
21     Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException, true);
22    
23 william 65 Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
24    
25 william 4 Application.EnableVisualStyles();
26     Application.SetCompatibleTextRenderingDefault(false);
27    
28     frmClientProperties objCustomDialogBox = new frmClientProperties();
29     objCustomDialogBox.dialogMode = frmClientProperties.ATSClientMode.CONTROL_PANEL; // Select the mode to run the form in.
30     Application.Run(objCustomDialogBox);
31     }
32 william 65
33     static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
34     {
35     CurrentDomain_UnhandledException(sender, new UnhandledExceptionEventArgs(e.Exception, false));
36     }
37 william 61 static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs args)
38     {
39 william 68 DialogResult result = DialogResult.Cancel;
40 william 61 Exception e = (Exception)args.ExceptionObject;
41     if (e == null)
42     {
43 william 66 Logging.TSControlPanelLog.Error("Encountered unhandled Exception, but the exception was null");
44 william 61 return;
45     }
46     if (e.GetType() == typeof(SqlException))
47     {
48     SqlException sql_ex = (e as SqlException);
49 william 70 List<string> strs = new List<string>();
50 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())))
51 william 61 {
52 william 70 strs = Logging.GetMessagesFromThreadContextStack("NDC");
53     Logging.ATSAdminLog.Error("Encountered unhandled Exception");
54 william 61 }
55 william 66 StringBuilder builder = new StringBuilder();
56 william 70 foreach (string str in strs) { builder.AppendLine(str); }
57 william 68 result = ShowAbortRetryIgnoreDialog("Encountered unhandled Exception", builder.ToString());
58     if (result == DialogResult.Abort)
59     Application.Exit();
60 william 61 }
61     else
62     {
63 william 70 List<string> strs = new List<string>();
64 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())))
65 william 61 {
66 william 70 strs = Logging.GetMessagesFromThreadContextStack("NDC");
67     Logging.ATSAdminLog.Error("Encountered unhandled Exception");
68     }
69 william 66 StringBuilder builder = new StringBuilder();
70 william 70 foreach (string str in strs) { builder.AppendLine(str); }
71 william 68 result = ShowAbortRetryIgnoreDialog("Encountered unhandled Exception", builder.ToString());
72     if (result == DialogResult.Abort)
73     Application.Exit();
74 william 61 }
75     }
76 william 68 // Creates the error message and displays it.
77     private static DialogResult ShowAbortRetryIgnoreDialog(string title, string message)
78     {
79     return MessageBox.Show(message, title, MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button1);
80     }
81 william 4 }
82     }

  ViewVC Help
Powered by ViewVC 1.1.22