public void Validation001_ValidationCollectionEmptyAfterInit() { ConfigValidator.Reset(); var cfg = new Config(); Assert.IsTrue(cfg.ValidationCollection != null); Assert.IsTrue(cfg.ValidationCollection.Count == 0); }
/// <summary> /// 添加服务 /// </summary> /// <param name="desc"></param> public void AddService(ServiceDesc desc) { ConfigValidator.ValidateServiceDesc(desc); ServiceKey servicekey = new ServiceKey(desc); serviceDic.Add(servicekey, desc); }
public async Task UpdateConfigAsync(Config config) { if (!ConfigValidator.ValidateDefault(config)) { throw new InvalidOperationException(Resources.ConfigValidFailString); } await _configsRepository.UpdateConfigAsync(config); }
public void TestInvalidFormat() { var config = CreateConfig(); config.Format.Returns("invalid"); var exception = Assert.Throws <InvalidConfigException>(() => ConfigValidator.Validate(config)); Assert.Equal("http-stream is the only supported format", exception.Message); }
/// <summary> /// Applications the start. /// </summary> protected void Application_Start() { ConfigValidator.Validate(); AreaRegistration.RegisterAllAreas(); GlobalConfiguration.Configure(WebApiConfig.Register); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); }
public void TestUnknownSocketType() { var config = CreateConfig(); config.ListenerSocketType.Returns(SocketType.Unknown); config.Listener.Returns("foobar"); var exception = Assert.Throws <InvalidConfigException>(() => ConfigValidator.Validate(config)); Assert.Equal("Invalid listener: foobar", exception.Message); }
/// <summary> /// The Create instance. /// </summary> /// <param name="server">the server name.</param> /// <returns>The config.</returns> public static IMono <Config> Create(string server) { var validator = new ConfigValidator(); var config = new Config(server); var validation = validator.Validate(config); return(validation.IsValid ? Mono.Just(config) : Mono.Error <Config>(new ArgumentException(string.Join(", ", validation.Errors)))); }
public void TestDoesNotAllowUnixSocketOnWindows() { Skip.IfNot(RuntimeInformation.IsOSPlatform(OSPlatform.Windows)); var config = CreateConfig(); config.ListenerSocketType.Returns(SocketType.Unix); var exception = Assert.Throws <InvalidConfigException>(() => ConfigValidator.Validate(config)); Assert.Equal("UNIX sockets are not supported on Windows", exception.Message); }
public IActionResult Index() { // Validate whether all the required configurations are provided in appsettings.json string configValidationResult = ConfigValidator.ValidateConfig(azureAd); if (configValidationResult != null) { Console.Error.WriteLine(configValidationResult); return(BadRequest(configValidationResult)); } return(View()); }
public void LoadConfig_DuplicateGroupNames_Throws() { var loader = GetLoader($"data\\duplicates\\duplicateGroups".ToCrossPlatformPath()); var config = loader(); var caught = Assert.Throws <ConfigException>(() => ConfigValidator.Validate(config)); Assert.That(caught, Is.Not.Null); Assert.That(caught.Message, Contains.Substring("The following alerting group names exist in multiple config files")); Assert.That(caught.Message, Contains.Substring("TestGroupName")); }
private bool ValidateConfiguration() { _configValidator = new ConfigValidator(GlobalConfig); var messages = _configValidator.Validate(); if (messages == string.Empty) { return(true); } MessageBox.Show("Errores de configuración", "Error config", MessageBoxButton.OK, MessageBoxImage.Error); return(false); }
private void ValidateConfig() { var result = new ConfigValidator().Validate(_config); if (result.IsValid) { _logger.Info("Config is valid."); } else { var errors = string.Join("\n", result.Errors.Select(p => p.PropertyName + ": " + p.ErrorMessage + " Value: " + p.AttemptedValue)); throw new InvalidProgramException("Invalid configuration!\n" + errors); } }
public ValidationResponse Init(ItemGeneratorConfig config) { var validate = new ConfigValidator(config).Validation(); if (validate.Passed) { Definitions = config.ItemDefinitions; Properties = config.PropertyDefinitions; Rarities = config.RarityDefinitions; ItemLevelScale = config.ItemLevelScale; ItemOverallLevelCap = config.LevelCap; return(validate); } else { return(validate); } }
public bool TryLoadAndValidateConfig(out Config?config) { config = null; if (!_configfile.IsExisting) { _log.Info("No bookgen.json config found."); return(false); } config = _configfile.DeserializeJson <Config>(_log); if (config == null) { _log.Critical("bookgen.json deserialize error. Invalid config file"); return(false); } if (config.Version < Program.CurrentState.ConfigVersion) { _configfile.CreateBackup(_log); config.UpgradeTo(Program.CurrentState.ConfigVersion); _configfile.SerializeJson(config, _log, true); _log.Info("Configuration file migrated to new version."); _log.Info("Review configuration then run program again"); return(false); } ConfigValidator validator = new ConfigValidator(config, _workdir); validator.Validate(); if (!validator.IsValid) { _log.Warning("Errors found in configuration: "); foreach (var error in validator.Errors) { _log.Warning(error); } return(false); } return(true); }
public void Validation007_Propagation() { ConfigValidator.Reset(); var cfg = new Config(); //cfg.SolutionPath = @"..\..\..\..\"; string mes1 = "test error message"; string mes2 = "test error message2"; var gr = cfg.Model.GroupConstantGroups.AddGroupConstants("Gr"); gr.NodeAddNewSubNode(); ConstantValidator.Validator.RuleFor(x => x).Null().WithMessage(mes1).WithSeverity(Severity.Error).WithState(x => SeverityWeight.Normal); cfg.ValidateSubTreeFromNode(cfg.Model.GroupConstantGroups); Assert.IsTrue(cfg.Model.GroupConstantGroups.ListConstantGroups[0].ListConstants[0].ValidationCollection.Count == 1); Assert.IsTrue(cfg.Model.GroupConstantGroups.ListConstantGroups[0].ListConstants[0].CountErrors == 1); Assert.IsTrue(cfg.Model.GroupConstantGroups.ListConstantGroups[0].CountErrors == 1); Assert.IsTrue(cfg.Model.GroupConstantGroups.ValidationCollection.Count == 1); Assert.IsTrue(cfg.Model.GroupConstantGroups.CountErrors == 1); Assert.IsTrue(cfg.ValidationCollection.Count == 0); Assert.IsTrue(cfg.CountErrors == 1); Assert.IsTrue(cfg.CountInfos == 0); Assert.IsTrue(cfg.CountWarnings == 0); cfg.Model.GroupEnumerations.NodeAddNewSubNode(); EnumerationValidator.Validator.RuleFor(x => x).Null().WithMessage(mes2).WithSeverity(Severity.Error).WithState(x => SeverityWeight.Low); cfg.ValidateSubTreeFromNode(cfg.Model.GroupEnumerations); Assert.IsTrue(cfg.Model.GroupEnumerations[0].ValidationCollection.Count == 1); Assert.IsTrue(cfg.Model.GroupEnumerations[0].CountErrors == 1); Assert.IsTrue(cfg.Model.GroupEnumerations.ValidationCollection.Count == 1); Assert.IsTrue(cfg.Model.GroupEnumerations.CountErrors == 1); Assert.IsTrue(cfg.ValidationCollection.Count == 0); Assert.IsTrue(cfg.CountErrors == 2); Assert.IsTrue(cfg.CountInfos == 0); Assert.IsTrue(cfg.CountWarnings == 0); cfg.ValidateSubTreeFromNode(cfg); Assert.IsTrue(cfg.ValidationCollection.Count == 2); Assert.IsTrue(cfg.CountErrors == 2); Assert.IsTrue(cfg.CountInfos == 0); Assert.IsTrue(cfg.CountWarnings == 0); }
/// <summary> /// Click event handler for saving the new config file to a new location. Validates prior to saving. Displays the error/save message box. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void SaveFileAs_Click(object sender, EventArgs e) { try { var formProcessor = new FormProcessor(ContentFlow); var cv = new ConfigValidator(ConfigPath, SchemaPath); if (cv.Validate(true) != 0) { throw new InvalidDataException("XSD-based Validation Failed. Check for errors."); } var cf = new ConfigWriter(); var safeFile = new SaveFileDialog(); safeFile.Title = "Select the new location for the newrelic.config file"; safeFile.FileName = "newrelic.config"; safeFile.Filter = "config files (*.config)|*.config|All files (*.*)|*.*"; safeFile.FilterIndex = 0; safeFile.RestoreDirectory = true; if (safeFile.ShowDialog() == DialogResult.OK) { cf.Write(safeFile.FileName); } Saved.Text = "Saved newrelic.config successfully"; Saved.BackColor = Color.FromArgb(244, 144, 0); Saved.Visible = true; _savedTimer.Start(); } catch (Exception ex) { log.Error(ex); Saved.Text = ex.Message; Saved.BackColor = Color.DarkRed; Saved.Visible = true; _savedTimer.Start(); } }
private void BtnSave_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrEmpty(TbDataBase.Text.Trim()) || string.IsNullOrEmpty(TbPathPendingBills.Text.Trim()) || string.IsNullOrEmpty(TbEmail.Text.Trim()) || string.IsNullOrEmpty(TbPassWord.Password.Trim()) || string.IsNullOrEmpty(TbPathSentBills.Text.Trim()) || string.IsNullOrEmpty(TbShippingTime.Text.Trim()) || string.IsNullOrEmpty(TbIntervalos.Text.Trim()) || string.IsNullOrEmpty(TbEmailServer.Text.Trim()) || string.IsNullOrEmpty(TbEmailServerPort.Text.Trim())) { MessageBox.Show(Properties.Resources.MUST_WRITE_ANY_CONFIG, Properties.Resources.INCOMPLETE_CONFIG, MessageBoxButton.OK, MessageBoxImage.Error); return; } var config = new Global { DataBasePath = TbDataBase.Text, PendingBillPath = TbPathPendingBills.Text, SentBillPath = TbPathSentBills.Text, Email = TbEmail.Text, EmailPassWord = TbPassWord.Password, EmailSever = TbEmailServer.Text, EmailSeverPort = int.Parse(TbEmailServerPort.Text), ShippingTime = TbShippingTime.Text, ShippingInterval = TbIntervalos.Text, LastShipmentWithErrors = _config.LastShipmentWithErrors }; var configValidate = new ConfigValidator(config); var messages = configValidate.Validate(); if (messages != string.Empty) { MessageBox.Show(messages, Properties.Resources.CONFIG_ERRORS, MessageBoxButton.OK, MessageBoxImage.Error); return; } Repositorio.Save(config); MessageBox.Show(Properties.Resources.CORRECT_SAVE, Properties.Resources.SAVE_CONFIG, MessageBoxButton.OK, MessageBoxImage.Asterisk); }
public async Task LoadAndGenerateAlarms(RunMode mode) { try { _logger.Info($"Starting {mode}"); var config = _configLoader.LoadConfig(); ConfigValidator.Validate(config); if (mode == RunMode.GenerateAlarms || mode == RunMode.DryRun) { await GenerateAlarms(config, mode); } _logger.Detail("Done"); } catch (Exception ex) { _logger.Error(ex, "Error in run"); throw; } }
public void TestConfigurationIsValid() { XmlDocument textDoc = new XmlDocument(); textDoc.Load(File.OpenRead(@"Resources\\empty_main.xml")); ConfigParser configParser = new ConfigParser(textDoc); ConfigValidator configValidator = new ConfigValidator(); Assert.AreNotEqual(configValidator.Validate(), "", "Config should not be valid"); foreach (string mandatoryConst in ConfigConsts.ReportMandatory) { configParser.SetStringValue("//Config/" + mandatoryConst, "StringValue"); } Assert.AreEqual(configValidator.Validate(), "", "Config should be valid"); CheckSetConfig(configParser, "abc", "123"); CheckSetConfig(configParser, "Url", @"https://uri.com.br/api/v1/installer?userId=0&programId=49730&status=init"); configParser.SetStringValue("//Config/" + ConfigConsts.URL_ANALYTICS, ""); Assert.AreNotEqual(configValidator.Validate(), "", "Config should not be valid"); }
/// <summary> /// Click event handler for the Validate button on the main form. Uses the error/save dialog. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ValidateXml_Click(object sender, EventArgs e) { var cv = new ConfigValidator(ConfigPath, SchemaPath); int errorCount = cv.Validate(); if (errorCount > 0) { Saved.Text = errorCount + " errors found, see validation.txt"; Saved.BackColor = Color.DarkRed; } else if (errorCount == 0) { Saved.Text = "Valid"; Saved.BackColor = Color.FromArgb(244, 144, 0); } else if (errorCount == -1) { Saved.Text = "Trouble reading the config or xsd files."; Saved.BackColor = Color.DarkRed; } Saved.Visible = true; _savedTimer.Start(); }
public static void NotValid(WatchmanConfiguration config, string expectedMessage) { var ex = Assert.Throws <ConfigException>(() => ConfigValidator.Validate(config)); Assert.That(ex.Message, Is.EqualTo(expectedMessage)); }
public static void IsValid(WatchmanConfiguration config) { ConfigValidator.Validate(config); Assert.That(config, Is.Not.Null); }
public void Validation002_CatalogValidationCollectionContainsValidationMessagesFromSubNodesForSelectedNode() { ConfigValidator.Reset(); CatalogValidator.Reset(); var cfg = new Config(); //cfg.SolutionPath = @"..\..\..\..\"; var c = cfg.Model.GroupCatalogs.AddCatalog("test"); Assert.IsTrue(c.Parent == cfg.Model.GroupCatalogs); string mes1 = "test error message"; string mes2 = "test warning message"; string mes22 = "test warning2 message"; string mes3 = "test info message"; CatalogValidator.Validator.RuleFor(x => x).Null().WithMessage(mes22).WithSeverity(Severity.Warning).WithState(x => SeverityWeight.VeryHigh); CatalogValidator.Validator.RuleFor(x => x).Null().WithMessage(mes1).WithSeverity(Severity.Error).WithState(x => SeverityWeight.VeryLow); CatalogValidator.Validator.RuleFor(x => x).Null().WithMessage(mes3).WithSeverity(Severity.Info).WithState(x => SeverityWeight.VeryHigh); CatalogValidator.Validator.RuleFor(x => x).Null().WithMessage(mes2).WithSeverity(Severity.Warning).WithState(x => SeverityWeight.VeryLow); cfg.Validate(); cfg.ValidateSubTreeFromNode(c, _logger); Assert.IsTrue(cfg.ValidationCollection.Count == 0); Assert.IsTrue(c.ValidationCollection.Count == 4); var p = c.ValidationCollection[0]; Assert.IsTrue(p.Severity == FluentValidation.Severity.Error); Assert.IsTrue(p.Message == mes1); Assert.IsTrue(p.Model == c); p = c.ValidationCollection[1]; Assert.IsTrue(p.Severity == FluentValidation.Severity.Warning); Assert.IsTrue(p.Message == mes22); Assert.IsTrue(p.Model == c); p = c.ValidationCollection[2]; Assert.IsTrue(p.Severity == FluentValidation.Severity.Warning); Assert.IsTrue(p.Message == mes2); Assert.IsTrue(p.Model == c); p = c.ValidationCollection[3]; Assert.IsTrue(p.Severity == FluentValidation.Severity.Info); Assert.IsTrue(p.Message == mes3); Assert.IsTrue(p.Model == c); Assert.AreEqual(1, c.CountErrors); Assert.AreEqual(2, c.CountWarnings); Assert.AreEqual(1, c.CountInfos); Assert.AreEqual(1, cfg.Model.GroupCatalogs.CountErrors); Assert.AreEqual(2, cfg.Model.GroupCatalogs.CountWarnings); Assert.AreEqual(1, cfg.Model.GroupCatalogs.CountInfos); Assert.AreEqual(1, cfg.CountErrors); Assert.AreEqual(2, cfg.CountWarnings); Assert.AreEqual(1, cfg.CountInfos); cfg.ValidateSubTreeFromNode(cfg, _logger); // .ConfigureAwait(continueOnCapturedContext: false); Assert.IsTrue(cfg.ValidationCollection.Count == 4); cfg.ValidateSubTreeFromNode(cfg, _logger); Assert.IsTrue(cfg.ValidationCollection.Count == 4); }
public void TestValidConfig() { var config = CreateConfig(); ConfigValidator.Validate(config); }
private void ValidateCollection(ConfigurationCollection collection, string path) { var validator = new ConfigValidator(collection); validator.GetErrors().ForEach(x => logger.LogError(x.Message, path)); }
/// <summary> /// Click event handler for the Validate button on the main form. Uses the error/save dialog. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ValidateXml_Click(object sender, EventArgs e) { var cv = new ConfigValidator(); int errorCount = cv.Validate(); if (errorCount > 0) { Saved.Text = errorCount + " errors found, see validation.txt"; Saved.BackColor = Color.DarkRed; } else if (errorCount == 0) { Saved.Text = "Valid"; Saved.BackColor = Color.FromArgb(244, 144, 0); } else if (errorCount == -1) { Saved.Text = "Trouble reading the config or xsd files."; Saved.BackColor = Color.DarkRed; } Saved.Visible = true; _savedTimer.Start(); }
/// <summary> /// Click event handler for saving the new config file. Validates prior to saving. Displays the error/save message box. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void SaveFile_Click(object sender, EventArgs e) { try { var reader = new FormReader(ContentFlow); var cv = new ConfigValidator(); if (cv.Validate(true) != 0) { throw new InvalidDataException("XSD-based Validation Failed. Check for errors."); } var cf = new ConfigWriter(); cf.Write(); Saved.Text = "Saved newrelic.config successfully"; Saved.BackColor = Color.FromArgb(244, 144, 0); Saved.Visible = true; _savedTimer.Start(); } catch (Exception ex) { log.Error("01 - " + ex.Message); Saved.Text = ex.Message; Saved.BackColor = Color.DarkRed; Saved.Visible = true; _savedTimer.Start(); } }
/// <summary> /// Click event handler for saving the new config file to a new location. Validates prior to saving. Displays the error/save message box. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void SaveFileAs_Click(object sender, EventArgs e) { try { var reader = new FormReader(ContentFlow); var cv = new ConfigValidator(); if (cv.Validate(true) != 0) { throw new InvalidDataException("XSD-based Validation Failed. Check for errors."); } var cf = new ConfigWriter(); var safeFile = new SaveFileDialog(); safeFile.Title = "Select the new location for the newrelic.config file"; safeFile.FileName = "newrelic.config"; safeFile.Filter = "config files (*.config)|*.config|All files (*.*)|*.*"; safeFile.FilterIndex = 0; safeFile.RestoreDirectory = true; if (safeFile.ShowDialog() == DialogResult.OK) { cf.Write(safeFile.FileName); } Saved.Text = "Saved newrelic.config successfully"; Saved.BackColor = Color.FromArgb(244, 144, 0); Saved.Visible = true; _savedTimer.Start(); } catch (Exception ex) { log.Error(ex); Saved.Text = ex.Message; Saved.BackColor = Color.DarkRed; Saved.Visible = true; _savedTimer.Start(); } }
public void Validation003_AppProjectGeneratorValidationCollectionContainsValidationMessagesFromSubNodesForSelectedNode() { ConfigValidator.Reset(); CatalogValidator.Reset(); var cfg = new Config(); cfg.CurrentCfgFolderPath = @".\"; //cfg.SolutionPath = @"..\..\..\..\"; var sol1 = cfg.GroupAppSolutions.AddAppSolution("sol1", "./"); var prj1 = sol1.AddProject("prj1", "./"); var gen1 = prj1.AddGenerator("gen1", null, null, ""); string mes1 = "test error message"; string mes2 = "test warning message"; string mes22 = "test warning2 message"; string mes3 = "test info message"; //AppProjectGeneratorValidator.Validator.RuleFor(x => x).Null().WithMessage(mes22).WithSeverity(Severity.Warning).WithState(x => SeverityWeight.VeryHigh); //AppProjectGeneratorValidator.Validator.RuleFor(x => x).Null().WithMessage(mes1).WithSeverity(Severity.Error).WithState(x => SeverityWeight.VeryLow); //AppProjectGeneratorValidator.Validator.RuleFor(x => x).Null().WithMessage(mes3).WithSeverity(Severity.Info).WithState(x => SeverityWeight.VeryHigh); //AppProjectGeneratorValidator.Validator.RuleFor(x => x).Null().WithMessage(mes2).WithSeverity(Severity.Warning).WithState(x => SeverityWeight.VeryLow); cfg.Validate(); cfg.ValidateSubTreeFromNode(sol1, _logger); // .ConfigureAwait(continueOnCapturedContext: false); Assert.IsTrue(cfg.ValidationCollection.Count == 0); Assert.IsTrue(sol1.ValidationCollection.Count == 5); //var p = sol1.ValidationCollection[0]; //Assert.IsTrue(p.Severity == FluentValidation.Severity.Error); //Assert.IsTrue(p.Message == mes1); //Assert.IsTrue(p.Model == sol1); //p = sol1.ValidationCollection[1]; //Assert.IsTrue(p.Severity == FluentValidation.Severity.Warning); //Assert.IsTrue(p.Message == mes22); //Assert.IsTrue(p.Model == sol1); //p = sol1.ValidationCollection[2]; //Assert.IsTrue(p.Severity == FluentValidation.Severity.Warning); //Assert.IsTrue(p.Message == mes2); //Assert.IsTrue(p.Model == sol1); //p = sol1.ValidationCollection[3]; //Assert.IsTrue(p.Severity == FluentValidation.Severity.Info); //Assert.IsTrue(p.Message == mes3); //Assert.IsTrue(p.Model == sol1); //Assert.AreEqual(1, sol1.CountErrors); //Assert.AreEqual(2, sol1.CountWarnings); //Assert.AreEqual(1, sol1.CountInfos); //Assert.AreEqual(1, cfg.Model.GroupCatalogs.CountErrors); //Assert.AreEqual(2, cfg.Model.GroupCatalogs.CountWarnings); //Assert.AreEqual(1, cfg.Model.GroupCatalogs.CountInfos); //Assert.AreEqual(1, cfg.CountErrors); //Assert.AreEqual(2, cfg.CountWarnings); //Assert.AreEqual(1, cfg.CountInfos); //cfg.ValidateSubTreeFromNode(cfg, _logger); // .ConfigureAwait(continueOnCapturedContext: false); //Assert.IsTrue(cfg.ValidationCollection.Count == 4); }
public void Run() { // Clean the previous failure log if (File.Exists("failures.log")) { File.Delete("failures.log"); } Config config; // Load config from the file try { config = ConfigLoader.LoadConfig(ConfigLoader.DefaultFilename); } catch (FileNotFoundException) { Console.Error.WriteLine($"Configuration file \"{ConfigLoader.DefaultFilename}\" not found."); Console.ReadLine(); return; } // Check validity of the config var configValidationResult = ConfigValidator.CheckValidity(config); var configProblems = configValidationResult.ReportProblems(); if (configProblems.Any()) { Console.Error.WriteLine($"{configProblems.Count} problem(s) detected in the configuration file."); configProblems.ForEach(it => { Console.Error.WriteLine($"- {it}"); }); Console.ReadLine(); return; } // Initiate a progress bar var pb = new ProgressBar(configValidationResult.TtfFiles.Count(), configValidationResult.TtcFiles.Count()); // Process TTF fonts var failedTtfFonts = ProcessTtfFonts(config, configValidationResult.TtfFiles.ToList(), pb); // Process TTC fonts var failedTtcFonts = ProcessTtcFonts(config, configValidationResult.TtcFiles.ToList(), pb); // Done processing pb.MarkDone(); pb.Dispose(); if (failedTtfFonts.Any() || failedTtcFonts.Any()) { // Write the failures to "failures.log" File.WriteAllLines("failures.log", failedTtfFonts.Concat(failedTtcFonts).Select(it => it.Name)); // Report Console.WriteLine($"Completed with the following {failedTtfFonts.Count + failedTtcFonts.Count} failures. They have been written in \"failures.log\"."); foreach (var failure in failedTtfFonts.Concat(failedTtcFonts)) { Console.WriteLine($"- {failure.Name}"); } } Console.ReadLine(); }
static void InitializeSettings() { var cm = new ConfigManager(); if (cm.FileExists()) { _config = cm.Read(); if (_config.Version != App.SettingsVersion) { Console.WriteLine("Your settings file is outdated, press [Enter] to back up the old version so you may fill out the new one."); Console.ReadLine(); cm.Save(_config, "Config_OLD"); cm.Save(new Config { Version = App.SettingsVersion }); if (!Platform.IsUnix) { SelectFile(Files.ConfigFile); } Console.WriteLine("Press [Enter] to continue."); Console.ReadLine(); Console.WriteLine(); _config = cm.Read(); } var validator = new ConfigValidator(); var results = validator.Validate(_config); if (!results.IsValid) { Console.WriteLine("Your config file is not valid:"); foreach (var error in results.Errors) { string message = error.ErrorMessage; Console.BackgroundColor = ConsoleColor.Red; Console.ForegroundColor = ConsoleColor.White; Console.WriteLine(" - {0}", message); Console.ResetColor(); } Console.WriteLine("Please fix the above errors."); Console.WriteLine("Press [Enter] to exit."); Console.ReadLine(); Environment.Exit(0); } } else { cm.Save(new Config { Version = App.SettingsVersion }); Console.WriteLine("A default config file has been created at {0}", Files.ConfigFile); Console.WriteLine("Documentation for the settings file can be found at {0}", "https://github.com/depthbomb/Scraps/blob/master/SETTINGS.md"); Console.WriteLine("Please fill it out and press [Enter] to continue."); Console.ReadLine(); Console.WriteLine(); _config = cm.Read(); } }