annotate ServerMonitor/Forms/ServerSummaryForm.cs @ 40:c4fc74593a78 default tip

Mono fix
author Brad Greco <brad@bgreco.net>
date Sat, 13 Jun 2020 13:28:20 -0400
parents 9c0e18d65e8b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10
9e77c0dccb66 Add update checker
Brad Greco <brad@bgreco.net>
parents: 8
diff changeset
1 using NAppUpdate.Framework;
9e77c0dccb66 Add update checker
Brad Greco <brad@bgreco.net>
parents: 8
diff changeset
2 using NAppUpdate.Framework.Sources;
9e77c0dccb66 Add update checker
Brad Greco <brad@bgreco.net>
parents: 8
diff changeset
3 using ServerMonitorApp.Properties;
4
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
4 using System;
0
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
5 using System.Collections.Generic;
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
6 using System.ComponentModel;
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
7 using System.Data;
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
8 using System.Drawing;
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
9 using System.Linq;
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
10 using System.Windows.Forms;
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
11
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
12 namespace ServerMonitorApp
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
13 {
16
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
14 /// <summary>Main application form that shows an overview of all servers.</summary>
0
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
15 public partial class ServerSummaryForm : Form
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
16 {
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
17 private readonly Dictionary<Server, ServerForm> serverForms = new Dictionary<Server, ServerForm>();
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
18 private ServerMonitor monitor;
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
19
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
20 public ServerSummaryForm()
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
21 {
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
22 InitializeComponent();
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
23 }
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
24
16
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
25 private void ServerSummaryForm_Load(object sender, EventArgs e)
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
26 {
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
27 // Restore the window size from the previous session.
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
28 Size size = Settings.Default.SummaryFormSize;
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
29 if (size.Height > 0 && size.Width > 0)
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
30 Size = size;
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
31
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
32 // Resize the images in buttons to fit the button size.
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
33 Helpers.FormatImageButton(NewServerButton);
19
b3128fe10d57 Add About form and license.
Brad Greco <brad@bgreco.net>
parents: 16
diff changeset
34 Helpers.FormatImageButton(AboutButton);
16
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
35 Helpers.FormatImageButton(SettingsButton);
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
36 // Create the global server monitor object.
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
37 monitor = new ServerMonitor(this);
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
38 // Load the server configuration file.
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
39 while (true)
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
40 {
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
41 try
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
42 {
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
43 // If the configuration file is loaded successfully, proceed.
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
44 monitor.LoadServers();
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
45 break;
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
46 }
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
47 catch (Exception ex)
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
48 {
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
49 // If there was an error loading the config file, show it.
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
50 DialogResult result = MessageBox.Show("Could not load servers. Please fix or delete the file " + monitor.ConfigFile + Environment.NewLine + Environment.NewLine
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
51 + "Error details:" + Environment.NewLine + ex.GetAllMessages(),
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
52 "Error loading servers", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
53 // If the error message was cancelled, exit. Otherwise, retry by continuing the loop.
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
54 if (result == DialogResult.Cancel)
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
55 {
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
56 Environment.Exit(1);
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
57 }
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
58 }
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
59 }
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
60 // Listen to server monitor events.
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
61 monitor.CheckStatusChanged += Monitor_CheckStatusChanged;
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
62 // Show the servers.
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
63 RefreshDisplay();
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
64 // If any servers have encrypted private keys, attempt to open them immediately
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
65 // rather than interrupting the user later when they are first used.
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
66 CollectPrivateKeyPasswords();
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
67 CheckForUpdate();
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
68 }
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
69
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
70 /// <summary>Shows a form to edit or create a server.</summary>
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
71 /// <param name="server">The server to edit. If null, a new server will be created.</param>
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
72 /// <param name="activate">Whether the server form should be activated.</param>
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
73 /// <returns>The created or existing server for for the server.</returns>
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
74 private ServerForm ShowServerForm(Server server, bool activate = true)
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
75 {
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
76 bool isNewServer = false;
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
77 if (server == null)
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
78 {
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
79 // Create a new server if none was given.
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
80 server = new Server();
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
81 // The server is added to the server monitor immediately so that
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
82 // checks can be created and run. If the server was created by
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
83 // mistake, it will automatically be removed when the form is closed
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
84 // as long as no information was entered into the form.
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
85 monitor.AddServer(server);
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
86 isNewServer = true;
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
87 }
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
88 if (serverForms.TryGetValue(server, out ServerForm form))
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
89 {
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
90 // If the server form is already open, just activate it if requested.
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
91 if (activate)
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
92 form.Activate();
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
93 }
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
94 else
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
95 {
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
96 // Open a new server form for the server.
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
97 form = new ServerForm(monitor, server, isNewServer);
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
98 // Keep track of the form so it can be activated later if the server is clicked again.
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
99 serverForms[server] = form;
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
100 form.FormClosing += ServerForm_FormClosing;
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
101 form.Show(activate);
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
102 }
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
103 return form;
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
104 }
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
105
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
106 /// <summary>Refreshes the server list with the server monitor data.</summary>
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
107 private void RefreshDisplay()
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
108 {
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
109 // Delete all server controls and recreate them.
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
110 ServerPanel.Controls.Clear();
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
111 foreach (Server server in monitor.Servers)
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
112 {
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
113 // Subscribe to server events.
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
114 server.EnabledChanged -= Server_EnabledChanged;
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
115 server.EnabledChanged += Server_EnabledChanged;
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
116 // Create a server control and add it to the panel.
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
117 ServerSummaryControl control = new ServerSummaryControl(server);
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
118 control.ContextMenuStrip = ServerContextMenu;
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
119 control.Click += ServerSummaryControl_Click;
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
120 ServerPanel.Controls.Add(control);
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
121 }
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
122 // Refresh the form icon that depends on the status of all servers.
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
123 UpdateIcon();
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
124 }
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
125
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
126 /// <summary>Refreshes a single server control.</summary>
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
127 /// <param name="server">The server to refresh.</param>
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
128 private void RefreshServer(Server server)
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
129 {
23
3866c19535fd Fix NullReferenceException when checks are executed on a brand new server.
Brad Greco <brad@bgreco.net>
parents: 19
diff changeset
130 ServerPanel.Controls.Cast<ServerSummaryControl>().FirstOrDefault(c => c.Server == server)?.Refresh();
16
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
131 // The server's status might have changed, so refresh the form icon.
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
132 UpdateIcon();
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
133 }
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
134
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
135 /// <summary>Flashes the taskbar button for a server form.</summary>
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
136 /// <param name="check">The check that needs attention.</param>
4
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
137 public void AlertServerForm(Check check)
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
138 {
16
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
139 // Show the form, but don't activate it since the user did not initiate this event.
4
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
140 ServerForm form = ShowServerForm(check.Server, false);
16
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
141 // Flash the taskbar button.
4
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
142 Win32Helpers.FlashWindowEx(form);
16
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
143 // If the form was not already open, focus the Log tab and display
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
144 // only the log entries for this check. Do not do this if the form
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
145 // was already open since the user might be in the middle of doing
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
146 // something with it.
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
147 if (!serverForms.ContainsKey(check.Server))
4
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
148 {
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
149 form.ShowLog(check);
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
150 }
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
151 }
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
152
16
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
153 /// <summary>Shows a balloon popup with the results of a failed check.</summary>
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
154 /// <param name="check">The check that failed.</param>
4
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
155 public void ShowBalloon(CheckResult result)
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
156 {
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
157 string title = string.Format("{0}: {1} failed", result.Check.Server.Name, result.Check.Name);
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
158 NotifyIcon.Tag = result;
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
159 NotifyIcon.ShowBalloonTip(30000, title, result.Message, GetToolTipIcon(result.CheckStatus));
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
160 }
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
161
16
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
162 /// <summary>Updates the form icon to reflect a summary of the status of all servers.</summary>
8
052aa62cb42a Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents: 6
diff changeset
163 private void UpdateIcon()
052aa62cb42a Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents: 6
diff changeset
164 {
16
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
165 // The status for the summary icon is the most severe status of all servers.
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
166 // When performing the comparison:
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
167 // - Enabled servers use their current status.
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
168 // - If a server is disabled due to a locked private key, report a warning.
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
169 // Otherwise, report success to effectively ignore it.
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
170 // The integer value of the CheckStatus enum increases with the severity,
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
171 // so the maximum value of all servers gives the most severe status.
8
052aa62cb42a Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents: 6
diff changeset
172 CheckStatus status = monitor.Servers
052aa62cb42a Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents: 6
diff changeset
173 .Select(s => s.Enabled
052aa62cb42a Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents: 6
diff changeset
174 ? s.Status
052aa62cb42a Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents: 6
diff changeset
175 : s.KeyStatus == KeyStatus.NeedPassword ? CheckStatus.Warning : CheckStatus.Success)
052aa62cb42a Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents: 6
diff changeset
176 .DefaultIfEmpty(CheckStatus.Success)
052aa62cb42a Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents: 6
diff changeset
177 .Max();
052aa62cb42a Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents: 6
diff changeset
178 Icon = status.GetIcon();
052aa62cb42a Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents: 6
diff changeset
179 NotifyIcon.Icon = Icon;
5
b6fe203af9d5 Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents: 4
diff changeset
180 }
b6fe203af9d5 Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents: 4
diff changeset
181
16
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
182 /// <summary>Prompts the user for the passwords to open all encrypted private keys.</summary>
5
b6fe203af9d5 Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents: 4
diff changeset
183 private void CollectPrivateKeyPasswords()
b6fe203af9d5 Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents: 4
diff changeset
184 {
16
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
185 // List of paths to keyfiles.
6
c1dffaac66fa - Don't show multiple password dialogs for the same key if the first one was cancelled.
Brad Greco <brad@bgreco.net>
parents: 5
diff changeset
186 List<string> triedKeys = new List<string>();
5
b6fe203af9d5 Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents: 4
diff changeset
187 foreach (Server server in monitor.Servers)
b6fe203af9d5 Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents: 4
diff changeset
188 {
16
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
189 // If the same private key is used for multiple servers, don't prompt
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
190 // the user multiple times to open the same keyfile.
6
c1dffaac66fa - Don't show multiple password dialogs for the same key if the first one was cancelled.
Brad Greco <brad@bgreco.net>
parents: 5
diff changeset
191 if (triedKeys.Contains(server.KeyFile))
c1dffaac66fa - Don't show multiple password dialogs for the same key if the first one was cancelled.
Brad Greco <brad@bgreco.net>
parents: 5
diff changeset
192 continue;
16
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
193 // Show the prompt.
5
b6fe203af9d5 Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents: 4
diff changeset
194 ServerForm.OpenPrivateKey(monitor, server, this);
16
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
195 // Keep track of the keyfile so we don't needlessly ask again.
6
c1dffaac66fa - Don't show multiple password dialogs for the same key if the first one was cancelled.
Brad Greco <brad@bgreco.net>
parents: 5
diff changeset
196 triedKeys.Add(server.KeyFile);
5
b6fe203af9d5 Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents: 4
diff changeset
197 }
b6fe203af9d5 Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents: 4
diff changeset
198 }
b6fe203af9d5 Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents: 4
diff changeset
199
16
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
200 /// <summary>Refreshes a server control when the server state changes.</summary>
5
b6fe203af9d5 Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents: 4
diff changeset
201 private void Server_EnabledChanged(object sender, EventArgs e)
b6fe203af9d5 Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents: 4
diff changeset
202 {
b6fe203af9d5 Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents: 4
diff changeset
203 RefreshServer((Server)sender);
b6fe203af9d5 Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents: 4
diff changeset
204 }
b6fe203af9d5 Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents: 4
diff changeset
205
16
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
206 /// <summary>Refreshes a server control when the server status might have changed.</summary>
4
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
207 private void Monitor_CheckStatusChanged(object sender, CheckStatusChangedEventArgs e)
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
208 {
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
209 if (e.CheckResult != null)
8
052aa62cb42a Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents: 6
diff changeset
210 {
5
b6fe203af9d5 Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents: 4
diff changeset
211 RefreshServer(e.Check.Server);
8
052aa62cb42a Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents: 6
diff changeset
212 }
4
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
213 }
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
214
16
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
215 /// <summary>Gets a Windows tooltip icon based on the severity of the message.</summary>
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
216 /// <param name="status">The status of the check that will be reported in the balloon tip.</param>
4
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
217 private ToolTipIcon GetToolTipIcon(CheckStatus status)
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
218 {
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
219 switch (status)
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
220 {
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
221 case CheckStatus.Error: return ToolTipIcon.Error;
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
222 case CheckStatus.Warning: return ToolTipIcon.Warning;
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
223 case CheckStatus.Information: return ToolTipIcon.Info;
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
224 default: return ToolTipIcon.None;
0
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
225 }
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
226 }
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
227
16
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
228 /// <summary>Shows a server form when a server control is clicked.</summary>
0
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
229 private void ServerSummaryControl_Click(object sender, EventArgs e)
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
230 {
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
231 ShowServerForm(((ServerSummaryControl)sender).Server);
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
232 }
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
233
16
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
234 /// <summary>Handles the closing of a server form.</summary>
0
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
235 private void ServerForm_FormClosing(object sender, FormClosingEventArgs e)
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
236 {
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
237 ServerForm form = (ServerForm)sender;
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
238 form.FormClosing -= ServerForm_FormClosing;
4
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
239 Server server = form.Server;
16
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
240 // Remove the closed form from the list of open forms.
0
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
241 serverForms.Remove(form.Server);
16
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
242 // If there is no user data associated with the server, it can be deleted.
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
243 // This usually happens when the New Server button is clicked and the server form
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
244 // is closed without entering any information.
4
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
245 if (server.IsEmpty())
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
246 {
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
247 monitor.DeleteServer(server);
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
248 }
0
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
249 RefreshDisplay();
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
250 }
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
251
16
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
252 /// <summary>Shows a server form to create a new server.</summary>
0
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
253 private void NewServerButton_Click(object sender, EventArgs e)
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
254 {
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
255 ShowServerForm(null);
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
256 }
4
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
257
16
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
258 /// <summary>Hides the main form instead of exiting the application based on user preferences.</summary>
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
259 /// <remarks>Allows the monitor to run in the background without being shown in the taskbar.</remarks>
4
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
260 private void ServerSummaryForm_FormClosing(object sender, FormClosingEventArgs e)
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
261 {
11
75ca86e0862c Add setting to hide to notification area.
Brad Greco <brad@bgreco.net>
parents: 10
diff changeset
262 if ((e.CloseReason == CloseReason.None || e.CloseReason == CloseReason.UserClosing) && Settings.Default.HideToNotificationArea)
4
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
263 {
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
264 Hide();
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
265 e.Cancel = true;
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
266 }
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
267 }
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
268
16
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
269 /// <summary>Shows the settings form.</summary>
4
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
270 private void SettingsButton_Click(object sender, EventArgs e)
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
271 {
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
272 new SettingsForm().Show();
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
273 }
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
274
16
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
275 /// <summary>Shows the details of a failed check when the balloon notification is clicked.</summary>
4
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
276 private void NotifyIcon_BalloonTipClicked(object sender, EventArgs e)
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
277 {
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
278 CheckResult result = (CheckResult)(sender as NotifyIcon).Tag;
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
279 ServerForm form = ShowServerForm(result.Check.Server);
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
280 form.ShowLog(result.Check);
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
281 form.WindowState = FormWindowState.Normal;
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
282 }
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
283
16
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
284 /// <summary>Handles the server context menu.</summary>
4
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
285 private void ServerContextMenu_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
286 {
5
b6fe203af9d5 Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents: 4
diff changeset
287 Server server = GetClickedServer((ContextMenuStrip)e.ClickedItem.Owner);
4
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
288 if (e.ClickedItem == DeleteServerMenuItem)
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
289 {
16
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
290 // Close the menu immediately so it doesn't stay open while the messagebox is shown.
4
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
291 ServerContextMenu.Close();
16
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
292 // Show the server delete confirmation dialog. No option to not ask again
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
293 // since it's a rare and very destructive event.
4
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
294 DialogResult result = MessageBox.Show(
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
295 string.Format("The server \"{0}\" and its {1} {2} will be deleted.", server.Name, server.Checks.Count, server.Checks.Count == 1 ? "check" : "checks"),
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
296 "Delete server",
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
297 MessageBoxButtons.OKCancel,
16
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
298 MessageBoxIcon.Warning);
4
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
299 if (result == DialogResult.OK)
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
300 {
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
301 monitor.DeleteServer(server);
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
302 RefreshDisplay();
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
303 }
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
304 }
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
305 else if (e.ClickedItem == ToggleEnableServerMenuItem)
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
306 {
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
307 bool enable = ToggleEnableServerMenuItem.Text == "Enable";
5
b6fe203af9d5 Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents: 4
diff changeset
308 if (enable)
b6fe203af9d5 Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents: 4
diff changeset
309 {
16
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
310 // Close the menu immediately so it doesn't stay open while the messagebox is shown.
5
b6fe203af9d5 Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents: 4
diff changeset
311 ServerContextMenu.Close();
16
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
312 // Attempt to open the private key for the server immediately since it has not
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
313 // been opened yet.
5
b6fe203af9d5 Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents: 4
diff changeset
314 ServerForm.OpenPrivateKey(monitor, server, this);
b6fe203af9d5 Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents: 4
diff changeset
315 }
4
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
316 server.Enabled = enable;
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
317 RefreshDisplay();
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
318 }
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
319 }
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
320
16
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
321 /// <summary>Activates the appropriate Enable/Disable menu option based on the server's current state.</summary>
4
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
322 private void ServerContextMenu_Opening(object sender, CancelEventArgs e)
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
323 {
5
b6fe203af9d5 Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents: 4
diff changeset
324 Server server = GetClickedServer((ContextMenuStrip)sender);
4
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
325 ToggleEnableServerMenuItem.Text = server.Enabled ? "Disable" : "Enable";
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
326 }
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
327
16
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
328 /// <summary>Gets the server corresponding to a server context menu.</summary>
5
b6fe203af9d5 Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents: 4
diff changeset
329 private Server GetClickedServer(ContextMenuStrip menu)
4
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
330 {
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
331 return ((ServerSummaryControl)menu.SourceControl).Server;
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents: 0
diff changeset
332 }
8
052aa62cb42a Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents: 6
diff changeset
333
16
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
334 /// <summary>Saves the window size after it is resized so it can be restored next time the program is run.</summary>
8
052aa62cb42a Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents: 6
diff changeset
335 private void ServerSummaryForm_ResizeEnd(object sender, EventArgs e)
052aa62cb42a Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents: 6
diff changeset
336 {
052aa62cb42a Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents: 6
diff changeset
337 Settings.Default.SummaryFormSize = Size;
052aa62cb42a Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents: 6
diff changeset
338 Settings.Default.Save();
052aa62cb42a Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents: 6
diff changeset
339 }
052aa62cb42a Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents: 6
diff changeset
340
16
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
341 /// <summary>Shows the main form when the WM_SHOWMONITOR message is received.</summary>
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
342 /// <remarks>
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
343 /// This is used to make this a single-instance application. When a second copy of the program
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
344 /// is launched, it sends this message to activate the first copy and then exits.
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
345 /// </remarks>
8
052aa62cb42a Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents: 6
diff changeset
346 protected override void WndProc(ref Message m)
052aa62cb42a Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents: 6
diff changeset
347 {
052aa62cb42a Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents: 6
diff changeset
348 if (m.Msg == Win32Helpers.WM_SHOWMONITOR)
052aa62cb42a Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents: 6
diff changeset
349 ShowWindow();
052aa62cb42a Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents: 6
diff changeset
350 base.WndProc(ref m);
052aa62cb42a Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents: 6
diff changeset
351 }
052aa62cb42a Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents: 6
diff changeset
352
16
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
353 /// <summary>Handles clicks on the notification area icon.</summary>
8
052aa62cb42a Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents: 6
diff changeset
354 private void NotifyIcon_MouseClick(object sender, MouseEventArgs e)
052aa62cb42a Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents: 6
diff changeset
355 {
052aa62cb42a Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents: 6
diff changeset
356 if (e.Button == MouseButtons.Left)
052aa62cb42a Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents: 6
diff changeset
357 ShowWindow();
052aa62cb42a Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents: 6
diff changeset
358 else if (e.Button == MouseButtons.Right)
052aa62cb42a Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents: 6
diff changeset
359 NotificationIconMenu.Show();
052aa62cb42a Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents: 6
diff changeset
360 }
052aa62cb42a Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents: 6
diff changeset
361
16
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
362 /// <summary>Shows the window.</summary>
8
052aa62cb42a Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents: 6
diff changeset
363 private void ShowWindow()
052aa62cb42a Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents: 6
diff changeset
364 {
052aa62cb42a Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents: 6
diff changeset
365 if (WindowState == FormWindowState.Minimized)
052aa62cb42a Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents: 6
diff changeset
366 WindowState = FormWindowState.Normal;
16
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
367 // Do various things to try to get this window on top.
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
368 // We only do this as a result of user input, so it's ok. ;)
8
052aa62cb42a Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents: 6
diff changeset
369 Show();
052aa62cb42a Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents: 6
diff changeset
370 TopMost = true;
052aa62cb42a Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents: 6
diff changeset
371 TopMost = false;
052aa62cb42a Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents: 6
diff changeset
372 Activate();
052aa62cb42a Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents: 6
diff changeset
373 }
052aa62cb42a Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents: 6
diff changeset
374
16
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
375 /// <summary>Handles clicks on the notification icon menu.</summary>
8
052aa62cb42a Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents: 6
diff changeset
376 private void NotificationIconMenu_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
052aa62cb42a Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents: 6
diff changeset
377 {
052aa62cb42a Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents: 6
diff changeset
378 if (e.ClickedItem == ShowServerMonitorMenuItem)
052aa62cb42a Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents: 6
diff changeset
379 ShowWindow();
052aa62cb42a Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents: 6
diff changeset
380 else if (e.ClickedItem == ExitMenuItem)
052aa62cb42a Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents: 6
diff changeset
381 Application.Exit();
052aa62cb42a Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents: 6
diff changeset
382 }
10
9e77c0dccb66 Add update checker
Brad Greco <brad@bgreco.net>
parents: 8
diff changeset
383
16
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
384 /// <summary>Begins checking for program updates in the background.</summary>
10
9e77c0dccb66 Add update checker
Brad Greco <brad@bgreco.net>
parents: 8
diff changeset
385 private void CheckForUpdate()
9e77c0dccb66 Add update checker
Brad Greco <brad@bgreco.net>
parents: 8
diff changeset
386 {
34
9c0e18d65e8b Build NuGet from source instead of using the NuGet package to fix the update notification always showing when the program is run from Windows startup.
Brad Greco <brad@bgreco.net>
parents: 30
diff changeset
387 // The latest NuGet package of NAppUpdate (0.5.1) always thinks that an update is available
9c0e18d65e8b Build NuGet from source instead of using the NuGet package to fix the update notification always showing when the program is run from Windows startup.
Brad Greco <brad@bgreco.net>
parents: 30
diff changeset
388 // when the program is run from Windows startup (https://github.com/synhershko/NAppUpdate/pull/122).
9c0e18d65e8b Build NuGet from source instead of using the NuGet package to fix the update notification always showing when the program is run from Windows startup.
Brad Greco <brad@bgreco.net>
parents: 30
diff changeset
389 // The fix has already been made but not released, so the version of NAppUpdate included in
9c0e18d65e8b Build NuGet from source instead of using the NuGet package to fix the update notification always showing when the program is run from Windows startup.
Brad Greco <brad@bgreco.net>
parents: 30
diff changeset
390 // this project was built from source instead of using the NuGet package.
10
9e77c0dccb66 Add update checker
Brad Greco <brad@bgreco.net>
parents: 8
diff changeset
391 UpdateManager manager = UpdateManager.Instance;
16
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
392 // Make the update manager happy if the program was just restarted to apply an update.
10
9e77c0dccb66 Add update checker
Brad Greco <brad@bgreco.net>
parents: 8
diff changeset
393 manager.ReinstateIfRestarted();
30
b0af6b4bed4d Change update URL to real URL.
Brad Greco <brad@bgreco.net>
parents: 23
diff changeset
394 manager.UpdateSource = new SimpleWebSource("https://www.bgreco.net/servermonitor/update.xml");
10
9e77c0dccb66 Add update checker
Brad Greco <brad@bgreco.net>
parents: 8
diff changeset
395 if (manager.State == UpdateManager.UpdateProcessState.NotChecked)
9e77c0dccb66 Add update checker
Brad Greco <brad@bgreco.net>
parents: 8
diff changeset
396 manager.BeginCheckForUpdates(CheckForUpdatesCallback, null);
9e77c0dccb66 Add update checker
Brad Greco <brad@bgreco.net>
parents: 8
diff changeset
397 }
9e77c0dccb66 Add update checker
Brad Greco <brad@bgreco.net>
parents: 8
diff changeset
398
16
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
399 /// <summary>Callback after the program update check completes.</summary>
10
9e77c0dccb66 Add update checker
Brad Greco <brad@bgreco.net>
parents: 8
diff changeset
400 private void CheckForUpdatesCallback(IAsyncResult result)
9e77c0dccb66 Add update checker
Brad Greco <brad@bgreco.net>
parents: 8
diff changeset
401 {
9e77c0dccb66 Add update checker
Brad Greco <brad@bgreco.net>
parents: 8
diff changeset
402 UpdateManager manager = UpdateManager.Instance;
9e77c0dccb66 Add update checker
Brad Greco <brad@bgreco.net>
parents: 8
diff changeset
403 if (manager.UpdatesAvailable > 0)
9e77c0dccb66 Add update checker
Brad Greco <brad@bgreco.net>
parents: 8
diff changeset
404 {
16
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
405 // Extract the new version number from the result.
10
9e77c0dccb66 Add update checker
Brad Greco <brad@bgreco.net>
parents: 8
diff changeset
406 GetUpdateInfo(out string version, out string _);
16
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
407 // If the user has not chosen to ignore this update, show a notification.
10
9e77c0dccb66 Add update checker
Brad Greco <brad@bgreco.net>
parents: 8
diff changeset
408 if (Settings.Default.IgnoreUpdate != version)
9e77c0dccb66 Add update checker
Brad Greco <brad@bgreco.net>
parents: 8
diff changeset
409 Invoke((MethodInvoker)(() => UpdatePanel.Show()));
9e77c0dccb66 Add update checker
Brad Greco <brad@bgreco.net>
parents: 8
diff changeset
410 }
9e77c0dccb66 Add update checker
Brad Greco <brad@bgreco.net>
parents: 8
diff changeset
411 }
9e77c0dccb66 Add update checker
Brad Greco <brad@bgreco.net>
parents: 8
diff changeset
412
16
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
413 /// <summary>Applies the program updates.</summary>
10
9e77c0dccb66 Add update checker
Brad Greco <brad@bgreco.net>
parents: 8
diff changeset
414 private void PrepareUpdatesCallback(IAsyncResult result)
9e77c0dccb66 Add update checker
Brad Greco <brad@bgreco.net>
parents: 8
diff changeset
415 {
9e77c0dccb66 Add update checker
Brad Greco <brad@bgreco.net>
parents: 8
diff changeset
416 UpdateManager manager = UpdateManager.Instance;
9e77c0dccb66 Add update checker
Brad Greco <brad@bgreco.net>
parents: 8
diff changeset
417 manager.EndCheckForUpdates(result);
9e77c0dccb66 Add update checker
Brad Greco <brad@bgreco.net>
parents: 8
diff changeset
418 manager.ApplyUpdates(true);
9e77c0dccb66 Add update checker
Brad Greco <brad@bgreco.net>
parents: 8
diff changeset
419 }
9e77c0dccb66 Add update checker
Brad Greco <brad@bgreco.net>
parents: 8
diff changeset
420
16
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
421 /// <summary>Shows information about a program update when the notification is clicked.</summary>
10
9e77c0dccb66 Add update checker
Brad Greco <brad@bgreco.net>
parents: 8
diff changeset
422 private void UpdateLabel_Click(object sender, EventArgs e)
9e77c0dccb66 Add update checker
Brad Greco <brad@bgreco.net>
parents: 8
diff changeset
423 {
16
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
424 // Extract the update information from the update manager result.
10
9e77c0dccb66 Add update checker
Brad Greco <brad@bgreco.net>
parents: 8
diff changeset
425 GetUpdateInfo(out string version, out string changeMessage);
9e77c0dccb66 Add update checker
Brad Greco <brad@bgreco.net>
parents: 8
diff changeset
426 string message = "Server Monitor version {0} is available for download." + Environment.NewLine
9e77c0dccb66 Add update checker
Brad Greco <brad@bgreco.net>
parents: 8
diff changeset
427 + Environment.NewLine
9e77c0dccb66 Add update checker
Brad Greco <brad@bgreco.net>
parents: 8
diff changeset
428 + "What's new:" + Environment.NewLine
9e77c0dccb66 Add update checker
Brad Greco <brad@bgreco.net>
parents: 8
diff changeset
429 + "{1}" + Environment.NewLine
9e77c0dccb66 Add update checker
Brad Greco <brad@bgreco.net>
parents: 8
diff changeset
430 + Environment.NewLine
9e77c0dccb66 Add update checker
Brad Greco <brad@bgreco.net>
parents: 8
diff changeset
431 + "Would you like to download and apply the update now?";
9e77c0dccb66 Add update checker
Brad Greco <brad@bgreco.net>
parents: 8
diff changeset
432 using (UpdateDialog dialog = new UpdateDialog { Message = string.Format(message, version, changeMessage) })
9e77c0dccb66 Add update checker
Brad Greco <brad@bgreco.net>
parents: 8
diff changeset
433 {
9e77c0dccb66 Add update checker
Brad Greco <brad@bgreco.net>
parents: 8
diff changeset
434 DialogResult result = dialog.ShowDialog();
16
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
435 // If the user declined the update and asked not to be notified again,
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
436 // save the preference so they will not be asked again for this version.
10
9e77c0dccb66 Add update checker
Brad Greco <brad@bgreco.net>
parents: 8
diff changeset
437 if (dialog.Checked && result == DialogResult.Cancel)
9e77c0dccb66 Add update checker
Brad Greco <brad@bgreco.net>
parents: 8
diff changeset
438 {
9e77c0dccb66 Add update checker
Brad Greco <brad@bgreco.net>
parents: 8
diff changeset
439 Settings.Default.IgnoreUpdate = version;
9e77c0dccb66 Add update checker
Brad Greco <brad@bgreco.net>
parents: 8
diff changeset
440 Settings.Default.Save();
9e77c0dccb66 Add update checker
Brad Greco <brad@bgreco.net>
parents: 8
diff changeset
441 UpdatePanel.Hide();
9e77c0dccb66 Add update checker
Brad Greco <brad@bgreco.net>
parents: 8
diff changeset
442 }
16
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
443 // If Yes was not chosen, do not apply the update.
10
9e77c0dccb66 Add update checker
Brad Greco <brad@bgreco.net>
parents: 8
diff changeset
444 if (result != DialogResult.OK)
9e77c0dccb66 Add update checker
Brad Greco <brad@bgreco.net>
parents: 8
diff changeset
445 return;
9e77c0dccb66 Add update checker
Brad Greco <brad@bgreco.net>
parents: 8
diff changeset
446 }
9e77c0dccb66 Add update checker
Brad Greco <brad@bgreco.net>
parents: 8
diff changeset
447 UpdateManager.Instance.BeginPrepareUpdates(PrepareUpdatesCallback, null);
9e77c0dccb66 Add update checker
Brad Greco <brad@bgreco.net>
parents: 8
diff changeset
448 }
9e77c0dccb66 Add update checker
Brad Greco <brad@bgreco.net>
parents: 8
diff changeset
449
16
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
450 /// <summary>Extracts the update information from the update manager result.</summary>
10
9e77c0dccb66 Add update checker
Brad Greco <brad@bgreco.net>
parents: 8
diff changeset
451 private void GetUpdateInfo(out string version, out string changeMessage)
9e77c0dccb66 Add update checker
Brad Greco <brad@bgreco.net>
parents: 8
diff changeset
452 {
16
7626b099aefd More comments.
Brad Greco <brad@bgreco.net>
parents: 11
diff changeset
453 // The update description is in the form {version}:{change message}.
10
9e77c0dccb66 Add update checker
Brad Greco <brad@bgreco.net>
parents: 8
diff changeset
454 string[] parts = UpdateManager.Instance.Tasks.First().Description.Split(new char[] { ':' }, 2);
9e77c0dccb66 Add update checker
Brad Greco <brad@bgreco.net>
parents: 8
diff changeset
455 version = parts[0];
9e77c0dccb66 Add update checker
Brad Greco <brad@bgreco.net>
parents: 8
diff changeset
456 changeMessage = parts[1];
9e77c0dccb66 Add update checker
Brad Greco <brad@bgreco.net>
parents: 8
diff changeset
457 }
19
b3128fe10d57 Add About form and license.
Brad Greco <brad@bgreco.net>
parents: 16
diff changeset
458
b3128fe10d57 Add About form and license.
Brad Greco <brad@bgreco.net>
parents: 16
diff changeset
459 private void AboutButton_Click(object sender, EventArgs e)
b3128fe10d57 Add About form and license.
Brad Greco <brad@bgreco.net>
parents: 16
diff changeset
460 {
b3128fe10d57 Add About form and license.
Brad Greco <brad@bgreco.net>
parents: 16
diff changeset
461 new AboutForm().Show();
b3128fe10d57 Add About form and license.
Brad Greco <brad@bgreco.net>
parents: 16
diff changeset
462 }
0
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
463 }
3e1a2131f897 Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff changeset
464 }