private static int Run(Options options) { int rc = 1; Banner(); if (string.IsNullOrWhiteSpace(options.OutputFilePath)) { options.OutputFilePath = MakeDefaultOutputFilePath(options.InstanceFilePath); } try { List <JsonError> errors = Validator.ValidateFile(options.InstanceFilePath, options.SchemaFilePath) .ToList(); IEnumerable <string> messages = Enumerable.Empty <string>(); using (var logBuilder = new ResultLogBuilder( options.InstanceFilePath, options.SchemaFilePath, options.OutputFilePath, new FileSystem())) { messages = logBuilder.BuildLog(errors); } if (errors.Count == 0) { Console.WriteLine(Resources.Success); rc = 0; } else { Console.WriteLine(Resources.FileContainsErrors, errors.Count); foreach (var message in messages) { Console.WriteLine(message); } } } catch (Exception ex) { ReportException(ex); } return(rc); }
private string FailureReason(IEnumerable <JsonError> errors, string inputFile) { var sb = new StringBuilder("file should be valid, but the following errors were found:\n"); string inputPath = MakeFullPath(inputFile); string outputPath = MakeOutputPath(inputPath); using (var logBuilder = new ResultLogBuilder( inputPath, _jsonSchemaFilePath, outputPath, new FileSystem())) { IEnumerable <string> messages = logBuilder.BuildLog(errors); foreach (var message in messages) { sb.AppendLine(message); } } return(sb.ToString()); }