Mercurial > servermonitor
annotate ServerMonitor/Objects/ServerMonitor.cs @ 28:437442cd8090
Fix checks still running after a server is deleted and checks not running immediately after a server is created.
author | Brad Greco <brad@bgreco.net> |
---|---|
date | Sun, 02 Jun 2019 17:55:38 -0400 |
parents | 781d8b980be1 |
children | f6235dc0a8ec |
rev | line source |
---|---|
8
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
1 using Microsoft.Win32; |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
2 using Renci.SshNet; |
5
b6fe203af9d5
Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
4
diff
changeset
|
3 using Renci.SshNet.Common; |
b6fe203af9d5
Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
4
diff
changeset
|
4 using ServerMonitorApp.Properties; |
4 | 5 using System; |
0
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
6 using System.Collections.Generic; |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
7 using System.IO; |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
8 using System.Linq; |
4 | 9 using System.Net.NetworkInformation; |
0
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
10 using System.Threading; |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
11 using System.Threading.Tasks; |
4 | 12 using System.Windows.Forms; |
0
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
13 using System.Xml.Serialization; |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
14 |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
15 namespace ServerMonitorApp |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
16 { |
17 | 17 /// <summary>Central class for scheduling and executing checks against remote servers.</summary> |
0
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
18 public class ServerMonitor |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
19 { |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
20 private readonly string configFileDir; |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
21 private readonly Logger logger; |
17 | 22 // Cancellation tokens for executing checks, keyed by check ID. |
0
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
23 private readonly Dictionary<int, CancellationTokenSource> tokens = new Dictionary<int, CancellationTokenSource>(); |
17 | 24 // SSH private keys, keyed by the path to the private key file. |
25 // A value of NULL indicates that the private key is inaccessible or encrypted. | |
5
b6fe203af9d5
Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
4
diff
changeset
|
26 private readonly Dictionary<string, PrivateKeyFile> privateKeys = new Dictionary<string, PrivateKeyFile>(); |
17 | 27 // IDs of all checks that have been paused due to network unavailability, |
28 // or due to the system being suspended. | |
29 // Not to be confused with checks that have been disabled by the user. | |
4 | 30 private readonly List<int> pausedChecks = new List<int>(); |
8
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
31 private bool running, networkAvailable, suspend; |
17 | 32 // List of check execution tasks that have been started. |
33 // A check task begins by sleeping until the next scheduled execution time, | |
34 // then executes. | |
0
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
35 private Dictionary<Task<CheckResult>, int> tasks; |
4 | 36 private ServerSummaryForm mainForm; |
37 | |
17 | 38 /// <summary>Fires when the status of a check changes.</summary> |
0
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
39 public event EventHandler<CheckStatusChangedEventArgs> CheckStatusChanged; |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
40 |
17 | 41 /// <summary>The collection of registered servers.</summary> |
0
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
42 public List<Server> Servers { get; private set; } = new List<Server>(); |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
43 |
17 | 44 /// <summary>A collection of all checks belonging to all registerd servers.</summary> |
4 | 45 public IEnumerable<Check> Checks => Servers.SelectMany(s => s.Checks); |
0
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
46 |
17 | 47 /// <summary>Path to the file that stores server and check configuration.</summary> |
0
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
48 public string ConfigFile { get; private set; } |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
49 |
17 | 50 /// <summary>Path to the file that stores server and check configuration.</summary> |
5
b6fe203af9d5
Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
4
diff
changeset
|
51 public IEnumerable<string> LockedKeys { get { return privateKeys.Where(kvp => kvp.Value == null).Select(kvp => kvp.Key); } } |
b6fe203af9d5
Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
4
diff
changeset
|
52 |
17 | 53 /// <summary>ServerMonitor constructor.</summary> |
54 /// <param name="mainForm">A reference to the main form.</param> | |
4 | 55 public ServerMonitor(ServerSummaryForm mainForm) |
0
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
56 { |
4 | 57 this.mainForm = mainForm; |
17 | 58 // Store configuration in %appdata%\ServerMonitor |
0
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
59 configFileDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "ServerMonitor"); |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
60 ConfigFile = Path.Combine(configFileDir, "servers.xml"); |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
61 logger = new Logger(Path.Combine(configFileDir, "monitor.log")); |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
62 } |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
63 |
17 | 64 /// <summary>Registers a new server with the server monitor.</summary> |
65 /// <param name="server">The server to be added.</param> | |
0
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
66 public void AddServer(Server server) |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
67 { |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
68 Servers.Add(server); |
4 | 69 SaveServers(); |
28
437442cd8090
Fix checks still running after a server is deleted and checks not running immediately after a server is created.
Brad Greco <brad@bgreco.net>
parents:
25
diff
changeset
|
70 server.CheckModified += Server_CheckModified; |
437442cd8090
Fix checks still running after a server is deleted and checks not running immediately after a server is created.
Brad Greco <brad@bgreco.net>
parents:
25
diff
changeset
|
71 server.EnabledChanged += Server_EnabledChanged; |
4 | 72 } |
73 | |
17 | 74 /// <summary>Deletes a server from the server monitor.</summary> |
75 /// <param name="server">The server to be deleted.</param> | |
4 | 76 public void DeleteServer(Server server) |
77 { | |
78 Servers.Remove(server); | |
28
437442cd8090
Fix checks still running after a server is deleted and checks not running immediately after a server is created.
Brad Greco <brad@bgreco.net>
parents:
25
diff
changeset
|
79 // Cancel all queued and executing checks belonging to a |
437442cd8090
Fix checks still running after a server is deleted and checks not running immediately after a server is created.
Brad Greco <brad@bgreco.net>
parents:
25
diff
changeset
|
80 // server that was deleted. |
437442cd8090
Fix checks still running after a server is deleted and checks not running immediately after a server is created.
Brad Greco <brad@bgreco.net>
parents:
25
diff
changeset
|
81 foreach (Check check in server.Checks) |
437442cd8090
Fix checks still running after a server is deleted and checks not running immediately after a server is created.
Brad Greco <brad@bgreco.net>
parents:
25
diff
changeset
|
82 { |
437442cd8090
Fix checks still running after a server is deleted and checks not running immediately after a server is created.
Brad Greco <brad@bgreco.net>
parents:
25
diff
changeset
|
83 CancelCheck(check); |
437442cd8090
Fix checks still running after a server is deleted and checks not running immediately after a server is created.
Brad Greco <brad@bgreco.net>
parents:
25
diff
changeset
|
84 } |
4 | 85 SaveServers(); |
0
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
86 } |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
87 |
17 | 88 /// <summary>Loads all servers and checks from the config file.</summary> |
0
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
89 public void LoadServers() |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
90 { |
17 | 91 bool triedBackup = false; |
92 | |
8
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
93 Read: |
0
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
94 TextReader reader = null; |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
95 try |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
96 { |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
97 reader = new StreamReader(ConfigFile); |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
98 XmlSerializer serializer = CreateXmlSerializer(); |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
99 Servers.Clear(); |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
100 Servers.AddRange((List<Server>)serializer.Deserialize(reader)); |
17 | 101 // Do some more set-up now that the servers and checks have been loaded. |
0
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
102 foreach (Server server in Servers) |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
103 { |
17 | 104 // Read private keys into memory if they are accessible and not encrypted. |
105 // If PrivateKeyFile != null, it means same the key has already been loaded for | |
106 // a different server and nothing more needs to be done. | |
6
c1dffaac66fa
- Don't show multiple password dialogs for the same key if the first one was cancelled.
Brad Greco <brad@bgreco.net>
parents:
5
diff
changeset
|
107 if (server.LoginType == LoginType.PrivateKey && server.PrivateKeyFile == null) |
5
b6fe203af9d5
Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
4
diff
changeset
|
108 OpenPrivateKey(server.KeyFile); |
0
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
109 foreach (Check check in server.Checks) |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
110 { |
17 | 111 // Update the checks so they know what server they belong to. |
112 // Would rather do this in the Server object on deserialization, but | |
113 // that doesn't work when using the XML serializer for some reason. | |
0
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
114 check.Server = server; |
17 | 115 // If the program last exited while the check was running, change its status |
116 // to the result of its last execution (since, at this point, the check is | |
117 // not running). | |
4 | 118 if (check.Status == CheckStatus.Running) |
119 check.Status = check.LastRunStatus; | |
0
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
120 } |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
121 server.CheckModified += Server_CheckModified; |
4 | 122 server.EnabledChanged += Server_EnabledChanged; |
0
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
123 } |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
124 } |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
125 // If the file doesn't exist, no special handling is needed. It will be created later. |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
126 catch (FileNotFoundException) { } |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
127 catch (DirectoryNotFoundException) { } |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
128 catch (InvalidOperationException) |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
129 { |
8
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
130 reader?.Close(); |
17 | 131 // If there was an error parsing the XML, try again with the backup config file. |
132 if (!triedBackup) | |
133 { | |
134 File.Copy(ConfigFile, ConfigFile + ".error", true); | |
135 string backupConfig = ConfigFile + ".bak"; | |
136 if (File.Exists(backupConfig)) | |
137 { | |
138 File.Copy(backupConfig, ConfigFile, true); | |
139 } | |
140 triedBackup = true; | |
141 goto Read; | |
142 } | |
143 else | |
144 { | |
145 // If there was an error reading the backup file too, give up. | |
146 throw; | |
147 } | |
0
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
148 } |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
149 finally |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
150 { |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
151 reader?.Close(); |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
152 } |
8
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
153 Application.ApplicationExit += Application_ApplicationExit; |
4 | 154 NetworkChange.NetworkAddressChanged += NetworkChange_NetworkAddressChanged; |
8
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
155 SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged; |
17 | 156 |
157 // Remove old entries from the log file according to user preferences. | |
6
c1dffaac66fa
- Don't show multiple password dialogs for the same key if the first one was cancelled.
Brad Greco <brad@bgreco.net>
parents:
5
diff
changeset
|
158 logger.TrimLog(); |
17 | 159 |
0
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
160 Run(); |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
161 } |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
162 |
17 | 163 /// <summary>Saves all servers and checks to the config file.</summary> |
0
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
164 public void SaveServers() |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
165 { |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
166 GenerateIds(); |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
167 TextWriter writer = null; |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
168 XmlSerializer serializer = null; |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
169 try |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
170 { |
17 | 171 // Make a backup first in case something goes wrong in the middle of writing. |
8
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
172 File.Copy(ConfigFile, ConfigFile + ".bak", true); |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
173 } |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
174 catch { } |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
175 try |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
176 { |
0
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
177 writer = new StreamWriter(ConfigFile); |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
178 serializer = CreateXmlSerializer(); |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
179 serializer.Serialize(writer, Servers); |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
180 } |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
181 catch (DirectoryNotFoundException) |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
182 { |
17 | 183 // If the directory does not exist, create it and try again. |
0
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
184 Directory.CreateDirectory(configFileDir); |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
185 writer = new StreamWriter(ConfigFile); |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
186 serializer = CreateXmlSerializer(); |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
187 serializer.Serialize(writer, Servers); |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
188 } |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
189 finally |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
190 { |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
191 writer?.Close(); |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
192 } |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
193 } |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
194 |
17 | 195 /// <summary>Main server monitor loop. Schedules and executes checks.</summary> |
0
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
196 private async void Run() |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
197 { |
17 | 198 // Do not run again if already running or if the system is suspending or resuming. |
8
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
199 if (running || suspend) |
0
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
200 return; |
17 | 201 |
0
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
202 running = true; |
17 | 203 |
204 // If the network is available, immediately execute checks that were supposed to run | |
205 // earlier but could not due to network unavailability or the system being suspended. | |
4 | 206 networkAvailable = Helpers.IsNetworkAvailable(); |
207 if (networkAvailable) | |
208 { | |
209 foreach (int id in pausedChecks) | |
210 { | |
211 await ExecuteCheckAsync(Checks.FirstOrDefault(c => c.Id == id)); | |
212 } | |
213 pausedChecks.Clear(); | |
214 } | |
17 | 215 |
216 // Schedule all checks to run according to their schedules. | |
217 // Each check will sleep until it is scheduled to run, then execute. | |
0
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
218 tasks = Checks.ToDictionary(c => ScheduleExecuteCheckAsync(c), c => c.Id); |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
219 while (tasks.Count > 0) |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
220 { |
17 | 221 // When any check is done sleeping and executing, remove the completed |
222 // task and queue a new task to schedule it again. | |
0
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
223 Task<CheckResult> task = await Task.WhenAny(tasks.Keys); |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
224 tasks.Remove(task); |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
225 try |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
226 { |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
227 CheckResult result = await task; |
17 | 228 // Do not schedule the task again if it is now disabled. |
229 // Result will be null if a scheduled check was disabled. | |
0
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
230 if (result != null && result.CheckStatus != CheckStatus.Disabled) |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
231 tasks.Add(ScheduleExecuteCheckAsync(result.Check), result.Check.Id); |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
232 } |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
233 catch (OperationCanceledException) |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
234 { |
17 | 235 // When a server's state changes to Disabled, any checks that are executing |
236 // are immediately cancelled. Silently catch these expected exceptions. | |
0
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
237 } |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
238 } |
17 | 239 // If there are no enabled checks scheduled, exit the main loop. |
240 // It will be restarted when a check or server is enabled. | |
0
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
241 running = false; |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
242 } |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
243 |
17 | 244 /// <summary>Schedules a check to be run on its schedule.</summary> |
245 /// <param name="check">The check to execute.</param> | |
246 /// <returns>The async check result.</returns> | |
247 private async Task<CheckResult> ScheduleExecuteCheckAsync(Check check) | |
248 { | |
249 // Do not schedule or execute the check if it or its server is disabled. | |
250 if (!check.Enabled || !check.Server.Enabled) | |
251 return await Task.FromResult(new CheckResult(check, CheckStatus.Disabled, null)); | |
252 | |
253 // Create a cancellation token that will be used to cancel the check if it or | |
254 // its server is disabled while it is executing. | |
255 CancellationTokenSource cts = new CancellationTokenSource(); | |
256 tokens[check.Id] = cts; | |
257 | |
258 // Sleep until next time the check is supposed to be executed. | |
259 // Use the LastScheduledRunTime so manual executions by the user do not | |
260 // interfere with the schedule. | |
261 check.NextRunTime = check.Schedule.GetNextTime(check.LastScheduledRunTime); | |
262 int delay = Math.Max(0, (int)(check.NextRunTime - DateTime.Now).TotalMilliseconds); | |
263 await Task.Delay(delay, cts.Token); | |
264 check.LastScheduledRunTime = check.NextRunTime; | |
265 | |
266 // Execute the check if not cancelled. | |
267 if (!cts.IsCancellationRequested) | |
268 { | |
269 // If the network is available, execute the check. | |
270 // Otherwise, add it to the list of paused checks to be executed | |
271 // when the network becomes available again. | |
272 if (networkAvailable) | |
273 { | |
274 return await ExecuteCheckAsync(check, cts.Token); | |
275 } | |
276 else | |
277 { | |
278 if (!pausedChecks.Contains(check.Id)) | |
279 pausedChecks.Add(check.Id); | |
280 } | |
281 } | |
282 return await Task.FromResult(new CheckResult(check, CheckStatus.Disabled, null)); | |
283 } | |
284 | |
285 /// <summary>Executes a check asynchronously.</summary> | |
286 /// <param name="check">The check to execute.</param> | |
287 /// <param name="token">A chancellation token that may be used to cancel the check execution.</param> | |
288 /// <returns>The async check result.</returns> | |
0
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
289 public async Task<CheckResult> ExecuteCheckAsync(Check check, CancellationToken token = default(CancellationToken)) |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
290 { |
17 | 291 // Update the status. |
0
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
292 check.Status = CheckStatus.Running; |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
293 OnCheckStatusChanged(check); |
17 | 294 |
295 // Execute the check. | |
0
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
296 CheckResult result = await check.ExecuteAsync(token); |
17 | 297 |
298 // Increment the consecutive failure counter on failue, or reset | |
299 // the counter on success. | |
8
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
300 if (result.Failed) |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
301 check.ConsecutiveFailures++; |
17 | 302 else |
303 check.ConsecutiveFailures = 0; | |
304 | |
0
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
305 OnCheckStatusChanged(check, result); |
4 | 306 HandleResultAsync(result); |
307 return result; | |
308 } | |
309 | |
17 | 310 /// <summary>Handles the result of a check execution.</summary> |
311 /// <param name="result">The result.</param> | |
4 | 312 private void HandleResultAsync(CheckResult result) |
313 { | |
17 | 314 // Log the result. |
0
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
315 logger.Log(result); |
17 | 316 |
317 // Notify the user of failure according to user preferences. | |
318 // If the check succeeded, result.FailAction will be None. | |
8
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
319 if (result.Check.ConsecutiveFailures >= result.Check.MaxConsecutiveFailures) |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
320 { |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
321 if (result.FailAction == FailAction.FlashTaskbar) |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
322 mainForm.AlertServerForm(result.Check); |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
323 if (result.FailAction.In(FailAction.FlashTaskbar, FailAction.NotificationBalloon)) |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
324 mainForm.ShowBalloon(result); |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
325 } |
0
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
326 } |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
327 |
17 | 328 /// <summary>Reads all check results from the log for a server.</summary> |
329 /// <param name="server">The server whose check results should be read.</param> | |
330 /// <returns>A list of all check results found in the log file for the given server.</returns> | |
0
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
331 public IList<CheckResult> GetLog(Server server) |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
332 { |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
333 return logger.Read(server); |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
334 } |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
335 |
17 | 336 /// <summary>Saves the check settings and notifies event subscribers when the status of a check changes.</summary> |
337 /// <param name="check">The check whose status has changed.</param> | |
338 /// <param name="result">The check result that caused the status to change, if any.</param> | |
0
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
339 private void OnCheckStatusChanged(Check check, CheckResult result = null) |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
340 { |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
341 SaveServers(); |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
342 CheckStatusChanged?.Invoke(check, new CheckStatusChangedEventArgs(check, result)); |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
343 } |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
344 |
17 | 345 /// <summary>Handles user modifications to a check's settings.</summary> |
346 /// <param name="sender">The check that was modified.</param> | |
0
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
347 private void Server_CheckModified(object sender, EventArgs e) |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
348 { |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
349 Check check = (Check)sender; |
17 | 350 |
351 // No need to mess with the task queue if not currently running. | |
0
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
352 if (running) |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
353 { |
17 | 354 Task<CheckResult> task = tasks.FirstOrDefault(kvp => kvp.Value == check.Id).Key; |
0
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
355 if (task == null) |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
356 { |
17 | 357 // No tasks associated with the check, so schedule a new one. |
0
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
358 tasks.Add(ScheduleExecuteCheckAsync(check), check.Id); |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
359 } |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
360 else |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
361 { |
17 | 362 // Check was modified or deleted, so remove any waiting tasks. |
4 | 363 CancelCheck(check); |
0
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
364 if (check.Server != null) |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
365 { |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
366 // If the check was not deleted, schedule the new check. |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
367 // But only if it's still running, otherwise restarting the monitor below |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
368 // will create a duplicate run. |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
369 if (running) |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
370 tasks.Add(ScheduleExecuteCheckAsync(check), check.Id); |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
371 } |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
372 } |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
373 } |
17 | 374 // Run again in case removing a task above caused it to stop. |
0
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
375 Run(); |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
376 } |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
377 |
17 | 378 /// <summary>Handles the enabled state of a server changing.</summary> |
379 /// <param name="sender">The server that was enabled or disabled.</param> | |
4 | 380 private void Server_EnabledChanged(object sender, EventArgs e) |
381 { | |
382 Server server = (Server)sender; | |
17 | 383 |
384 // Make sure the monitor is running. If no servers were enabled before this | |
385 // one was enabled, it is not running. | |
4 | 386 if (server.Enabled) |
387 { | |
388 Run(); | |
25
781d8b980be1
Fix checks not getting scheduled when a server is enabled.
Brad Greco <brad@bgreco.net>
parents:
17
diff
changeset
|
389 // Schedule all checks to run. |
781d8b980be1
Fix checks not getting scheduled when a server is enabled.
Brad Greco <brad@bgreco.net>
parents:
17
diff
changeset
|
390 foreach (Check check in server.Checks) |
781d8b980be1
Fix checks not getting scheduled when a server is enabled.
Brad Greco <brad@bgreco.net>
parents:
17
diff
changeset
|
391 { |
781d8b980be1
Fix checks not getting scheduled when a server is enabled.
Brad Greco <brad@bgreco.net>
parents:
17
diff
changeset
|
392 Server_CheckModified(check, new EventArgs()); |
781d8b980be1
Fix checks not getting scheduled when a server is enabled.
Brad Greco <brad@bgreco.net>
parents:
17
diff
changeset
|
393 } |
4 | 394 } |
395 else | |
396 { | |
17 | 397 // Cancel all queued and executing checks belonging to a |
398 // server that was disabled. | |
4 | 399 foreach (Check check in server.Checks) |
400 { | |
401 CancelCheck(check); | |
402 } | |
403 } | |
404 } | |
405 | |
17 | 406 /// <summary>Cancels a check that may be executing.</summary> |
407 /// <param name="check">The check to cancel.</param> | |
4 | 408 private void CancelCheck(Check check) |
409 { | |
6
c1dffaac66fa
- Don't show multiple password dialogs for the same key if the first one was cancelled.
Brad Greco <brad@bgreco.net>
parents:
5
diff
changeset
|
410 if (tasks == null) |
c1dffaac66fa
- Don't show multiple password dialogs for the same key if the first one was cancelled.
Brad Greco <brad@bgreco.net>
parents:
5
diff
changeset
|
411 return; |
17 | 412 |
413 // Find the waiting or executing task for the check and remove it. | |
4 | 414 Task<CheckResult> task = tasks.FirstOrDefault(kvp => kvp.Value == check.Id).Key; |
5
b6fe203af9d5
Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
4
diff
changeset
|
415 if (task != null) |
b6fe203af9d5
Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
4
diff
changeset
|
416 tasks.Remove(task); |
17 | 417 |
418 // Remove it from the list of paused checks so it doesn't get restarted later. | |
4 | 419 pausedChecks.RemoveAll(id => id == check.Id); |
17 | 420 |
421 // Cancel the current execution. | |
4 | 422 if (tokens.TryGetValue(check.Id, out CancellationTokenSource cts)) |
423 cts.Cancel(); | |
424 } | |
425 | |
17 | 426 /// <summary>Handles network state changing.</summary> |
4 | 427 private void NetworkChange_NetworkAddressChanged(object sender, EventArgs e) |
428 { | |
429 networkAvailable = Helpers.IsNetworkAvailable(); | |
17 | 430 // If the network is available, it might not have been before. |
431 // This method is not called from the correct thread, so special | |
432 // handling is needed to start it on the UI thread again. | |
4 | 433 if (networkAvailable) |
434 mainForm.Invoke((MethodInvoker)(() => Run())); | |
0
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
435 } |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
436 |
17 | 437 /// <summary>Handles system power mode changes.</summary> |
8
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
438 private async void SystemEvents_PowerModeChanged(object sender, PowerModeChangedEventArgs e) |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
439 { |
17 | 440 // If the system is being suspended, cancel all waiting and executing checks. |
441 // Once all the checks are removed, the main loop will exit. | |
8
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
442 if (e.Mode == PowerModes.Suspend) |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
443 { |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
444 foreach (Check check in Checks) |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
445 { |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
446 CancelCheck(check); |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
447 } |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
448 suspend = true; |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
449 } |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
450 else if (e.Mode == PowerModes.Resume) |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
451 { |
17 | 452 // When resuming from suspend, examine each check to find out if it was |
453 // scheduled to be executed during the time period when the systems was | |
454 // suspended. Add them to the paused checks list, to be executed almost | |
455 // immediately. | |
456 // Make sure the list is empty to start. | |
8
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
457 pausedChecks.Clear(); |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
458 foreach (Check check in Checks) |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
459 { |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
460 if (check.Enabled && check.Server.Enabled && check.NextRunTime < DateTime.Now) |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
461 { |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
462 pausedChecks.Add(check.Id); |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
463 } |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
464 } |
17 | 465 // Wait 10 seconds to give things time to quiet down after resuming. |
8
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
466 await Task.Delay(10000); |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
467 suspend = false; |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
468 Run(); |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
469 } |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
470 } |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
471 |
17 | 472 /// <summary>Unregister system events when exiting.</summary> |
8
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
473 private void Application_ApplicationExit(object sender, EventArgs e) |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
474 { |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
475 NetworkChange.NetworkAddressChanged -= NetworkChange_NetworkAddressChanged; |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
476 SystemEvents.PowerModeChanged -= SystemEvents_PowerModeChanged; |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
477 } |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
478 |
17 | 479 /// <summary>Attempts to read a private file.</summary> |
480 /// <param name="path">The path to the private key file.</param> | |
481 /// <param name="password">The password used to encrypt the key.</param> | |
482 /// <returns>A status indicating the result of the attempt.</returns> | |
5
b6fe203af9d5
Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
4
diff
changeset
|
483 public KeyStatus OpenPrivateKey(string path, string password = null) |
b6fe203af9d5
Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
4
diff
changeset
|
484 { |
b6fe203af9d5
Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
4
diff
changeset
|
485 KeyStatus keyStatus; |
17 | 486 |
5
b6fe203af9d5
Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
4
diff
changeset
|
487 if (path == null) |
8
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
488 keyStatus = KeyStatus.NotAccessible; |
17 | 489 |
490 // Check if the key has already been open and read. | |
5
b6fe203af9d5
Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
4
diff
changeset
|
491 if (privateKeys.TryGetValue(path, out PrivateKeyFile key) && key != null) |
b6fe203af9d5
Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
4
diff
changeset
|
492 keyStatus = KeyStatus.Open; |
8
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
493 else |
5
b6fe203af9d5
Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
4
diff
changeset
|
494 { |
8
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
495 try |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
496 { |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
497 key = new PrivateKeyFile(path, password); |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
498 keyStatus = KeyStatus.Open; |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
499 } |
17 | 500 // If the key is encrypted and the password is empty or incorrect, |
501 // return the NeedPassword status. | |
8
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
502 catch (Exception e) when (e is SshPassPhraseNullOrEmptyException || e is InvalidOperationException) |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
503 { |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
504 keyStatus = KeyStatus.NeedPassword; |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
505 } |
17 | 506 // For any other failure reason, return the NotAccessible status. |
8
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
507 catch (Exception) |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
508 { |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
509 keyStatus = KeyStatus.NotAccessible; |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
510 } |
5
b6fe203af9d5
Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
4
diff
changeset
|
511 } |
17 | 512 // A single private key may be used by multiple servers. Update all servers |
513 // that use this private key with the results of the above operations. | |
5
b6fe203af9d5
Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
4
diff
changeset
|
514 foreach (Server server in Servers) |
b6fe203af9d5
Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
4
diff
changeset
|
515 { |
b6fe203af9d5
Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
4
diff
changeset
|
516 if (server.KeyFile == path) |
b6fe203af9d5
Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
4
diff
changeset
|
517 { |
b6fe203af9d5
Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
4
diff
changeset
|
518 server.PrivateKeyFile = key; |
b6fe203af9d5
Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
4
diff
changeset
|
519 server.KeyStatus = keyStatus; |
b6fe203af9d5
Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
4
diff
changeset
|
520 } |
b6fe203af9d5
Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
4
diff
changeset
|
521 } |
17 | 522 // Keep a reference to this private key so we don't have to re-open |
523 // it later if the same key is used on a different server. | |
5
b6fe203af9d5
Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
4
diff
changeset
|
524 privateKeys[path] = key; |
17 | 525 |
5
b6fe203af9d5
Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
4
diff
changeset
|
526 return keyStatus; |
b6fe203af9d5
Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
4
diff
changeset
|
527 } |
b6fe203af9d5
Private key passwords and validation
Brad Greco <brad@bgreco.net>
parents:
4
diff
changeset
|
528 |
17 | 529 /// <summary>Generates internal IDs for servers and checks.</summary> |
0
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
530 private void GenerateIds() |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
531 { |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
532 if (Servers.Any()) |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
533 { |
17 | 534 // Start at the maximum ID to make sure IDs are not reused |
535 // if a server was deleted so old log entries do not get associated | |
536 // with a new server. | |
0
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
537 int id = Servers.Max(s => s.Id); |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
538 foreach (Server server in Servers) |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
539 { |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
540 if (server.Id == 0) |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
541 server.Id = ++id; |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
542 } |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
543 } |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
544 |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
545 if (Checks.Any()) |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
546 { |
17 | 547 // Start with the max check ID, same reasons as above. |
548 // Is there a reason this is stored in a setting? | |
4 | 549 int id = Math.Max(Settings.Default.MaxCheckId, Checks.Max(c => c.Id)); |
0
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
550 foreach (Check check in Checks) |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
551 { |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
552 if (check.Id == 0) |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
553 check.Id = ++id; |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
554 } |
4 | 555 Settings.Default.MaxCheckId = id; |
556 Settings.Default.Save(); | |
0
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
557 } |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
558 } |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
559 |
17 | 560 /// <summary>Creates an XML serializer that can handle servers and all check types.</summary> |
561 /// <returns>An XML serializer that can handle servers and all check types.</returns> | |
0
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
562 private XmlSerializer CreateXmlSerializer() |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
563 { |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
564 return new XmlSerializer(typeof(List<Server>), Check.CheckTypes); |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
565 } |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
566 } |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
567 |
17 | 568 /// <summary>Event arguments for when a check status changes.</summary> |
0
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
569 public class CheckStatusChangedEventArgs : EventArgs |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
570 { |
17 | 571 /// <summary>The check whose status changed.</summary> |
0
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
572 public Check Check { get; private set; } |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
573 |
17 | 574 /// <summary>The check result that caused the status to change, if any.</summary> |
0
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
575 public CheckResult CheckResult { get; private set; } |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
576 |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
577 public CheckStatusChangedEventArgs(Check check, CheckResult result) |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
578 { |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
579 Check = check; |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
580 CheckResult = result; |
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
581 } |
4 | 582 } |
0
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
583 |
17 | 584 /// <summary>Possible actions that may be taken when a check fails.</summary> |
585 public enum FailAction | |
586 { | |
587 /// <summary>Flashes the Server Monitor tasbar program icon.</summary> | |
588 FlashTaskbar = 0, | |
589 /// <summary>Shows a balloon in the notification area.</summary> | |
590 NotificationBalloon = 1, | |
591 /// <summary>Take no action.</summary> | |
592 None = 10 | |
593 } | |
594 | |
0
3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
Brad Greco <brad@bgreco.net>
parents:
diff
changeset
|
595 } |