public APITemplateCreator(FileReader fileReader, TemplateCreator templateCreator, PolicyTemplateCreator policyTemplateCreator, ProductAPITemplateCreator productAPITemplateCreator, DiagnosticTemplateCreator diagnosticTemplateCreator) { this.fileReader = fileReader; this.templateCreator = templateCreator; this.policyTemplateCreator = policyTemplateCreator; this.productAPITemplateCreator = productAPITemplateCreator; this.diagnosticTemplateCreator = diagnosticTemplateCreator; }
public MasterTemplateCreator(TemplateCreator templateCreator) { this.templateCreator = templateCreator; }
public ProductTemplateCreator(TemplateCreator templateCreator) { this.templateCreator = templateCreator; }
public CreateCommand() { this.Name = GlobalConstants.CreateName; this.Description = GlobalConstants.CreateDescription; // list command options CommandOption configFile = this.Option("--configFile <configFile>", "Config YAML file location", CommandOptionType.SingleValue).IsRequired(); this.HelpOption(); this.OnExecute(async() => { // convert config file to CreatorConfig class FileReader fileReader = new FileReader(); CreatorConfig creatorConfig = await fileReader.ConvertConfigYAMLToCreatorConfigAsync(configFile.Value()); // validate creator config bool isValidCreatorConfig = ValidateCreatorConfig(creatorConfig); if (isValidCreatorConfig == true) { // required parameters have been supplied // initialize helper classes FileWriter fileWriter = new FileWriter(); FileNameGenerator fileNameGenerator = new FileNameGenerator(); TemplateCreator templateCreator = new TemplateCreator(); APIVersionSetTemplateCreator apiVersionSetTemplateCreator = new APIVersionSetTemplateCreator(templateCreator); LoggerTemplateCreator loggerTemplateCreator = new LoggerTemplateCreator(templateCreator); ProductTemplateCreator productTemplateCreator = new ProductTemplateCreator(templateCreator); ProductAPITemplateCreator productAPITemplateCreator = new ProductAPITemplateCreator(); PolicyTemplateCreator policyTemplateCreator = new PolicyTemplateCreator(fileReader); DiagnosticTemplateCreator diagnosticTemplateCreator = new DiagnosticTemplateCreator(); APITemplateCreator apiTemplateCreator = new APITemplateCreator(fileReader, templateCreator, policyTemplateCreator, productAPITemplateCreator, diagnosticTemplateCreator); MasterTemplateCreator masterTemplateCreator = new MasterTemplateCreator(templateCreator); CreatorFileNames creatorFileNames = fileNameGenerator.GenerateCreatorLinkedFileNames(creatorConfig); // create templates from provided configuration Template apiVersionSetsTemplate = creatorConfig.apiVersionSets != null ? apiVersionSetTemplateCreator.CreateAPIVersionSetTemplate(creatorConfig) : null; Template productsTemplate = creatorConfig.products != null ? productTemplateCreator.CreateProductTemplate(creatorConfig) : null; Template loggersTemplate = creatorConfig.loggers != null ? loggerTemplateCreator.CreateLoggerTemplate(creatorConfig) : null; // store name and full template on each api necessary to build unlinked templates Dictionary <string, Template> initialAPITemplates = new Dictionary <string, Template>(); Dictionary <string, Template> subsequentAPITemplates = new Dictionary <string, Template>(); // store name and whether the api will depend on the version set template each api necessary to build linked templates List <LinkedMasterTemplateAPIInformation> apiInformation = new List <LinkedMasterTemplateAPIInformation>(); // create parameters file Template masterTemplateParameters = masterTemplateCreator.CreateMasterTemplateParameterValues(creatorConfig); foreach (APIConfig api in creatorConfig.apis) { Template initialAPITemplate = await apiTemplateCreator.CreateInitialAPITemplateAsync(creatorConfig, api); Template subsequentAPITemplate = apiTemplateCreator.CreateSubsequentAPITemplate(api); initialAPITemplates.Add(api.name, initialAPITemplate); subsequentAPITemplates.Add(api.name, subsequentAPITemplate); apiInformation.Add(new LinkedMasterTemplateAPIInformation() { name = api.name, dependsOnVersionSets = api.apiVersionSetId != null, dependsOnProducts = api.products != null, dependsOnLoggers = masterTemplateCreator.DetermineIfAPIDependsOnLogger(api, fileReader) }); } // write templates to outputLocation if (creatorConfig.linked == true) { // create linked master template Template masterTemplate = masterTemplateCreator.CreateLinkedMasterTemplate(apiVersionSetsTemplate, productsTemplate, loggersTemplate, apiInformation, creatorFileNames, fileNameGenerator); fileWriter.WriteJSONToFile(masterTemplate, String.Concat(creatorConfig.outputLocation, creatorFileNames.linkedMaster)); } foreach (KeyValuePair <string, Template> initialAPITemplatePair in initialAPITemplates) { string initialAPIFileName = fileNameGenerator.GenerateAPIFileName(initialAPITemplatePair.Key, true); fileWriter.WriteJSONToFile(initialAPITemplatePair.Value, String.Concat(creatorConfig.outputLocation, initialAPIFileName)); } foreach (KeyValuePair <string, Template> subsequentAPITemplatePair in subsequentAPITemplates) { string subsequentAPIFileName = fileNameGenerator.GenerateAPIFileName(subsequentAPITemplatePair.Key, false); fileWriter.WriteJSONToFile(subsequentAPITemplatePair.Value, String.Concat(creatorConfig.outputLocation, subsequentAPIFileName)); } if (apiVersionSetsTemplate != null) { fileWriter.WriteJSONToFile(apiVersionSetsTemplate, String.Concat(creatorConfig.outputLocation, creatorFileNames.apiVersionSets)); } if (productsTemplate != null) { fileWriter.WriteJSONToFile(productsTemplate, String.Concat(creatorConfig.outputLocation, creatorFileNames.products)); } if (loggersTemplate != null) { fileWriter.WriteJSONToFile(loggersTemplate, String.Concat(creatorConfig.outputLocation, creatorFileNames.loggers)); } // write parameters to outputLocation fileWriter.WriteJSONToFile(masterTemplateParameters, String.Concat(creatorConfig.outputLocation, creatorConfig.linked == true ? creatorFileNames.linkedParameters : creatorFileNames.unlinkedParameters)); ColoredConsole.WriteLine("Templates written to output location"); } return(0); }); }
public APIVersionSetTemplateCreator(TemplateCreator templateCreator) { this.templateCreator = templateCreator; }
public CreateCommand() { this.Name = Constants.CreateName; this.Description = Constants.CreateDescription; // list command options CommandOption configFile = this.Option("--configFile <configFile>", "Config YAML file location", CommandOptionType.SingleValue).IsRequired(); this.HelpOption(); this.OnExecute(async() => { // convert config file to CreatorConfig class FileReader fileReader = new FileReader(); CreatorConfig creatorConfig = await fileReader.ConvertConfigYAMLToCreatorConfigAsync(configFile.Value()); // validate creator config bool isValidCreatorConfig = ValidateCreatorConfig(creatorConfig); if (isValidCreatorConfig == true) { // required parameters have been supplied // initialize helper classes FileWriter fileWriter = new FileWriter(); TemplateCreator templateCreator = new TemplateCreator(); APIVersionSetTemplateCreator apiVersionSetTemplateCreator = new APIVersionSetTemplateCreator(templateCreator); ProductAPITemplateCreator productAPITemplateCreator = new ProductAPITemplateCreator(); PolicyTemplateCreator policyTemplateCreator = new PolicyTemplateCreator(fileReader); DiagnosticTemplateCreator diagnosticTemplateCreator = new DiagnosticTemplateCreator(); APITemplateCreator apiTemplateCreator = new APITemplateCreator(fileReader, templateCreator, policyTemplateCreator, productAPITemplateCreator, diagnosticTemplateCreator); MasterTemplateCreator masterTemplateCreator = new MasterTemplateCreator(templateCreator); // create templates from provided configuration Template apiVersionSetTemplate = creatorConfig.apiVersionSet != null ? apiVersionSetTemplateCreator.CreateAPIVersionSetTemplate(creatorConfig) : null; Template initialAPITemplate = await apiTemplateCreator.CreateInitialAPITemplateAsync(creatorConfig); Template subsequentAPITemplate = apiTemplateCreator.CreateSubsequentAPITemplate(creatorConfig); if (creatorConfig.linked == true) { CreatorFileNames creatorFileNames = fileWriter.GenerateCreatorLinkedFileNames(); // create linked master template Template masterTemplate = masterTemplateCreator.CreateLinkedMasterTemplate(apiVersionSetTemplate, initialAPITemplate, subsequentAPITemplate, creatorFileNames); Template masterTemplateParameters = masterTemplateCreator.CreateMasterTemplateParameterValues(creatorConfig); // write templates to outputLocation if (apiVersionSetTemplate != null) { fileWriter.WriteJSONToFile(apiVersionSetTemplate, String.Concat(creatorConfig.outputLocation, creatorFileNames.apiVersionSet)); } fileWriter.WriteJSONToFile(initialAPITemplate, String.Concat(creatorConfig.outputLocation, creatorFileNames.initialAPI)); fileWriter.WriteJSONToFile(subsequentAPITemplate, String.Concat(creatorConfig.outputLocation, creatorFileNames.subsequentAPI)); fileWriter.WriteJSONToFile(masterTemplate, String.Concat(creatorConfig.outputLocation, "/master.template.json")); fileWriter.WriteJSONToFile(masterTemplateParameters, String.Concat(creatorConfig.outputLocation, "/master.parameters.json")); } else { // create unlinked master template Template initialMasterTemplate = masterTemplateCreator.CreateInitialUnlinkedMasterTemplate(apiVersionSetTemplate, initialAPITemplate); Template subsequentMasterTemplate = masterTemplateCreator.CreateSubsequentUnlinkedMasterTemplate(subsequentAPITemplate); Template masterTemplateParameters = masterTemplateCreator.CreateMasterTemplateParameterValues(creatorConfig); // write templates to outputLocation fileWriter.WriteJSONToFile(initialMasterTemplate, String.Concat(creatorConfig.outputLocation, "/master1.template.json")); fileWriter.WriteJSONToFile(subsequentMasterTemplate, String.Concat(creatorConfig.outputLocation, "/master2.template.json")); fileWriter.WriteJSONToFile(masterTemplateParameters, String.Concat(creatorConfig.outputLocation, "/master.parameters.json")); } ColoredConsole.WriteLine("Templates written to output location"); } return(0); }); }
public LoggerTemplateCreator(TemplateCreator templateCreator) { this.templateCreator = templateCreator; }