comparison ServerMonitor/Forms/CheckForm.cs @ 9:7127d5b5ac75

Code cleanup and comments
author Brad Greco <brad@bgreco.net>
date Mon, 08 Apr 2019 21:29:54 -0400
parents 052aa62cb42a
children d92176c5398a
comparison
equal deleted inserted replaced
8:052aa62cb42a 9:7127d5b5ac75
1 using ServerMonitorApp.Properties; 1 using System;
2 using System;
3 using System.Collections.Generic; 2 using System.Collections.Generic;
4 using System.ComponentModel; 3 using System.ComponentModel;
5 using System.Data;
6 using System.Drawing; 4 using System.Drawing;
7 using System.Linq; 5 using System.Linq;
8 using System.Text; 6 using System.Text;
9 using System.Threading; 7 using System.Threading;
10 using System.Windows.Forms; 8 using System.Windows.Forms;
9 using ServerMonitorApp.Properties;
11 10
12 namespace ServerMonitorApp 11 namespace ServerMonitorApp
13 { 12 {
14 public partial class CheckForm : Form 13 public partial class CheckForm : Form
15 { 14 {
16 //private static readonly Dictionary<Type, CheckInfo> checkInfo = new Dictionary<Type, CheckInfo>();
17 private readonly List<CheckControl> checkControls = new List<CheckControl>(); 15 private readonly List<CheckControl> checkControls = new List<CheckControl>();
18 private bool helpShown; 16 private bool helpShown;
19 private CancellationTokenSource cancellationTokenSource; 17 private CancellationTokenSource cancellationTokenSource;
20 private Check workCheck; 18 private Check workCheck;
21 private CheckControl checkControl; 19 private CheckControl checkControl;
84 private void CheckTypeComboBox_Format(object sender, ListControlConvertEventArgs e) 82 private void CheckTypeComboBox_Format(object sender, ListControlConvertEventArgs e)
85 { 83 {
86 e.Value = Helpers.GetDisplayName((Type)e.ListItem); 84 e.Value = Helpers.GetDisplayName((Type)e.ListItem);
87 } 85 }
88 86
89 /*private void showGroupBox(GroupBox groupBox)
90 {
91
92 }*/
93
94 /*private Type GetCheckType()
95 {
96 return (Type)CheckTypeComboBox.SelectedItem;
97 }*/
98
99 private void ShowCheckControl() 87 private void ShowCheckControl()
100 { 88 {
101 IEnumerable<CheckControl> checkControls = CheckSettingsPanel.Controls.OfType<CheckControl>(); 89 IEnumerable<CheckControl> checkControls = CheckSettingsPanel.Controls.OfType<CheckControl>();
102 foreach (CheckControl control in checkControls) 90 foreach (CheckControl control in checkControls)
103 control.Hide(); 91 control.Hide();
113 CheckSettingsPanel.Controls.Add(checkControl); 101 CheckSettingsPanel.Controls.Add(checkControl);
114 } 102 }
115 } 103 }
116 if (checkControl != null) 104 if (checkControl != null)
117 { 105 {
118 //CheckSettingsPanel.Height = checkControl.Height;
119 //Height = 230 + checkControl.Height;
120 checkControl.Show(); 106 checkControl.Show();
121 } 107 }
122 } 108 }
123 109
124 private void LoadCheck(Check check) 110 private void LoadCheck(Check check)
208 OnRunFinished(result); 194 OnRunFinished(result);
209 localCancellationTokenSource.Dispose(); 195 localCancellationTokenSource.Dispose();
210 localCancellationTokenSource = null; 196 localCancellationTokenSource = null;
211 } 197 }
212 198
213 //private void RunButton_Click(object sender, EventArgs e)
214 //{
215 // if (!Check.Server.SshClient.IsConnected)
216 // Check.Server.SshClient.Connect();
217 // using (Renci.SshNet.SshCommand command = Check.Server.SshClient.CreateCommand("ls"))
218 // {
219 // //token.Register(command.CancelAsync);
220 // //command.BeginExecute(asyncResult =>
221 // //{
222 // // string result = command.EndExecute(asyncResult);
223 // // //tcs.SetResult(new CheckResult(this, CheckStatus.Success, result));
224 // //});
225 // IAsyncResult iar = command.BeginExecute(z);
226 // command.EndExecute(iar);
227 // //string result = command.Execute();
228 // //System.Console.Write(result);
229 // }
230 //}
231
232 //private void z(IAsyncResult ar)
233 //{
234 // throw new NotImplementedException();
235 //}
236
237 private void CancelRunButton_Click(object sender, EventArgs e) 199 private void CancelRunButton_Click(object sender, EventArgs e)
238 { 200 {
239 cancellationTokenSource.Cancel(); 201 cancellationTokenSource.Cancel();
240 OnRunFinished(); 202 OnRunFinished();
241 } 203 }
248 RunButton.Text = "Run"; 210 RunButton.Text = "Run";
249 CancelRunButton.Visible = false; 211 CancelRunButton.Visible = false;
250 if (result != null) 212 if (result != null)
251 { 213 {
252 ResultLabel.Text = result.Message; 214 ResultLabel.Text = result.Message;
253 //ResultLabel.ForeColor = result.CheckStatus == CheckStatus.Success ? Color.Green : Color.Red;
254 ResultIconPictureBox.Image = result.CheckStatus.GetImage(); 215 ResultIconPictureBox.Image = result.CheckStatus.GetImage();
255 ResultLabel.Visible = ResultIconPictureBox.Visible = true; 216 ResultLabel.Visible = ResultIconPictureBox.Visible = true;
256 } 217 }
257 } 218 }
258
259 /*private class CheckInfo
260 {
261 public GroupBox GroupBox { get; private set; }
262
263 public Func<string> ValidateFunction { get; private set; }
264
265 public CheckInfo(GroupBox groupBox, Func<string> validateFunction)
266 {
267 GroupBox = groupBox;
268 ValidateFunction = validateFunction;
269 }
270 }*/
271 219
272 private string BuildHelpText() 220 private string BuildHelpText()
273 { 221 {
274 StringBuilder rtf = new StringBuilder(@"{\rtf1\ansi "); 222 StringBuilder rtf = new StringBuilder(@"{\rtf1\ansi ");
275 foreach (Type checkType in Check.CheckTypes) 223 foreach (Type checkType in Check.CheckTypes)