comparison ServerMonitor/Objects/Server.cs @ 26:b5502ce8cb1f

Fix servers getting disabled at program launch if no SSH key is set, even if they have no SSH checks.
author Brad Greco <brad@bgreco.net>
date Sun, 02 Jun 2019 17:45:37 -0400
parents 06ff59b59e70
children 7645122aa7a9
comparison
equal deleted inserted replaced
25:781d8b980be1 26:b5502ce8cb1f
109 { 109 {
110 // The private key has not been opened yet. 110 // The private key has not been opened yet.
111 // Disable the server until the user enters the decryption key, 111 // Disable the server until the user enters the decryption key,
112 // and set the KeyStatus to indicate why the server was disabled. 112 // and set the KeyStatus to indicate why the server was disabled.
113 KeyStatus = KeyStatus.Closed; 113 KeyStatus = KeyStatus.Closed;
114 Enabled = false; 114 if (HasSshChecks)
115 Enabled = false;
115 } 116 }
116 else 117 else
117 { 118 {
118 // The private key is open and accessible. 119 // The private key is open and accessible.
119 // Automatically re-enable the server if it was previously disabled 120 // Automatically re-enable the server if it was previously disabled
137 set 138 set
138 { 139 {
139 // Do not allow enabling the server if the private key is not accessible. 140 // Do not allow enabling the server if the private key is not accessible.
140 // Do not fire the EnabledChanged event if the Enabled state is not actually changing 141 // Do not fire the EnabledChanged event if the Enabled state is not actually changing
141 // from its existing value. 142 // from its existing value.
142 if ((LoginType == LoginType.PrivateKey && PrivateKeyFile == null && value == true && Checks.Any(c => c is SshCheck)) || value == _enabled) 143 if ((LoginType == LoginType.PrivateKey && PrivateKeyFile == null && value == true && HasSshChecks) || value == _enabled)
143 return; 144 return;
144 _enabled = value; 145 _enabled = value;
145 EnabledChanged?.Invoke(this, new EventArgs()); 146 EnabledChanged?.Invoke(this, new EventArgs());
146 } 147 }
147 } 148 }
173 _sshClient = new SshClient(info); 174 _sshClient = new SshClient(info);
174 } 175 }
175 return _sshClient; 176 return _sshClient;
176 } 177 }
177 } 178 }
179
180 public bool HasSshChecks => Checks.Any(c => c is SshCheck);
178 181
179 /// <summary>Deletes a check from the server.</summary> 182 /// <summary>Deletes a check from the server.</summary>
180 /// <param name="check">The check to delete.</param> 183 /// <param name="check">The check to delete.</param>
181 public void DeleteCheck(Check check) 184 public void DeleteCheck(Check check)
182 { 185 {