Mercurial > servermonitor
comparison 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 |
comparison
equal
deleted
inserted
replaced
5:b6fe203af9d5 | 6:c1dffaac66fa |
---|---|
70 // Update the Checks so they know what Server they belong to. | 70 // Update the Checks so they know what Server they belong to. |
71 // Would rather do this in the Server object on deserialization, but | 71 // Would rather do this in the Server object on deserialization, but |
72 // that doesn't work when using the XML serializer for some reason. | 72 // that doesn't work when using the XML serializer for some reason. |
73 foreach (Server server in Servers) | 73 foreach (Server server in Servers) |
74 { | 74 { |
75 if (server.LoginType == LoginType.PrivateKey) | 75 if (server.LoginType == LoginType.PrivateKey && server.PrivateKeyFile == null) |
76 OpenPrivateKey(server.KeyFile); | 76 OpenPrivateKey(server.KeyFile); |
77 foreach (Check check in server.Checks) | 77 foreach (Check check in server.Checks) |
78 { | 78 { |
79 check.Server = server; | 79 check.Server = server; |
80 if (check.Status == CheckStatus.Running) | 80 if (check.Status == CheckStatus.Running) |
95 finally | 95 finally |
96 { | 96 { |
97 reader?.Close(); | 97 reader?.Close(); |
98 } | 98 } |
99 NetworkChange.NetworkAddressChanged += NetworkChange_NetworkAddressChanged; | 99 NetworkChange.NetworkAddressChanged += NetworkChange_NetworkAddressChanged; |
100 logger.TrimLog(); | |
100 Run(); | 101 Run(); |
101 } | 102 } |
102 | 103 |
103 public void SaveServers() | 104 public void SaveServers() |
104 { | 105 { |
240 } | 241 } |
241 } | 242 } |
242 | 243 |
243 private void CancelCheck(Check check) | 244 private void CancelCheck(Check check) |
244 { | 245 { |
246 if (tasks == null) | |
247 return; | |
245 Task<CheckResult> task = tasks.FirstOrDefault(kvp => kvp.Value == check.Id).Key; | 248 Task<CheckResult> task = tasks.FirstOrDefault(kvp => kvp.Value == check.Id).Key; |
246 if (task != null) | 249 if (task != null) |
247 tasks.Remove(task); | 250 tasks.Remove(task); |
248 pausedChecks.RemoveAll(id => id == check.Id); | 251 pausedChecks.RemoveAll(id => id == check.Id); |
249 if (tokens.TryGetValue(check.Id, out CancellationTokenSource cts)) | 252 if (tokens.TryGetValue(check.Id, out CancellationTokenSource cts)) |
284 return KeyStatus.NotAccessible; | 287 return KeyStatus.NotAccessible; |
285 if (privateKeys.TryGetValue(path, out PrivateKeyFile key) && key != null) | 288 if (privateKeys.TryGetValue(path, out PrivateKeyFile key) && key != null) |
286 return KeyStatus.Open; | 289 return KeyStatus.Open; |
287 try | 290 try |
288 { | 291 { |
289 key = new PrivateKeyFile(path, password); | 292 key = new PrivateKeyFile(path, password); |
290 keyStatus = KeyStatus.Open; | 293 keyStatus = KeyStatus.Open; |
291 } | 294 } |
292 catch (Exception e) when (e is SshPassPhraseNullOrEmptyException || e is InvalidOperationException) | 295 catch (Exception e) when (e is SshPassPhraseNullOrEmptyException || e is InvalidOperationException) |
293 { | 296 { |
294 keyStatus = KeyStatus.NeedPassword; | 297 keyStatus = KeyStatus.NeedPassword; |