diff 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
line wrap: on
line diff
--- a/ServerMonitor/Forms/ServerForm.cs	Fri Jan 11 22:34:18 2019 -0500
+++ b/ServerMonitor/Forms/ServerForm.cs	Sun Feb 10 20:51:26 2019 -0500
@@ -1,4 +1,5 @@
-using System;
+using ServerMonitorApp.Properties;
+using System;
 using System.Collections.Generic;
 using System.ComponentModel;
 using System.Data;
@@ -23,9 +24,9 @@
 
         public Server Server { get; private set; }
 
-        private IEnumerable<Check> SelectedChecks { get { return CheckGrid.SelectedRows.Cast<DataGridViewRow>().Select(r => r.DataBoundItem).Cast<Check>(); } }
+        private IEnumerable<Check> SelectedChecks => CheckGrid.SelectedRows.Cast<DataGridViewRow>().Select(r => r.DataBoundItem).Cast<Check>();
 
-        private Check SelectedCheck { get { return SelectedChecks.FirstOrDefault(); } }
+        private Check SelectedCheck => SelectedChecks.FirstOrDefault();
 
         public ServerForm(ServerMonitor monitor, Server server, bool isNewServer = false)
         {
@@ -70,8 +71,17 @@
             UpdateCheckButtons();
         }
 
+        public void Show(bool activate)
+        {
+            if (!activate)
+                WindowState = FormWindowState.Minimized;
+            Show();
+        }
+
         private void Monitor_CheckStatusChanged(object sender, CheckStatusChangedEventArgs e)
         {
+            if (e.Check.Server != Server)
+                return;
             CheckGrid.Refresh();
             if (e.CheckResult != null && logResults != null)
             {
@@ -175,7 +185,7 @@
 
         private void DeleteSelectedChecks()
         {
-            if (Properties.Settings.Default.ConfirmDeleteCheck)
+            if (Settings.Default.ConfirmDeleteCheck)
             {
                 string message = "Delete " + (SelectedChecks.Count() == 1 ? "\"" + SelectedCheck.Name + "\"" : "selected checks") + "?";
                 using (CheckBoxDialog dialog = new CheckBoxDialog { Message = message })
@@ -183,8 +193,8 @@
                     DialogResult result = dialog.ShowDialog();
                     if (dialog.Checked && result == DialogResult.OK)
                     {
-                        Properties.Settings.Default.ConfirmDeleteCheck = false;
-                        Properties.Settings.Default.Save();
+                        Settings.Default.ConfirmDeleteCheck = false;
+                        Settings.Default.Save();
                     }
                     if (result != DialogResult.OK)
                         return;
@@ -199,10 +209,10 @@
             await Task.WhenAll(checks.Select(c => monitor.ExecuteCheckAsync(c)));
         }
 
-        private void ShowLog(Check check)
+        public void ShowLog(Check check)
         {
+            CheckTabControl.SelectedTab = LogTabPage;
             LogCheckComboBox.SelectedItem = check;
-            CheckTabControl.SelectedTab = LogTabPage;
         }
 
         private void UpdateCheckButtons()
@@ -223,7 +233,7 @@
         {
             foreach (Control control in ServerInfoPanel.Controls.OfType<Control>().Where(c => c is TextBox))
                 control.TextChanged += (sender, e) => UpdateServer(false);
-            foreach (Control control in Controls.OfType<Control>().Where(c => c is ComboBox))
+            foreach (Control control in ServerInfoPanel.Controls.OfType<Control>().Where(c => c is ComboBox))
                 control.TextChanged += (sender, e) => UpdateServer();
             foreach (CheckBox control in LogTabPage.Controls.OfType<CheckBox>())
                 control.CheckedChanged += FilterChanged;
@@ -354,6 +364,21 @@
             }
         }
 
+        private void ServerForm_Activated(object sender, EventArgs e)
+        {
+            Win32Helpers.StopFlashWindowEx(this);
+        }
+
+        private void KeyBrowseButton_Click(object sender, EventArgs e)
+        {
+            OpenFileDialog dialog = new OpenFileDialog() { Title = "Select private key file" };
+            if (dialog.ShowDialog() == DialogResult.OK)
+            {
+                KeyTextBox.Text = dialog.FileName;
+                UpdateServer();
+            }
+        }
+
         private bool MatchesFilter(CheckResult result)
         {
             return filteredStatuses.Contains(result.CheckStatus) && (LogCheckComboBox.SelectedIndex == 0 || LogCheckComboBox.SelectedItem == result.Check);