private static void BuildDocumentation(string content, List <string> matches) { Collection <PGSchema> schemas = SchemaProcessor.GetSchemas(Program.SchemaPattern, Program.xSchemaPattern); content = content.Replace("[DBName]", Program.Database.ToUpperInvariant()); content = Parsers.SchemaParser.Parse(content, matches, schemas); FileHelper.WriteFile(content, OutputPath); Console.WriteLine("Writing tables."); TablesRunner.Run(); Console.WriteLine("Writing triggers."); TriggersRunner.Run(); Console.WriteLine("Writing views."); ViewsRunner.Run(); Console.WriteLine("Writing materialized views."); MaterializedViewsRunner.Run(); Console.WriteLine("Writing sequences."); SequencesRunner.Run(); Console.WriteLine("Writing functions."); FunctionsRunner.Run(); Console.WriteLine("Writing types."); TypesRunner.Run(); }
private void TryExportSchema(SchemaProcessor schemaProcessor) { try { if (DialogResult.Yes == MessageBox.Show("Do you want to use the built in newrelic.xsd file?", "Use built in newrelic.xsd?", MessageBoxButtons.YesNo)) { using ( var resource = Assembly.GetExecutingAssembly() .GetManifestResourceStream("NewRelic.AgentConfiguration.Resources.newrelic.xsd")) { using ( var file = new FileStream(Application.StartupPath + "\\newrelic.xsd", FileMode.Create, FileAccess.Write)) { resource.CopyTo(file); } } schemaProcessor.ProcessSchema(Application.StartupPath + "\\newrelic.xsd"); SchemaPath = Application.StartupPath + "\\newrelic.xsd"; } } catch (Exception ex) { log.Error(ex); MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message); } }
public OverwriteApplier(IHostService host, OverwriteModelType type) { _host = host ?? throw new ArgumentNullException(nameof(host)); _overwriteModelType = type; switch (type) { case OverwriteModelType.Classic: _overwriteProcessor = new SchemaProcessor( new FileIncludeInterpreter(), new MarkdownWithContentAnchorInterpreter(new MarkdownInterpreter()), new FileInterpreter(true, false), new HrefInterpreter(true, false), new XrefInterpreter() ); break; case OverwriteModelType.MarkdownFragments: _overwriteProcessor = new SchemaProcessor( new FileIncludeInterpreter(), new FileInterpreter(true, false), new HrefInterpreter(true, false), new MarkdownAstInterpreter(new MarkdownInterpreter()), new XrefInterpreter() ); break; } }
private static void BuildDocumentation(string content, List <string> matches, string schemaName) { PGSchema schema = SchemaProcessor.GetSchema(schemaName); content = content.Replace("[DBName]", Program.Database.ToUpperInvariant()); content = content.Replace("[SchemaName]", schemaName); content = SequenceParser.Parse(content, matches, SequenceProcessor.GetSequences(schemaName)); content = TableParser.Parse(content, matches, schema.Tables); content = ViewParser.Parse(content, matches, schema.Views); content = SequenceParser.Parse(content, matches, schema.Sequences); content = MaterializedViewParser.Parse(content, matches, schema.MaterializedViews); content = FunctionParser.Parse(content, matches, schema.Functions); content = FunctionParser.ParseTriggers(content, matches, schema.TriggerFunctions); content = TypeParser.Parse(content, matches, schema.Types); foreach (PgTable table in schema.Tables) { Console.WriteLine("Generating documentation for table \"{0}\".", table.Name); TableRunner.Run(table); } foreach (PgFunction function in schema.Functions) { Console.WriteLine("Generating documentation for function \"{0}\".", function.Name); FunctionRunner.Run(function); } foreach (PgFunction function in schema.TriggerFunctions) { Console.WriteLine("Generating documentation for trigger function \"{0}\".", function.Name); FunctionRunner.Run(function); } foreach (PgMaterializedView materializedView in schema.MaterializedViews) { Console.WriteLine("Generating documentation for materialized view \"{0}\".", materializedView.Name); MaterializedViewRunner.Run(materializedView); } foreach (PgView view in schema.Views) { Console.WriteLine("Generating documentation for view \"{0}\".", view.Name); ViewRunner.Run(view); } foreach (PgType type in schema.Types) { Console.WriteLine("Generating documentation for type \"{0}\".", type.Name); TypeRunner.Run(type); } string targetPath = System.IO.Path.Combine(OutputPath, schemaName + ".html"); FileHelper.WriteFile(content, targetPath); }
public override void Postbuild(ImmutableList <FileModel> models, IHostService host) { if (TagInterpreters == null) { return; } var schemaProcessor = new SchemaProcessor(new TagsInterpreter(TagInterpreters.ToList())); models.Where(s => s.Type == DocumentType.Article).RunAll(model => { model.Content = schemaProcessor.Process(model.Content, model.Properties.Schema, new ProcessContext(host, model)); }); }
public override void Postbuild(ImmutableList <FileModel> models, IHostService host) { if (TagInterpreters == null) { return; } var schemaProcessor = new SchemaProcessor(new TagsInterpreter(TagInterpreters.ToList())); foreach (var model in models) { model.Content = schemaProcessor.Process(model.Content, model.Properties.Schema, new ProcessContext(host, model)); } }
public override void Postbuild(ImmutableList <FileModel> models, IHostService host) { var schemaProcessor = new SchemaProcessor(new MergeTypeInterpreter()); foreach (var uid in host.GetAllUids()) { var ms = host.LookupByUid(uid); var od = ms.Where(m => m.Type == DocumentType.Overwrite).ToList(); var articles = ms.Except(od).ToList(); if (articles.Count == 0 || od.Count == 0) { continue; } if (articles.Count > 1) { throw new DocumentException($"{uid} is defined in multiple articles {articles.Select(s => s.LocalPathFromRoot).ToDelimitedString()}"); } var model = articles[0]; var uids = model.Properties.Uids; model.Content = schemaProcessor.Process(model.Content, model.Properties.Schema, new ProcessContext(host, model)); } }
public static async Task Generate(GeneratorOptions options) { Stream openApiStream = null; if (options.Url != null) { var http = new HttpClient(); try { openApiStream = await http.GetStreamAsync(options.Url); } catch { ConsoleHelper.WriteLineColored("Failed to load data from the given URL", ConsoleColor.Red); } } else if (options.File != null) { openApiStream = File.OpenRead(options.File.FullName); } else { ConsoleHelper.WriteLineColored("Either a file or a url is required", ConsoleColor.Red); return; } try { if (options.RemoveIfExists && Directory.Exists(options.OutputDirectory.FullName)) { Directory.Delete(options.OutputDirectory.FullName, true); } if (!Directory.Exists(options.OutputDirectory.FullName)) { Directory.CreateDirectory(options.OutputDirectory.FullName); } if (options.ProjectName == null) { options.ProjectName = options.OutputDirectory.Name; } var openApiDocument = new OpenApiStreamReader().Read(openApiStream, out var diagnostic); openApiStream.Dispose(); File.Copy(Path.Combine(AppContext.BaseDirectory, TemplatesDirectory, options.Executable ? "CsprojExe.xml" : "CsprojLib.xml"), Path.Combine(options.OutputDirectory.FullName, options.ProjectName + ".csproj")); Directory.CreateDirectory(Path.Combine(options.OutputDirectory.FullName, ModelsDirectory)); Directory.CreateDirectory(Path.Combine(options.OutputDirectory.FullName, ApisDirectory)); if (openApiDocument.Components == null && openApiDocument.Paths == null) { ConsoleHelper.WriteLineColored("Input document is not an OpenApi definition.", ConsoleColor.Red); return; } SchemaProcessor.ProcessSchemas(options, openApiDocument.Components.Schemas); var allApis = new List <string>(); foreach (var pathGroup in GetPathGroups(openApiDocument.Paths, options.GroupingStrategy)) { string apiName = pathGroup.Key.ToPascalCase(); allApis.Add(apiName); string apiCode = InterfaceWriter.GetApiInterface(options, pathGroup.Key, pathGroup); await File.WriteAllTextAsync(Path.Combine(options.OutputDirectory.FullName, ApisDirectory, $"I{apiName}Api.cs"), apiCode); } string clientCode = GetClientClass(options.ProjectName, allApis); await File.WriteAllTextAsync(Path.Combine(options.OutputDirectory.FullName, $"ApiClient.cs"), clientCode); if (options.Executable) { string programTemplate = File.ReadAllText(Path.Combine(AppContext.BaseDirectory, TemplatesDirectory, "ProgramTemplate.csx")); await File.WriteAllTextAsync( Path.Combine(options.OutputDirectory.FullName, "Program.cs"), string.Format(programTemplate, options.ProjectName, openApiDocument.Servers.FirstOrDefault()?.Url ?? "url missing!")); } } catch (IOException) { ConsoleHelper.WriteLineColored("Could not write to that location.", ConsoleColor.Red); } }
/// <summary> /// Click event handler for the Open button. This handles finding and opening the XSD file and the CONFIG file. /// Will always prompt for CONFIG and only prompts for XSD if it cannot locate it. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OpenFile_Click(object sender, EventArgs e) { LoadingLabel.Visible = true; var schemaProcessor = new SchemaProcessor(); DataFile.Instance.SchemaFile = schemaProcessor.ProcessSchema(FilePaths.Instance.SchemaFile); if (DataFile.Instance.SchemaFile != null) { SchemaPath = FilePaths.Instance.SchemaFile; } else { var openFile = new OpenFileDialog(); openFile.Title = "Select the newrelic.xsd file"; openFile.InitialDirectory = "c:\\ProgramData\\New Relic\\.Net Agent"; openFile.FileName = "newrelic.xsd"; openFile.Filter = "xsd files (*.xsd)|*.xsd|All files (*.*)|*.*"; openFile.FilterIndex = 0; openFile.Multiselect = false; openFile.RestoreDirectory = true; if (openFile.ShowDialog() == DialogResult.OK) { try { DataFile.Instance.SchemaFile = schemaProcessor.ProcessSchema(openFile.FileName); SchemaPath = openFile.FileName; } catch (Exception ex) { log.Error(ex); MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message); } } else { TryExportSchema(schemaProcessor); } } if (DataFile.Instance.SchemaFile != null) { var openFile = new OpenFileDialog(); openFile.Title = "Select the newrelic.config file"; openFile.InitialDirectory = Path.GetDirectoryName(FilePaths.Instance.ConfigFile); openFile.FileName = "newrelic.config"; openFile.Filter = "config files (*.config)|*.config|All files (*.*)|*.*"; openFile.FilterIndex = 0; openFile.Multiselect = false; openFile.RestoreDirectory = true; if (openFile.ShowDialog() == DialogResult.OK) { try { var configProcessor = new ConfigProcessor(); DataFile.Instance.ConfigFile = configProcessor.ProcessConfig(openFile.FileName); ConfigPath = openFile.FileName; DataFile.Instance.MergedFile = DataFile.Instance.SchemaFile.Clone(); var mergeProcessor = new MergeProcessor(); mergeProcessor.PrePopulateMergedFile(DataFile.Instance.SchemaFile, DataFile.Instance.MergedFile); mergeProcessor.Merge(DataFile.Instance.ConfigFile); mergeProcessor.SetMergedRootObject(DataFile.Instance.MergedFile); LoadUI(); } catch (Exception ex) { log.Error(ex); MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message); } } else { TryExportConfig(); } } LoadingLabel.Visible = false; }
public void PopulateSchemaFile() { var sproc = new SchemaProcessor(); DataFile.Instance.SchemaFile = sproc.ProcessSchema(PathRoot); }