annotate ServerMonitor/Program.cs @ 32:2342e9459444

Fix schedule times not being saved.
author Brad Greco <brad@bgreco.net>
date Sun, 16 Jun 2019 16:55:14 -0400
parents 68d7834dc28e
children 7645122aa7a9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
1 using System;
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
2 using System.Linq;
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
3 using System.Threading;
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
4 using System.Windows.Forms;
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
5
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
6 namespace ServerMonitorApp
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
7 {
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
8 static class Program
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
9 {
8
052aa62cb42a Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
10 static Mutex mutex = new Mutex(true, "c681570e-dff4-45fa-bdca-d8ca928a0f8a");
052aa62cb42a Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
11
0
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
12 /// <summary>
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
13 /// The main entry point for the application.
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
14 /// </summary>
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
15 [STAThread]
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
16 static void Main()
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
17 {
17
68d7834dc28e More comments.
Brad Greco <brad@bgreco.net>
parents: 8
diff changeset
18 // Check if the program is already running.
8
052aa62cb42a Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
19 if (mutex.WaitOne(TimeSpan.Zero, true))
052aa62cb42a Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
20 {
17
68d7834dc28e More comments.
Brad Greco <brad@bgreco.net>
parents: 8
diff changeset
21 // Show unhandled exceptions to the user.
8
052aa62cb42a Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
22 Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);
052aa62cb42a Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
23 Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
052aa62cb42a Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
24 AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
0
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
25
8
052aa62cb42a Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
26 Application.EnableVisualStyles();
052aa62cb42a Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
27 Application.SetCompatibleTextRenderingDefault(false);
052aa62cb42a Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
28 Application.Run(new ServerSummaryForm());
052aa62cb42a Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
29 }
052aa62cb42a Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
30 else
052aa62cb42a Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
31 {
17
68d7834dc28e More comments.
Brad Greco <brad@bgreco.net>
parents: 8
diff changeset
32 // If the program is already running, send a message to the main form
68d7834dc28e More comments.
Brad Greco <brad@bgreco.net>
parents: 8
diff changeset
33 // asking it to show itself, then exit.
8
052aa62cb42a Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
34 Win32Helpers.PostMessage(
052aa62cb42a Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
35 (IntPtr)Win32Helpers.HWND_BROADCAST,
052aa62cb42a Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
36 Win32Helpers.WM_SHOWMONITOR,
052aa62cb42a Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
37 IntPtr.Zero,
052aa62cb42a Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
38 IntPtr.Zero);
052aa62cb42a Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
39 }
0
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
40 }
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
41
17
68d7834dc28e More comments.
Brad Greco <brad@bgreco.net>
parents: 8
diff changeset
42 /// <summary>Shows unhandled exceptions in a message box.</summary>
0
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
43 static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
44 {
17
68d7834dc28e More comments.
Brad Greco <brad@bgreco.net>
parents: 8
diff changeset
45 if (!System.Diagnostics.Debugger.IsAttached)
0
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
46 ShowError(e.Exception);
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
47 }
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
48
17
68d7834dc28e More comments.
Brad Greco <brad@bgreco.net>
parents: 8
diff changeset
49 /// <summary>Shows unhandled exceptions in a message box.</summary>
0
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
50 static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
51 {
17
68d7834dc28e More comments.
Brad Greco <brad@bgreco.net>
parents: 8
diff changeset
52 if (!System.Diagnostics.Debugger.IsAttached)
0
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
53 ShowError(e.ExceptionObject as Exception);
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
54 }
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
55
17
68d7834dc28e More comments.
Brad Greco <brad@bgreco.net>
parents: 8
diff changeset
56 /// <summary>Shows exception details in a message box.</summary>
68d7834dc28e More comments.
Brad Greco <brad@bgreco.net>
parents: 8
diff changeset
57 /// <param name="e">The exception to show.</param>
0
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
58 static void ShowError(Exception e)
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
59 {
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
60 string simpleStackTrace = string.Join(Environment.NewLine, new System.Diagnostics.StackTrace(e).GetFrames()
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
61 .Select(f => f.GetMethod().DeclaringType.Name + "." + f.GetMethod().Name).ToArray());
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
62 MessageBox.Show(e.Message + Environment.NewLine + Environment.NewLine + simpleStackTrace, "Server Monitor Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
63 }
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
64 }
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
65 }