private static void GenerateTypeMappings(EcsSpecification model) { var targetDir = Path.GetFullPath(CodeConfiguration.ElasticCommonSchemaNESTGeneratedFolder); var outputFile = Path.Combine(targetDir, @"TypeMappings.Generated.cs"); var path = Path.Combine(CodeConfiguration.ViewFolder, @"TypeMappings.Generated.cshtml"); var template = File.ReadAllText(path); var source = DoRazor(nameof(GenerateTypeMappings), template, model); File.WriteAllText(outputFile, source); }
private static void GenerateBaseJsonFormatter(EcsSpecification model) { var targetDir = Path.GetFullPath(CodeConfiguration.ElasticCommonSchemaGeneratedFolder); var outputFile = Path.Combine(targetDir, "Serialization", @"BaseJsonFormatter.Generated.cs"); var path = Path.Combine(CodeConfiguration.ViewFolder, @"BaseJsonFormatter.Generated.cshtml"); var template = File.ReadAllText(path); var source = DoRazor(nameof(GenerateBaseJsonFormatter), template, model); File.WriteAllText(outputFile, source); }
private static EcsSpecification GetEcsSpecification(string downloadBranch, string[] folders) { var specificationFolder = Path.Combine(CodeConfiguration.SpecificationFolder, downloadBranch); var directories = Directory .GetDirectories(specificationFolder, "*", SearchOption.AllDirectories) .Where(f => folders == null || folders.Length == 0 || folders.Contains(new DirectoryInfo(f).Name)) .ToList(); var yamlSchemas = new List <YamlSchema>(); var templates = new Dictionary <int, string>(); using (var progressBar = new ProgressBar(directories.Count, $"Listing {directories.Count} directories", new ProgressBarOptions { BackgroundColor = ConsoleColor.DarkGray })) { var yamlFiles = directories.Select(dir => Directory.GetFiles(dir).Where(f => f.EndsWith("_nested.yml")).ToList() ); foreach (var files in yamlFiles) { using (var fileProgress = progressBar.Spawn(files.Count, $"Listing {files.Count} files", new ProgressBarOptions { ProgressCharacter = '─', BackgroundColor = ConsoleColor.DarkGray })) { foreach (var file in files) { var specifications = GetYamlSchemas(downloadBranch, file); yamlSchemas.AddRange(specifications); fileProgress.Tick(); } } progressBar.Tick(); } var jsonFiles = directories.Select(dir => Directory.GetFiles(dir).Where(f => f.EndsWith(".json")).ToList() ); foreach (var files in jsonFiles) { using (var fileProgress = progressBar.Spawn(files.Count, $"Listing {files.Count} files", new ProgressBarOptions { ProgressCharacter = '─', BackgroundColor = ConsoleColor.DarkGray })) { foreach (var file in files) { var groupCollection = Regex.Match(file, ".*Template(\\d).*").Groups; var versionString = groupCollection[1].Value; var version = int.Parse(versionString); var contents = File.ReadAllText(file); templates.Add(version, contents); } } progressBar.Tick(); } } var spec = new EcsSpecification { YamlSchemas = yamlSchemas, Templates = templates }; return(spec); }
private static string DoRazor(string name, string template, EcsSpecification model) => Razor.CompileRenderStringAsync(name, template, model).GetAwaiter().GetResult();