Mercurial > servermonitor
comparison 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 |
comparison
equal
deleted
inserted
replaced
4:3142e52cbe69 | 5:b6fe203af9d5 |
---|---|
62 } | 62 } |
63 } | 63 } |
64 NotifyIcon.Icon = new Icon(Icon, 16, 16); | 64 NotifyIcon.Icon = new Icon(Icon, 16, 16); |
65 monitor.CheckStatusChanged += Monitor_CheckStatusChanged; | 65 monitor.CheckStatusChanged += Monitor_CheckStatusChanged; |
66 RefreshDisplay(); | 66 RefreshDisplay(); |
67 CollectPrivateKeyPasswords(); | |
67 } | 68 } |
68 | 69 |
69 private ServerForm ShowServerForm(Server server, bool activate = true) | 70 private ServerForm ShowServerForm(Server server, bool activate = true) |
70 { | 71 { |
71 bool isNewServer = false; | 72 bool isNewServer = false; |
93 private void RefreshDisplay() | 94 private void RefreshDisplay() |
94 { | 95 { |
95 ServerPanel.Controls.Clear(); | 96 ServerPanel.Controls.Clear(); |
96 foreach (Server server in monitor.Servers) | 97 foreach (Server server in monitor.Servers) |
97 { | 98 { |
99 server.EnabledChanged -= Server_EnabledChanged; | |
100 server.EnabledChanged += Server_EnabledChanged; | |
98 ServerSummaryControl control = new ServerSummaryControl(server); | 101 ServerSummaryControl control = new ServerSummaryControl(server); |
99 control.ContextMenuStrip = ServerContextMenu; | 102 control.ContextMenuStrip = ServerContextMenu; |
100 control.Click += ServerSummaryControl_Click; | 103 control.Click += ServerSummaryControl_Click; |
101 ServerPanel.Controls.Add(control); | 104 ServerPanel.Controls.Add(control); |
102 } | 105 } |
103 } | 106 } |
104 | 107 |
108 private void RefreshServer(Server server) | |
109 { | |
110 ServerPanel.Controls.Cast<ServerSummaryControl>().FirstOrDefault(c => c.Server == server).Refresh(); | |
111 } | |
112 | |
113 private void CollectPrivateKeyPasswords() | |
114 { | |
115 foreach (Server server in monitor.Servers) | |
116 { | |
117 ServerForm.OpenPrivateKey(monitor, server, this); | |
118 } | |
119 } | |
120 | |
121 private void Server_EnabledChanged(object sender, EventArgs e) | |
122 { | |
123 RefreshServer((Server)sender); | |
124 } | |
125 | |
105 private void Monitor_CheckStatusChanged(object sender, CheckStatusChangedEventArgs e) | 126 private void Monitor_CheckStatusChanged(object sender, CheckStatusChangedEventArgs e) |
106 { | 127 { |
107 if (e.CheckResult != null) | 128 if (e.CheckResult != null) |
108 ServerPanel.Controls.Cast<ServerSummaryControl>().FirstOrDefault(c => c.Server == e.Check.Server).Refresh(); | 129 RefreshServer(e.Check.Server); |
109 } | 130 } |
110 | 131 |
111 private ToolTipIcon GetToolTipIcon(CheckStatus status) | 132 private ToolTipIcon GetToolTipIcon(CheckStatus status) |
112 { | 133 { |
113 switch (status) | 134 switch (status) |
164 form.WindowState = FormWindowState.Normal; | 185 form.WindowState = FormWindowState.Normal; |
165 } | 186 } |
166 | 187 |
167 private void ServerContextMenu_ItemClicked(object sender, ToolStripItemClickedEventArgs e) | 188 private void ServerContextMenu_ItemClicked(object sender, ToolStripItemClickedEventArgs e) |
168 { | 189 { |
169 Server server = getClickedServer((ContextMenuStrip)e.ClickedItem.Owner); | 190 Server server = GetClickedServer((ContextMenuStrip)e.ClickedItem.Owner); |
170 if (e.ClickedItem == DeleteServerMenuItem) | 191 if (e.ClickedItem == DeleteServerMenuItem) |
171 { | 192 { |
172 ServerContextMenu.Close(); | 193 ServerContextMenu.Close(); |
173 DialogResult result = MessageBox.Show( | 194 DialogResult result = MessageBox.Show( |
174 string.Format("The server \"{0}\" and its {1} {2} will be deleted.", server.Name, server.Checks.Count, server.Checks.Count == 1 ? "check" : "checks"), | 195 string.Format("The server \"{0}\" and its {1} {2} will be deleted.", server.Name, server.Checks.Count, server.Checks.Count == 1 ? "check" : "checks"), |
182 } | 203 } |
183 } | 204 } |
184 else if (e.ClickedItem == ToggleEnableServerMenuItem) | 205 else if (e.ClickedItem == ToggleEnableServerMenuItem) |
185 { | 206 { |
186 bool enable = ToggleEnableServerMenuItem.Text == "Enable"; | 207 bool enable = ToggleEnableServerMenuItem.Text == "Enable"; |
208 if (enable) | |
209 { | |
210 ServerContextMenu.Close(); | |
211 ServerForm.OpenPrivateKey(monitor, server, this); | |
212 } | |
187 server.Enabled = enable; | 213 server.Enabled = enable; |
188 RefreshDisplay(); | 214 RefreshDisplay(); |
189 } | 215 } |
190 } | 216 } |
191 | 217 |
192 private void ServerContextMenu_Opening(object sender, CancelEventArgs e) | 218 private void ServerContextMenu_Opening(object sender, CancelEventArgs e) |
193 { | 219 { |
194 Server server = getClickedServer((ContextMenuStrip)sender); | 220 Server server = GetClickedServer((ContextMenuStrip)sender); |
195 ToggleEnableServerMenuItem.Text = server.Enabled ? "Disable" : "Enable"; | 221 ToggleEnableServerMenuItem.Text = server.Enabled ? "Disable" : "Enable"; |
196 } | 222 } |
197 | 223 |
198 private Server getClickedServer(ContextMenuStrip menu) | 224 private Server GetClickedServer(ContextMenuStrip menu) |
199 { | 225 { |
200 return ((ServerSummaryControl)menu.SourceControl).Server; | 226 return ((ServerSummaryControl)menu.SourceControl).Server; |
201 } | 227 } |
202 } | 228 } |
203 } | 229 } |