comparison ServerMonitor/Forms/ServerForm.cs @ 4:3142e52cbe69

Lots more progress
author Brad Greco <brad@bgreco.net>
date Sun, 10 Feb 2019 20:51:26 -0500
parents 3e1a2131f897
children b6fe203af9d5
comparison
equal deleted inserted replaced
3:96f0b028176d 4:3142e52cbe69
1 using System; 1 using ServerMonitorApp.Properties;
2 using System;
2 using System.Collections.Generic; 3 using System.Collections.Generic;
3 using System.ComponentModel; 4 using System.ComponentModel;
4 using System.Data; 5 using System.Data;
5 using System.Drawing; 6 using System.Drawing;
6 using System.Linq; 7 using System.Linq;
21 private readonly Dictionary<int, CheckForm> checkForms = new Dictionary<int, CheckForm>(); 22 private readonly Dictionary<int, CheckForm> checkForms = new Dictionary<int, CheckForm>();
22 private readonly Dictionary<CheckBox, CheckStatus> filterChecks; 23 private readonly Dictionary<CheckBox, CheckStatus> filterChecks;
23 24
24 public Server Server { get; private set; } 25 public Server Server { get; private set; }
25 26
26 private IEnumerable<Check> SelectedChecks { get { return CheckGrid.SelectedRows.Cast<DataGridViewRow>().Select(r => r.DataBoundItem).Cast<Check>(); } } 27 private IEnumerable<Check> SelectedChecks => CheckGrid.SelectedRows.Cast<DataGridViewRow>().Select(r => r.DataBoundItem).Cast<Check>();
27 28
28 private Check SelectedCheck { get { return SelectedChecks.FirstOrDefault(); } } 29 private Check SelectedCheck => SelectedChecks.FirstOrDefault();
29 30
30 public ServerForm(ServerMonitor monitor, Server server, bool isNewServer = false) 31 public ServerForm(ServerMonitor monitor, Server server, bool isNewServer = false)
31 { 32 {
32 InitializeComponent(); 33 InitializeComponent();
33 this.monitor = monitor; 34 this.monitor = monitor;
68 BindChangeListeners(); 69 BindChangeListeners();
69 FormatImageButtons(); 70 FormatImageButtons();
70 UpdateCheckButtons(); 71 UpdateCheckButtons();
71 } 72 }
72 73
74 public void Show(bool activate)
75 {
76 if (!activate)
77 WindowState = FormWindowState.Minimized;
78 Show();
79 }
80
73 private void Monitor_CheckStatusChanged(object sender, CheckStatusChangedEventArgs e) 81 private void Monitor_CheckStatusChanged(object sender, CheckStatusChangedEventArgs e)
74 { 82 {
83 if (e.Check.Server != Server)
84 return;
75 CheckGrid.Refresh(); 85 CheckGrid.Refresh();
76 if (e.CheckResult != null && logResults != null) 86 if (e.CheckResult != null && logResults != null)
77 { 87 {
78 logResults.Insert(0, e.CheckResult); 88 logResults.Insert(0, e.CheckResult);
79 if (logResultsFiltered != null && MatchesFilter(e.CheckResult)) 89 if (logResultsFiltered != null && MatchesFilter(e.CheckResult))
173 ShowCheckForm(SelectedCheck); 183 ShowCheckForm(SelectedCheck);
174 } 184 }
175 185
176 private void DeleteSelectedChecks() 186 private void DeleteSelectedChecks()
177 { 187 {
178 if (Properties.Settings.Default.ConfirmDeleteCheck) 188 if (Settings.Default.ConfirmDeleteCheck)
179 { 189 {
180 string message = "Delete " + (SelectedChecks.Count() == 1 ? "\"" + SelectedCheck.Name + "\"" : "selected checks") + "?"; 190 string message = "Delete " + (SelectedChecks.Count() == 1 ? "\"" + SelectedCheck.Name + "\"" : "selected checks") + "?";
181 using (CheckBoxDialog dialog = new CheckBoxDialog { Message = message }) 191 using (CheckBoxDialog dialog = new CheckBoxDialog { Message = message })
182 { 192 {
183 DialogResult result = dialog.ShowDialog(); 193 DialogResult result = dialog.ShowDialog();
184 if (dialog.Checked && result == DialogResult.OK) 194 if (dialog.Checked && result == DialogResult.OK)
185 { 195 {
186 Properties.Settings.Default.ConfirmDeleteCheck = false; 196 Settings.Default.ConfirmDeleteCheck = false;
187 Properties.Settings.Default.Save(); 197 Settings.Default.Save();
188 } 198 }
189 if (result != DialogResult.OK) 199 if (result != DialogResult.OK)
190 return; 200 return;
191 } 201 }
192 } 202 }
197 private async void ExecuteChecks(IEnumerable<Check> checks) 207 private async void ExecuteChecks(IEnumerable<Check> checks)
198 { 208 {
199 await Task.WhenAll(checks.Select(c => monitor.ExecuteCheckAsync(c))); 209 await Task.WhenAll(checks.Select(c => monitor.ExecuteCheckAsync(c)));
200 } 210 }
201 211
202 private void ShowLog(Check check) 212 public void ShowLog(Check check)
203 { 213 {
214 CheckTabControl.SelectedTab = LogTabPage;
204 LogCheckComboBox.SelectedItem = check; 215 LogCheckComboBox.SelectedItem = check;
205 CheckTabControl.SelectedTab = LogTabPage;
206 } 216 }
207 217
208 private void UpdateCheckButtons() 218 private void UpdateCheckButtons()
209 { 219 {
210 RunAllButton.Enabled = CheckGrid.RowCount > 0; 220 RunAllButton.Enabled = CheckGrid.RowCount > 0;
221 231
222 private void BindChangeListeners() 232 private void BindChangeListeners()
223 { 233 {
224 foreach (Control control in ServerInfoPanel.Controls.OfType<Control>().Where(c => c is TextBox)) 234 foreach (Control control in ServerInfoPanel.Controls.OfType<Control>().Where(c => c is TextBox))
225 control.TextChanged += (sender, e) => UpdateServer(false); 235 control.TextChanged += (sender, e) => UpdateServer(false);
226 foreach (Control control in Controls.OfType<Control>().Where(c => c is ComboBox)) 236 foreach (Control control in ServerInfoPanel.Controls.OfType<Control>().Where(c => c is ComboBox))
227 control.TextChanged += (sender, e) => UpdateServer(); 237 control.TextChanged += (sender, e) => UpdateServer();
228 foreach (CheckBox control in LogTabPage.Controls.OfType<CheckBox>()) 238 foreach (CheckBox control in LogTabPage.Controls.OfType<CheckBox>())
229 control.CheckedChanged += FilterChanged; 239 control.CheckedChanged += FilterChanged;
230 } 240 }
231 241
352 logResultsFiltered = new BindingList<CheckResult>(logResults.Where(result => MatchesFilter(result)).ToList()); 362 logResultsFiltered = new BindingList<CheckResult>(logResults.Where(result => MatchesFilter(result)).ToList());
353 LogGrid.DataSource = logResultsFiltered; 363 LogGrid.DataSource = logResultsFiltered;
354 } 364 }
355 } 365 }
356 366
367 private void ServerForm_Activated(object sender, EventArgs e)
368 {
369 Win32Helpers.StopFlashWindowEx(this);
370 }
371
372 private void KeyBrowseButton_Click(object sender, EventArgs e)
373 {
374 OpenFileDialog dialog = new OpenFileDialog() { Title = "Select private key file" };
375 if (dialog.ShowDialog() == DialogResult.OK)
376 {
377 KeyTextBox.Text = dialog.FileName;
378 UpdateServer();
379 }
380 }
381
357 private bool MatchesFilter(CheckResult result) 382 private bool MatchesFilter(CheckResult result)
358 { 383 {
359 return filteredStatuses.Contains(result.CheckStatus) && (LogCheckComboBox.SelectedIndex == 0 || LogCheckComboBox.SelectedItem == result.Check); 384 return filteredStatuses.Contains(result.CheckStatus) && (LogCheckComboBox.SelectedIndex == 0 || LogCheckComboBox.SelectedItem == result.Check);
360 } 385 }
361 } 386 }