/// <summary> /// The validate from text. /// </summary> /// <param name="fileContents"> /// The file contents. /// </param> /// <returns> /// The <see cref="Task"/>. /// </returns> /// <exception cref="ArgumentNullException">exception thrown /// </exception> public async Task <ConfigValidationResult> ValidateFromTextAsync(string fileContents) { if (string.IsNullOrWhiteSpace(fileContents)) { throw new ArgumentNullException(nameof(fileContents)); } var configValidationResult = new ConfigValidationResult { Success = true, Results = new List <string>(), }; try { var job = new ConfigReader().ReadXmlFromText(fileContents); configValidationResult.Results.Add("Config format: OK"); //var ping = new Ping(); //PingReply pingResult = null; //ping.SendPingAsync("dockerhost").ContinueWith((a) => pingResult = a.Result).Wait(); //configValidationResult.Results.Add($"ping dockerhost: {pingResult?.Address}"); configValidationResult.Results.Add($"Sql Connection String: {job.Config.ConnectionString}"); await this.CheckDatabaseConnectionStringIsValid(job); configValidationResult.Results.Add($"Sql Connection String: OK"); var firstQueryIsValid = await this.CheckFirstQueryIsValid(job) ? "OK" : "No Rows"; configValidationResult.Results.Add($"First Query: {firstQueryIsValid}"); foreach (var load in job.Data.DataSources) { var queryIsValid = await this.CheckQueryIsValid(job, load) ? "OK" : "No Rows"; configValidationResult.Results.Add($"Query [{load.Path}]: {queryIsValid}"); } if (job.Config.UploadToElasticSearch) { // string x = await (new ElasticSearchUploader(job.Config.ElasticSearchUserName, // job.Config.ElasticSearchPassword, job.Config.KeepIndexOnline).TestElasticSearchConnection(job.Config.Urls)); // configValidationResult.Results.Add($"ElasticSearch Connection: {x}"); } } catch (Exception ex) { configValidationResult.ErrorText = ex.ToString(); configValidationResult.Success = false; } return(configValidationResult); }
public IActionResult SaveSection([Required] OcelotConfigSection configSection) { ConfigValidationResult result = _validator.Validate(configSection).Result; if (result.IsError) { _logger.Warn("Ocelot配置片段错误: " + JsonConvert.SerializeObject(result.Errors)); return(BadRequest(result.Errors)); } else { _sectionRepo.SaveOrUpdate(configSection); _logger.Info("保存Ocelot配置片段: " + JsonConvert.SerializeObject(configSection)); return(Ok(configSection)); } }
public IActionResult BuildConfig([Required, FromQuery] string description) { if (string.IsNullOrWhiteSpace(description)) { throw new ArgumentNullException(nameof(description)); } var configItems = _sectionRepo.GetAll(false); ConfigValidationResult validationResult = _validator.Validate(configItems).Result; if (validationResult.IsError) { return(BadRequest(validationResult.Errors)); } var config = _fullConfigRepo.Create(configItems, description); _logger.Info($"生成新Ocelot配置: {JsonConvert.SerializeObject(config)}"); return(Ok(config)); }