diff ServerMonitor/Forms/ServerSummaryForm.cs @ 5:b6fe203af9d5

Private key passwords and validation
author Brad Greco <brad@bgreco.net>
date Thu, 28 Feb 2019 21:19:32 -0500
parents 3142e52cbe69
children c1dffaac66fa
line wrap: on
line diff
--- a/ServerMonitor/Forms/ServerSummaryForm.cs	Sun Feb 10 20:51:26 2019 -0500
+++ b/ServerMonitor/Forms/ServerSummaryForm.cs	Thu Feb 28 21:19:32 2019 -0500
@@ -64,6 +64,7 @@
             NotifyIcon.Icon = new Icon(Icon, 16, 16);
             monitor.CheckStatusChanged += Monitor_CheckStatusChanged;
             RefreshDisplay();
+            CollectPrivateKeyPasswords();
         }
 
         private ServerForm ShowServerForm(Server server, bool activate = true)
@@ -95,6 +96,8 @@
             ServerPanel.Controls.Clear();
             foreach (Server server in monitor.Servers)
             {
+                server.EnabledChanged -= Server_EnabledChanged;
+                server.EnabledChanged += Server_EnabledChanged;
                 ServerSummaryControl control = new ServerSummaryControl(server);
                 control.ContextMenuStrip = ServerContextMenu;
                 control.Click += ServerSummaryControl_Click;
@@ -102,10 +105,28 @@
             }
         }
 
+        private void RefreshServer(Server server)
+        {
+            ServerPanel.Controls.Cast<ServerSummaryControl>().FirstOrDefault(c => c.Server == server).Refresh();
+        }
+
+        private void CollectPrivateKeyPasswords()
+        {
+            foreach (Server server in monitor.Servers)
+            {
+                ServerForm.OpenPrivateKey(monitor, server, this);
+            }
+        }
+
+        private void Server_EnabledChanged(object sender, EventArgs e)
+        {
+            RefreshServer((Server)sender);
+        }
+
         private void Monitor_CheckStatusChanged(object sender, CheckStatusChangedEventArgs e)
         {
             if (e.CheckResult != null)
-                ServerPanel.Controls.Cast<ServerSummaryControl>().FirstOrDefault(c => c.Server == e.Check.Server).Refresh();
+                RefreshServer(e.Check.Server);
         }
 
         private ToolTipIcon GetToolTipIcon(CheckStatus status)
@@ -166,7 +187,7 @@
 
         private void ServerContextMenu_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
         {
-            Server server = getClickedServer((ContextMenuStrip)e.ClickedItem.Owner);
+            Server server = GetClickedServer((ContextMenuStrip)e.ClickedItem.Owner);
             if (e.ClickedItem == DeleteServerMenuItem)
             {
                 ServerContextMenu.Close();
@@ -184,6 +205,11 @@
             else if (e.ClickedItem == ToggleEnableServerMenuItem)
             {
                 bool enable = ToggleEnableServerMenuItem.Text == "Enable";
+                if (enable)
+                {
+                    ServerContextMenu.Close();
+                    ServerForm.OpenPrivateKey(monitor, server, this);
+                }
                 server.Enabled = enable;
                 RefreshDisplay();
             }
@@ -191,11 +217,11 @@
 
         private void ServerContextMenu_Opening(object sender, CancelEventArgs e)
         {
-            Server server = getClickedServer((ContextMenuStrip)sender);
+            Server server = GetClickedServer((ContextMenuStrip)sender);
             ToggleEnableServerMenuItem.Text = server.Enabled ? "Disable" : "Enable";
         }
 
-        private Server getClickedServer(ContextMenuStrip menu)
+        private Server GetClickedServer(ContextMenuStrip menu)
         {
             return ((ServerSummaryControl)menu.SourceControl).Server;
         }