public IHttpActionResult ExecuteSmoothConfigurationValidation([FromUri] int id) { List <string> results = new List <string>(); try { var smoothConfiguration = _smoothConfigurationRepository.GetById(id); if (smoothConfiguration == null) { return(NotFound()); } // Validate Smooth configuration SmoothConfigurationValidator smoothConfigurationValidator = new SmoothConfigurationValidator(); results = smoothConfigurationValidator.Validate(smoothConfiguration); } catch (Exception exception) { results.Add($"Smooth configuration is corrupted: {exception.Message}"); } return(Ok(new { messages = results })); }
/// <summary> /// Validate Smooth configuration /// </summary> /// <param name="run"></param> /// <param name="smoothConfigurationRepository"></param> /// <returns></returns> private List <SystemMessage> ValidateSmoothConfiguration(Run run, ISmoothConfigurationRepository smoothConfigurationRepository) { List <SystemMessage> messages = new List <SystemMessage>(); if (run.Smooth) { // Try loading configuration SmoothConfiguration smoothConfiguration = null; try { smoothConfiguration = smoothConfigurationRepository.GetById(SmoothConfiguration.DefaultId); if (smoothConfiguration == null) // Not found { messages.Add(FormatSystemMessage(SystemMessage.SmoothConfigurationMissing)); } } catch (System.Exception exception) // Possible corruption caused by manual modification { messages.Add(FormatSystemMessage(SystemMessage.SmoothConfigurationInvalid, new Dictionary <string, string>() { { _placeholderInvalidData, string.Format("Error loading Smooth configuration: {0}", exception.Message) } })); } // Validate Smooth configuration if (smoothConfiguration != null) { SmoothConfigurationValidator smoothConfigurationValidator = new SmoothConfigurationValidator(); var validationResults = smoothConfigurationValidator.Validate(smoothConfiguration); validationResults.ForEach(validationResult => messages.Add(FormatSystemMessage(SystemMessage.SmoothConfigurationInvalid, new Dictionary <string, string>() { { _placeholderInvalidData, validationResult } }))); } } return(messages); }