private IEnumerable <HealthCheckEntity> CheckHosts(IOperation operation, IEnumerable <HostSettingsItemEntity> hosts) { var checks = new List <HealthCheckEntity>(); foreach (var host in hosts) { var hostCredentials = host.CredentialsList.ToList(); for (var i = 0; i < hostCredentials.Count; i++) { var(_, result) = portalSettingsService.CheckConnection(operation, new CheckConnectionToHostEntity { OperatingSystem = host.OperatingSystem, Host = host.Domain, Type = hostCredentials[i].Type, Port = hostCredentials[i].Port, Username = hostCredentials[i].Username, Password = hostCredentials[i].Password }); var credentialsInfo = host.Domain; if (!string.IsNullOrWhiteSpace(hostCredentials[i].Username)) { credentialsInfo = $"{hostCredentials[i].Username}@{credentialsInfo}"; } if (hostCredentials[i].Port.HasValue) { credentialsInfo = $"{credentialsInfo}:{hostCredentials[i].Port}"; } checks.Add(new HealthCheckEntity { Type = $"Host \"{host.Name}\" (credentials #{i + 1}, {credentialsInfo})", IsOk = !result.HasErrors }); } } return(checks); }
public ActionResult <CheckConnectionsToHostResultModel> CheckConnection([FromBody] CheckConnectionToHostModel model) => Execute(operation => { var checks = portalSettingsService.CheckConnection(operation, model.ToEntity()); return(checks.ToModel()); });