diff ServerMonitor/Objects/ServerMonitor.cs @ 6:c1dffaac66fa

- Don't show multiple password dialogs for the same key if the first one was cancelled. - Add option to trim log files.
author Brad Greco <brad@bgreco.net>
date Fri, 01 Mar 2019 21:38:22 -0500
parents b6fe203af9d5
children 052aa62cb42a
line wrap: on
line diff
--- a/ServerMonitor/Objects/ServerMonitor.cs	Thu Feb 28 21:19:32 2019 -0500
+++ b/ServerMonitor/Objects/ServerMonitor.cs	Fri Mar 01 21:38:22 2019 -0500
@@ -72,7 +72,7 @@
                 // that doesn't work when using the XML serializer for some reason.
                 foreach (Server server in Servers)
                 {
-                    if (server.LoginType == LoginType.PrivateKey)
+                    if (server.LoginType == LoginType.PrivateKey && server.PrivateKeyFile == null)
                         OpenPrivateKey(server.KeyFile);
                     foreach (Check check in server.Checks)
                     {
@@ -97,6 +97,7 @@
                 reader?.Close();
             }
             NetworkChange.NetworkAddressChanged += NetworkChange_NetworkAddressChanged;
+            logger.TrimLog();
             Run();
         }
 
@@ -242,6 +243,8 @@
 
         private void CancelCheck(Check check)
         {
+            if (tasks == null)
+                return;
             Task<CheckResult> task = tasks.FirstOrDefault(kvp => kvp.Value == check.Id).Key;
             if (task != null)
                 tasks.Remove(task);
@@ -286,7 +289,7 @@
                 return KeyStatus.Open;
             try
             {
-               key = new PrivateKeyFile(path, password);
+                key = new PrivateKeyFile(path, password);
                 keyStatus = KeyStatus.Open;
             }
             catch (Exception e) when (e is SshPassPhraseNullOrEmptyException || e is InvalidOperationException)