/// <summary> /// To generate WebAPI Sub Projects and added those projects to root solutions created by Swagger Codegen /// </summary> /// <param name="webapiName">Package Name from Swagger codegen. example - For ProtoType.Api, webapiName is Prototype </param> /// <param name="subProjects"></param> /// <param name=""></param> /// <param name=""></param> public async Task GenerateSubProjectProjectCode(CodeGenConfig config, WebApiProjectStructure webApiProjectStructure) { string apiRootProjectPath = config.outputFolderPath + "\\" + "src"; string apiSolutionPath = config.outputFolderPath + "\\" + config.PackageName + "." + webApiProjectStructure.RootWebAPIProjectNameSuffix + ".sln"; string[] folders = System.IO.Directory.GetDirectories(apiRootProjectPath); if (folders != null && folders.Length > 0) { foreach (var subProject in webApiProjectStructure.SubProjects) { var subProjectDirectoryPath = apiRootProjectPath + "\\" + config.PackageName + "." + subProject.SubProjectPath; if (Directory.Exists(apiRootProjectPath)) { Directory.CreateDirectory(subProjectDirectoryPath); } var codeGenerationOptions = new DotNetCoreCommandOptions(); codeGenerationOptions.ProjectName = config.PackageName + "." + subProject.SubProjectName; codeGenerationOptions.ProjectType = subProject.SubProjectType; codeGenerationOptions.OutPutLocation = subProjectDirectoryPath; await CodeGenerationCoreOperations.CreateNewDotNetCoreProject(codeGenerationOptions); var csprojFilePath = codeGenerationOptions.OutPutLocation + "\\" + codeGenerationOptions.ProjectName + ".csproj"; while (!File.Exists(csprojFilePath)) { } await CodeGenerationCoreOperations.AddProjectToSoluion(apiSolutionPath, csprojFilePath); } } }
/// <summary> /// Loads the <see cref="CodeGenConfig"/> before the corresponding <see cref="CodeGenConfig.Children"/>. /// </summary> /// <param name="config">The <see cref="CodeGenConfig"/> being loaded.</param> public void LoadBeforeChildren(CodeGenConfig config) { if (config.Attributes.ContainsKey("Property")) { UpdateConfigFromProperty(config, config.Attributes["Property"]); } config.AttributeAdd("PrivateName", CodeGenerator.ToPrivateCase(config.Attributes["Name"])); config.AttributeAdd("ArgumentName", CodeGenerator.ToCamelCase(config.Attributes["Name"])); config.AttributeAdd("Type", "string"); config.AttributeAdd("LayerPassing", "All"); if (config.GetAttributeValue <string>("RefDataType") != null) { config.AttributeAdd("Text", string.Format("{1} (see {{{{{0}}}}})", config.Attributes["Type"], CodeGenerator.ToSentenceCase(config.Attributes["Name"]))); } else if (CodeGenConfig.SystemTypes.Contains(config.Attributes["Type"])) { config.AttributeAdd("Text", CodeGenerator.ToSentenceCase(config.Attributes["Name"])); } else { config.AttributeAdd("Text", string.Format("{1} (see {{{{{0}}}}})", config.Attributes["Type"], CodeGenerator.ToSentenceCase(config.Attributes["Name"]))); } config.AttributeUpdate("Text", config.Attributes["Text"]); }
private static void AddTableColumns(CodeGenConfig config, Table table) { if (CodeGenConfig.FindConfigList(config, "Column") != null) { return; } var eci = string.IsNullOrEmpty(config.GetAttributeValue <string>("IncludeColumns")) ? new List <string>() : config.GetAttributeValue <string>("IncludeColumns").Split(',').Select(x => x.Trim()).ToList(); var ecx = string.IsNullOrEmpty(config.GetAttributeValue <string>("ExcludeColumns")) ? new List <string>() : config.GetAttributeValue <string>("ExcludeColumns").Split(',').Select(x => x.Trim()).ToList(); var colList = new List <CodeGenConfig>(); foreach (var col in table.Columns) { if (string.IsNullOrEmpty(col.Name)) { continue; } if (eci.Count > 0 && !eci.Contains(col.Name)) { continue; } if (ecx.Contains(col.Name)) { continue; } var c = new CodeGenConfig("Column", config); c.AttributeAdd("Name", col.Name); c.AttributeAdd("Type", col.Type); c.AttributeAdd("IsNullable", XmlConvert.ToString(col.IsNullable)); c.AttributeAdd("IsIdentity", XmlConvert.ToString(col.IsIdentity)); c.AttributeAdd("IsPrimaryKey", XmlConvert.ToString(col.IsPrimaryKey)); c.AttributeAdd("IsComputed", XmlConvert.ToString(col.IsComputed)); if (col.Length.HasValue) { c.AttributeAdd("Length", XmlConvert.ToString(col.Length.Value)); } if (col.Precision.HasValue) { c.AttributeAdd("Precision", XmlConvert.ToString(col.Precision.Value)); } if (col.Scale.HasValue) { c.AttributeAdd("Scale", XmlConvert.ToString(col.Scale.Value)); } c.AttributeAdd("DotNetType", col.DotNetType); colList.Add(c); } if (colList.Count > 0) { config.Children.Add("Column", colList); } }
/// <summary> /// Loads the <see cref="CodeGenConfig"/> before the corresponding <see cref="CodeGenConfig.Children"/>. /// </summary> /// <param name="config">The <see cref="CodeGenConfig"/> being loaded.</param> public void LoadBeforeChildren(CodeGenConfig config) { config.AttributeAdd("Type", "string"); if (config.GetAttributeValue <string>("RefDataType") != null) { config.AttributeAdd("Text", string.Format("{1} (see {{{{{0}}}}})", config.Attributes["Type"], CodeGenerator.ToSentenceCase(config.Attributes["Name"]))); } else if (CodeGenConfig.SystemTypes.Contains(config.Attributes["Type"])) { config.AttributeAdd("Text", CodeGenerator.ToSentenceCase(config.Attributes["Name"])); } else { config.AttributeAdd("Text", string.Format("{1} (see {{{{{0}}}}})", config.Attributes["Type"], CodeGenerator.ToSentenceCase(config.Attributes["Name"]))); } config.AttributeUpdate("Text", config.Attributes["Text"]); config.AttributeAdd("StringTrim", "End"); config.AttributeAdd("StringTransform", "EmptyToNull"); config.AttributeAdd("DateTimeTransform", "DateTimeLocal"); config.AttributeAdd("PrivateName", CodeGenerator.ToPrivateCase(config.Attributes["Name"])); config.AttributeAdd("ArgumentName", CodeGenerator.ToCamelCase(config.Attributes["Name"])); config.AttributeAdd("DisplayName", GenerateDisplayName(config)); }
/// <summary> /// Loads the <see cref="CodeGenConfig"/> before the corresponding <see cref="CodeGenConfig.Children"/>. /// </summary> /// <param name="config">The <see cref="CodeGenConfig"/> being loaded.</param> public Task LoadBeforeChildrenAsync(CodeGenConfig config) { if (config == null) { throw new ArgumentNullException(nameof(config)); } if (!config.Attributes.ContainsKey("Name")) { throw new CodeGenException("Property element must have a Name property."); } config.AttributeAdd("Type", "string"); if (config.GetAttributeValue <string>("Type").StartsWith("RefDataNamespace.", StringComparison.InvariantCulture)) { config.AttributeAdd("RefDataType", "string"); } if (config.GetAttributeValue <string>("RefDataType") != null) { config.AttributeAdd("Text", string.Format(System.Globalization.CultureInfo.InvariantCulture, "{1} (see {{{{{0}}}}})", config.Attributes["Type"], CodeGenerator.ToSentenceCase(config.Attributes["Name"]))); } else if (CodeGenConfig.SystemTypes.Contains(config.Attributes["Type"] !)) { config.AttributeAdd("Text", CodeGenerator.ToSentenceCase(config.Attributes["Name"])); }
/// <summary> /// Loads the <see cref="CodeGenConfig"/> before the corresponding <see cref="CodeGenConfig.Children"/>. /// </summary> /// <param name="config">The <see cref="CodeGenConfig"/> being loaded.</param> public void LoadBeforeChildren(CodeGenConfig config) { if (config == null) { throw new ArgumentNullException(nameof(config)); } if (_tables == null) { LoadDatabase(config.Root.GetAttributeValue <string>("ConnectionString") ?? throw new CodeGenException("Config.ConnectionString has not been specified."), config.Root.GetAttributeValue <string>("RefDatabaseSchema")); } var name = config.GetAttributeValue <string>("Name") ?? throw new CodeGenException("Table has no Name attribute specified."); config.AttributeAdd("Schema", "dbo"); var schema = config.GetAttributeValue <string>("Schema"); var table = _tables.Where(x => x.Name == name && x.Schema == schema).SingleOrDefault(); if (table == null) { throw new CodeGenException($"Specified Schema.Table '{schema}.{name}' not found in database."); } config.AttributeAdd("Alias", table.Alias); config.AttributeAdd("IsAView", XmlConvert.ToString(table.IsAView)); }
/// <summary> /// Loads the <see cref="CodeGenConfig"/> before the corresponding <see cref="CodeGenConfig.Children"/>. /// </summary> /// <param name="config">The <see cref="CodeGenConfig"/> being loaded.</param> public Task LoadBeforeChildrenAsync(CodeGenConfig config) { if (config == null) { throw new ArgumentNullException(nameof(config)); } if (!config.Attributes.ContainsKey("Name")) { throw new CodeGenException("Entity element must have a Name property."); } config.AttributeAdd("Text", CodeGenerator.ToSentenceCase(config.Attributes["Name"])); config.AttributeAdd("PrivateName", CodeGenerator.ToPrivateCase(config.Attributes["Name"])); config.AttributeAdd("ArgumentName", CodeGenerator.ToCamelCase(config.Attributes["Name"])); config.AttributeUpdate("Text", config.Attributes["Text"]); if (config.Attributes.ContainsKey("RefDataType")) { config.AttributeAdd("ConstType", config.Attributes["RefDataType"]); } config.AttributeAdd("Namespace", config.Root.GetAttributeValue <string>("Namespace")); config.AttributeAdd("FileName", config.Attributes["Name"]); config.AttributeAdd("EntityScope", "Common"); return(Task.CompletedTask); }
/// <summary> /// Generate and customize API code based on Mustache template /// </summary> /// <param name="config">Configuration values to customize API Code</param> /// <param name="webApiProjectStructure">API Structure and dependencies</param> public static async Task CustomizeAPICode(CodeGenConfig config, WebApiProjectStructure webApiProjectStructure) { //Generate Startup.cs file await GenerateStartupCode(config, webApiProjectStructure); //Generate Docker file await GenerateDockerfileCode(config, webApiProjectStructure); //Generate Deployment Manifest File await GenerateDeploymentManifestCode(config); //Generate Pipeline code await GeneratePipelineCode(config); //Generate Jenkins file await GenerateJenkinsfileCode(config); //Generate UpdateAssembly file await GenerateUpdateAssemblyCode(config); //Generate AppSettings file await GenerateAppSettings(config, webApiProjectStructure); await GenerateGitIgnoreCode(config); }
public void OnExecute() { if (string.IsNullOrEmpty(ConfigFile)) { PackageName = PackageName ?? Prompt.GetString("What is the name of the project?", null, ConsoleColor.Cyan); SwaggerFile = SwaggerFile ?? Prompt.GetString("Enter the Path/URL of Swagger file", null, ConsoleColor.Cyan); UseCircuitbreaker = UseCircuitbreaker ?? Prompt.GetYesNo("Include Circute Breaker?", false, ConsoleColor.Cyan); UseMessaging = UseMessaging ?? Prompt.GetYesNo("Include Messaging?", false, ConsoleColor.Cyan); UseCaching = UseCaching ?? Prompt.GetYesNo("Include Caching?", false, ConsoleColor.Cyan); var config = new CodeGenConfig { PackageName = this.PackageName, SwaggerFile = this.SwaggerFile, ExecutableJarFilePath = this.ExecutableJarFilePath, TemplateDirectoryPath = this.TemplateDirectoryPath, ConfigForSwaggerCodeGenFilePath = this.ConfigForSwaggerCodeGenFilePath, UseCircuitbreaker = this.UseCircuitbreaker, UseMessaging = this.UseMessaging, Database = EnumDatabase.MongoDB, Messaging = new List <string> { "kafka" }, UseCaching = this.UseCaching, outputFolderPath = this.OutPutFolder//@"D:\E-Comm\Modernization\CodeGeneratorAPI\CodeGeneratorAPI\Output" //this.OutPutFolder }; WebApiProjectCodeGen codeGen = new WebApiProjectCodeGen(); var result = codeGen.GenerateProjectCode(config).GetAwaiter().GetResult(); } }
/// <summary> /// Loads the <see cref="CodeGenConfig"/> before the corresponding <see cref="CodeGenConfig.Children"/>. /// </summary> /// <param name="config">The <see cref="CodeGenConfig"/> being loaded.</param> public void LoadBeforeChildren(CodeGenConfig config) { CodeGenConfig entity = CodeGenConfig.FindConfig(config, "Entity"); if (config.GetAttributeValue <bool>("UniqueKey")) { List <CodeGenConfig> paramList = new List <CodeGenConfig>(); var layerPassing = new string[] { "Create", "Update" }.Contains(config.GetAttributeValue <string>("OperationType")) ? "ToManagerSet" : "All"; var isMandatory = new string[] { "Create", "Update" }.Contains(config.GetAttributeValue <string>("OperationType")) ? "false" : "true"; var propConfigs = CodeGenConfig.FindConfigList(config, "Property") ?? new List <CodeGenConfig>(); foreach (CodeGenConfig propConfig in propConfigs) { if (!propConfig.GetAttributeValue <bool>("UniqueKey")) { continue; } CodeGenConfig p = new CodeGenConfig("Parameter", config); p.AttributeAdd("Name", propConfig.GetAttributeValue <string>("Name")); p.AttributeAdd("LayerPassing", layerPassing); p.AttributeAdd("IsMandatory", isMandatory); ParameterConfigLoader.UpdateConfigFromProperty(p, propConfig.GetAttributeValue <string>("Name")); paramList.Add(p); } if (paramList.Count > 0) { config.Children.Add("Parameter", paramList); } } config.AttributeAdd("OperationType", "Get"); config.AttributeAdd("ReturnType", "void"); if (config.Attributes.ContainsKey("ReturnType")) { config.AttributeAdd("ReturnText", string.Format("A resultant {{{{{0}}}}}.", config.Attributes["ReturnType"])); } else { config.AttributeAdd("ReturnText", string.Format("A resultant {{{{{0}}}}}.", entity.Attributes["Name"])); } config.AttributeUpdate("ReturnText", config.Attributes["ReturnText"]); if (config.Attributes.ContainsKey("OperationType") && config.Attributes["OperationType"] == "Custom") { config.AttributeAdd("Text", CodeGenerator.ToSentenceCase(config.Attributes["Name"])); } if (config.Attributes.ContainsKey("Text")) { config.AttributeUpdate("Text", config.Attributes["Text"]); } config.AttributeAdd("PrivateName", CodeGenerator.ToPrivateCase(config.Attributes["Name"])); config.AttributeAdd("ArgumentName", CodeGenerator.ToCamelCase(config.Attributes["Name"])); config.AttributeAdd("QualifiedName", entity.Attributes["Name"] + config.Attributes["Name"]); }
public async Task <bool> GenerateProjectCode(CodeGenConfig config) { bool isCreated = true; string webApiFolderStructureJson = Directory.GetCurrentDirectory() + "\\" + WEBAPI_Project_Structure_JSON; //@"D:\E-Comm\Modernization\poc-codegenerator\src\IMP4CMACGM.Generation.WebApi\WebApiProjectStructure.json"; string rawJson = File.ReadAllText(webApiFolderStructureJson); var webApiProjectStructure = JsonConvert.DeserializeObject <WebApiProjectStructure>(rawJson); //Generate Web API Project using Swagger CodeGendsad WebApiServerCodegen aspNetCoreCodeGen = new WebApiServerCodegen(); await aspNetCoreCodeGen.GenerateServerCode(webApiProjectStructure.RootWebAPIProjectNameSuffix, config); //Generate WebAPI Sub Projects using DOTNET Cli var webApiProjectCodeGeneration = new WebApiSubProjectCodeGeneration(); await webApiProjectCodeGeneration.GenerateSubProjectProjectCode(config, webApiProjectStructure); //Generate WebAPI Test Projects using DOTNET Cli var apiTestProjectCodeGeneration = new WebApiTestProjectCodeGeneration(); await apiTestProjectCodeGeneration.GenerateTestProjectCode(config, webApiProjectStructure); //Add Project Reference for API project await aspNetCoreCodeGen.AddProjectReferenceForWebApiProjects(config, webApiProjectStructure); //Add Packages for Web API await aspNetCoreCodeGen.AddPackagesForWebApiProjects(config, webApiProjectStructure); //Generate and customize API code based on Mustache Template await MustacheCodeGeneration.CustomizeAPICode(config, webApiProjectStructure); return(isCreated); }
/// <summary> /// Loads the <see cref="CodeGenConfig"/> before the corresponding <see cref="CodeGenConfig.Children"/>. /// </summary> /// <param name="config">The <see cref="CodeGenConfig"/> being loaded.</param> public async Task LoadBeforeChildrenAsync(CodeGenConfig config) { if (config == null) { throw new ArgumentNullException(nameof(config)); } if (_tables == null) { await LoadDatabaseAsync(config.Root.GetAttributeValue <string>("ConnectionString") ?? throw new CodeGenException("Config.ConnectionString has not been specified."), config.Root.GetAttributeValue <string>("RefDatabaseSchema")).ConfigureAwait(false); } if (!config.Attributes.ContainsKey("Name")) { throw new CodeGenException("Table element must have a Name property."); } var name = config.GetAttributeValue <string>("Name") !; config.AttributeAdd("Schema", "dbo"); var schema = config.GetAttributeValue <string>("Schema"); var table = _tables.Where(x => x.Name == name && x.Schema == schema).SingleOrDefault(); if (table == null) { throw new CodeGenException($"Specified Schema.Table '{schema}.{name}' not found in database."); } config.AttributeAdd("Alias", table.Alias); config.AttributeAdd("IsAView", XmlConvert.ToString(table.IsAView)); }
public static string GenerateCommandForSwaggerCodeGen(CodeGenConfig config) { string command = string.Empty; if (!string.IsNullOrEmpty(config.ExecutableJarFilePath)) { command += "-jar " + config.ExecutableJarFilePath; } command += " generate"; if (!string.IsNullOrEmpty(config.SwaggerFile)) { command += " -i " + config.SwaggerFile; } if (!string.IsNullOrEmpty(config.TemplateDirectoryPath)) { command += " -t " + config.TemplateDirectoryPath; } command += " -l aspnet5"; if (!string.IsNullOrEmpty(config.ConfigForSwaggerCodeGenFilePath)) { command += " -c " + config.ConfigForSwaggerCodeGenFilePath; } if (!string.IsNullOrEmpty(config.OutPutFolder)) { command += " -o " + config.OutPutFolder; } return(command); }
/// <summary> /// Loads the <see cref="CodeGenConfig"/> before the corresponding <see cref="CodeGenConfig.Children"/>. /// </summary> /// <param name="config">The <see cref="CodeGenConfig"/> being loaded.</param> public Task LoadBeforeChildrenAsync(CodeGenConfig config) { if (config == null) { throw new ArgumentNullException(nameof(config)); } if (!config.Attributes.ContainsKey("Name")) { throw new CodeGenException("Parameter element must have a Name property."); } if (config.Attributes.ContainsKey("Property")) { UpdateConfigFromProperty(config, config.Attributes["Property"] !); } config.AttributeAdd("PrivateName", StringConversion.ToPrivateCase(config.Attributes["Name"])); config.AttributeAdd("ArgumentName", StringConversion.ToCamelCase(config.Attributes["Name"])); config.AttributeAdd("Type", "string"); config.AttributeAdd("LayerPassing", "All"); if (config.GetAttributeValue <string>("RefDataType") != null) { config.AttributeAdd("Text", string.Format(System.Globalization.CultureInfo.InvariantCulture, "{1} (see {{{{{0}}}}})", config.Attributes["Type"], StringConversion.ToSentenceCase(config.Attributes["Name"]))); } else if (CodeGenConfig.SystemTypes.Contains(config.Attributes["Type"] !)) { config.AttributeAdd("Text", StringConversion.ToSentenceCase(config.Attributes["Name"])); }
/// <summary> /// Update the <see cref="CodeGenConfig"/> from a named <b>Property</b>. /// </summary> /// <param name="config">The <see cref="CodeGenConfig"/> to update.</param> /// <param name="propertyName">The <b>Property</b> name.</param> public static void UpdateConfigFromProperty(CodeGenConfig config, string propertyName) { if (config == null) { throw new ArgumentNullException(nameof(config)); } List <CodeGenConfig> propConfig = CodeGenConfig.FindConfigList(config, "Property"); if (propConfig == null) { throw new CodeGenException($"Attribute value references Property '{propertyName}' that does not exist for Entity."); } CodeGenConfig itemConfig = null; foreach (CodeGenConfig p in propConfig) { if (p.Attributes["Name"] == propertyName) { itemConfig = p; } } if (itemConfig == null) { throw new CodeGenException($"Attribute value references Property '{propertyName}' that does not exist for Entity."); } config.AttributeAdd("ArgumentName", CodeGenerator.ToCamelCase(config.Attributes["Name"])); config.AttributeAdd("Text", itemConfig.Attributes["Text"]); config.AttributeAdd("Type", itemConfig.Attributes["Type"]); config.AttributeAdd("LayerPassing", "All"); if (itemConfig.Attributes.ContainsKey("Nullable")) { config.AttributeAdd("Nullable", itemConfig.Attributes["Nullable"]); } if (itemConfig.Attributes.ContainsKey("RefDataType")) { config.AttributeAdd("RefDataType", itemConfig.Attributes["RefDataType"]); } if (itemConfig.Attributes.ContainsKey("DataConverter")) { config.AttributeAdd("DataConverter", itemConfig.Attributes["DataConverter"]); } if (itemConfig.Attributes.ContainsKey("IsDataConverterGeneric")) { config.AttributeAdd("IsDataConverterGeneric", itemConfig.Attributes["IsDataConverterGeneric"]); } if (itemConfig.Attributes.ContainsKey("UniqueKey")) { config.AttributeAdd("UniqueKey", itemConfig.Attributes["UniqueKey"]); } }
/// <summary> /// Applies the Operation Loader. /// </summary> private CodeGenConfig ApplyOperationLoader(CodeGenConfig config) { var opl = new OperationConfigLoader(); opl.LoadBeforeChildren(config); opl.LoadAfterChildren(config); return(config); }
/// <summary> /// Applies the Operation Loader. /// </summary> private static async Task <CodeGenConfig> ApplyOperationLoaderAsync(CodeGenConfig config) { var opl = new OperationConfigLoader() as ICodeGenConfigLoader; await opl.LoadBeforeChildrenAsync(config).ConfigureAwait(false); await opl.LoadAfterChildrenAsync(config).ConfigureAwait(false); return(config); }
private static async Task GenerateJenkinsfileCode(CodeGenConfig config) { string fileName = "Jenkinsfile"; string jenkinsFilePath = config.outputFolderPath + "\\" + fileName; dynamic jenkinsfileConfig = new JObject(); jenkinsfileConfig.packageName = config.PackageName; await MustacheParser.GenerateCodeFile(fileName, jenkinsFilePath, jenkinsfileConfig); }
public async Task <IActionResult> CreateWebAPI([FromBody] WebAPI webApi) { if (webApi != null) { //var outputFolderPath = _hostingEnvironment.ContentRootPath + "\\" + webApi.projectName + localDateTime +"\\"; var outputFolderPath = @"D:\work\poc\CodeGenOutput" + "\\" + webApi.projectName + localDateTime + "\\"; while (!Directory.Exists(outputFolderPath)) { Directory.CreateDirectory(outputFolderPath); } if (webApi.saveToGit) { gitOperations = new GitOperations(webApi.gitUsername, webApi.gitPassword, webApi.gitURL, outputFolderPath); gitOperations.CloneRepo(); gitbranchName = gitbranchName + webApi.projectName; } var config = new CodeGenConfig() { Messaging = webApi.messaging, UseCircuitbreaker = webApi.useCircuitBreaker, PackageName = webApi.projectName, namespaceName = webApi.namespaceName, SwaggerFile = webApi.swaggerPath, outputFolderPath = outputFolderPath }; WebApiProjectCodeGen webApiProjectCodeGen = new WebApiProjectCodeGen(); await webApiProjectCodeGen.GenerateProjectCode(config); if (webApi.saveToGit) { if (!string.IsNullOrEmpty(webApi.gitUsername) && !string.IsNullOrEmpty(webApi.gitPassword) && !string.IsNullOrEmpty(webApi.gitURL)) { var branches = gitOperations.ListGitBranches(gitbranchName); if (!branches) { gitOperations.CreateBranch(gitbranchName, gitbranchName); gitOperations.PushCommits(gitbranchName, gitbranchName); return(Ok(new CreateResponse() { Result = "Project Created. Pushed to Git." })); } } } } return(Ok(new CreateResponse() { Result = "Project Created. TODO: Download zip file." })); }
private static async Task GenerateUpdateAssemblyCode(CodeGenConfig config) { string fileName = "UpdateAssembly"; string fileExtension = "ps1"; string updateAssemblyFilePath = config.outputFolderPath + "\\" + fileName + "." + fileExtension; dynamic updateAssemblyConfig = new JObject(); updateAssemblyConfig.packageName = config.PackageName; await MustacheParser.GenerateCodeFile(fileName, updateAssemblyFilePath, updateAssemblyConfig); }
private static async Task GenerateGitIgnoreCode(CodeGenConfig config) { string fileName = ""; string fileExtension = "gitignore"; string updateAssemblyFilePath = config.outputFolderPath + "\\" + fileName + "." + fileExtension; dynamic updateGitIgnore = new JObject(); updateGitIgnore.packageName = config.PackageName; await MustacheParser.GenerateCodeFile("gitignore", updateAssemblyFilePath, updateGitIgnore); }
private static async Task GeneratePipelineCode(CodeGenConfig config) { string fileName = "pipeline"; string fileExtension = "yml"; string pipelineFilePath = config.outputFolderPath + "\\" + fileName + "." + fileExtension; dynamic pipelineConfig = new JObject(); pipelineConfig.packageName = config.PackageName; await MustacheParser.GenerateCodeFile(fileName, pipelineFilePath, pipelineConfig); }
readonly ClientApiTsFunctionGenAbstract apiFunctionGen; //to be injected in ctor of derived class. /// <summary> /// /// </summary> /// <param name="jsOutput"></param> /// <param name="apiFunctionGen"></param> /// <remarks>The client data types should better be generated through SvcUtil.exe with the DC option. The client namespace will then be the original namespace plus suffix ".client". </remarks> protected ControllersTsClientApiGenBase(JSOutput jsOutput, ClientApiTsFunctionGenAbstract apiFunctionGen) { this.jsOutput = jsOutput ?? throw new ArgumentNullException("jsOutput"); this.apiFunctionGen = apiFunctionGen; this.apiSelections = jsOutput.ApiSelections; TargetUnit = new CodeCompileUnit(); poco2TsGen = CreatePoco2TsGen(); TsCodeGenerationOptions options = TsCodeGenerationOptions.Instance; options.BracingStyle = "JS"; options.IndentString = "\t"; options.CamelCase = jsOutput.CamelCase ?? false; }
private static async Task GenerateDockerfileCode(CodeGenConfig config, WebApiProjectStructure webApiProjectStructure) { string fileName = "Dockerfile"; string dockerFilePath = config.outputFolderPath + "\\src\\" + config.PackageName + "." + webApiProjectStructure.RootWebAPIProjectNameSuffix + "\\" + fileName; dynamic dockerConfig = new JObject(); dockerConfig.packageName = config.PackageName + "." + webApiProjectStructure.RootWebAPIProjectNameSuffix; dockerConfig.donotcoreVersion = webApiProjectStructure.DotnetCoreVersion; await MustacheParser.GenerateCodeFile(fileName, dockerFilePath, dockerConfig); }
/// <summary> /// Loads the <see cref="CodeGenConfig"/> before the corresponding <see cref="CodeGenConfig.Children"/>. /// </summary> /// <param name="config">The <see cref="CodeGenConfig"/> being loaded.</param> public void LoadBeforeChildren(CodeGenConfig config) { config.AttributeAdd("Text", CodeGenerator.ToSentenceCase(config.Attributes["Name"])); config.AttributeAdd("PrivateName", CodeGenerator.ToPrivateCase(config.Attributes["Name"])); config.AttributeAdd("ArgumentName", CodeGenerator.ToCamelCase(config.Attributes["Name"])); config.AttributeUpdate("Text", config.Attributes["Text"]); if (config.Attributes.ContainsKey("RefDataType")) { config.AttributeAdd("ConstType", config.Attributes["RefDataType"]); } config.AttributeAdd("Namespace", config.Root.GetAttributeValue <string>("Namespace")); config.AttributeAdd("FileName", config.Attributes["Name"]); config.AttributeAdd("EntityScope", "Common"); }
private static async Task GenerateDeploymentManifestCode(CodeGenConfig config) { string fileName = "deployit-manifest"; string fileExtension = "xml"; string deploymentManifestFilePath = config.outputFolderPath + "\\" + fileName + "." + fileExtension; dynamic deploymentManifestConfig = new JObject(); deploymentManifestConfig.packageName = config.PackageName; deploymentManifestConfig.packageNameLowerCase = config.PackageName.ToLower(); deploymentManifestConfig.websiteName = "{{NET_ECOMMERCE-API-" + config.PackageName.ToUpper() + "_WEBSITE_NAME}}"; deploymentManifestConfig.websitePhysicalPath = "{{NET_ECOMMERCE-API-" + config.PackageName.ToUpper() + "_WEBSITE_PHYSICALPATH}}"; await MustacheParser.GenerateCodeFile(fileName, deploymentManifestFilePath, deploymentManifestConfig); }
private static async Task GenerateStartupCode(CodeGenConfig config, WebApiProjectStructure webApiProjectStructure) { string csprojAPIPath = config.outputFolderPath + "\\src\\" + config.PackageName + "." + webApiProjectStructure.RootWebAPIProjectNameSuffix + "\\" + config.PackageName + "." + webApiProjectStructure.RootWebAPIProjectNameSuffix + ".csproj"; string fileName = "Startup"; string fileExtension = "cs"; string startupFilePath = config.outputFolderPath + "\\src\\" + config.PackageName + "." + webApiProjectStructure.RootWebAPIProjectNameSuffix + "\\" + fileName + "." + fileExtension; dynamic startupConfig = new JObject(); if (config.UseCircuitbreaker == true) { startupConfig.isPolly = true; //Add Polly Package to Web API Project await CodeGenerationCoreOperations.AddPackageToProject(csprojAPIPath, webApiProjectStructure.PollyWebApiPackage.PackageName, webApiProjectStructure.PollyWebApiPackage.Version); } if (config.UseLogging == true) { startupConfig.isSteeltoe = true; //Add Steeltoe Package to Web API Project await CodeGenerationCoreOperations.AddPackageToProject(csprojAPIPath, webApiProjectStructure.SteeltoeWebApiPackage.PackageName, webApiProjectStructure.SteeltoeWebApiPackage.Version); } if (config.Database == EnumDatabase.MongoDB) { startupConfig.isMongo = true; startupConfig.mongoConnectionName = config.PackageName + "MongoConnectionString"; //Add Mongo Package await CodeGenerationCoreOperations.AddPackageToProject(csprojAPIPath, webApiProjectStructure.MongoDBDriver.PackageName, webApiProjectStructure.MongoDBDriver.Version); await CodeGenerationCoreOperations.AddPackageToProject(csprojAPIPath, webApiProjectStructure.MongoDBDriverCore.PackageName, webApiProjectStructure.MongoDBDriverCore.Version); await CodeGenerationCoreOperations.AddPackageToProject(csprojAPIPath, webApiProjectStructure.MongoBSON.PackageName, webApiProjectStructure.MongoBSON.Version); await CodeGenerationCoreOperations.AddPackageToProject(csprojAPIPath, webApiProjectStructure.MongoHealthCheck.PackageName, webApiProjectStructure.MongoHealthCheck.Version); } startupConfig.packageName = config.PackageName; startupConfig.apiTitle = config.PackageName + " " + webApiProjectStructure.RootWebAPIProjectNameSuffix; startupConfig.apiVersion = webApiProjectStructure.ApiVersion; await MustacheParser.GenerateCodeFile(fileName, startupFilePath, startupConfig); }
public async Task UpdateConfig(CodeGenConfig codeGenConfig) { codeGenConfig.Models.List = codeGenConfig.Models.List.OrderBy(x => x.Name).ToList(); await _fileService.Create( "code-gen-config.json", JsonConvert.SerializeObject( new { CodeGenConfig = codeGenConfig }, Formatting.Indented, new JsonSerializerSettings { DefaultValueHandling = DefaultValueHandling.Ignore } ) ); }
ClientApiTsFunctionGenBase apiFunctionGen; //to be injected in ctor of derived class. /// <summary> /// /// </summary> /// <param name="excludedControllerNames">Excluse some Api Controllers from being exposed to the client API. Each item should be fully qualified class name but without the assembly name.</param> /// <remarks>The client data types should better be generated through SvcUtil.exe with the DC option. The client namespace will then be the original namespace plus suffix ".client". </remarks> protected ControllersTsClientApiGenBase(JSOutput jsOutput, ClientApiTsFunctionGenBase apiFunctionGen) { if (jsOutput == null) { throw new ArgumentNullException("jsOutput"); } this.jsOutput = jsOutput; this.apiFunctionGen = apiFunctionGen; this.apiSelections = jsOutput.ApiSelections; TargetUnit = new CodeCompileUnit(); poco2TsGen = new Poco2TsGen(TargetUnit); TsCodeGenerationOptions options = TsCodeGenerationOptions.Instance; options.BracingStyle = "JS"; options.IndentString = " "; options.CamelCase = jsOutput.CamelCase.HasValue ? jsOutput.CamelCase.Value : false; }
public async Task AddProjectReferenceForWebApiProjects(CodeGenConfig config, WebApiProjectStructure webApiProjectStructure) { //Add Project Reference for API project string csprojAPIPath = config.outputFolderPath + "\\src\\" + config.PackageName + "." + webApiProjectStructure.RootWebAPIProjectNameSuffix + "\\" + config.PackageName + "." + webApiProjectStructure.RootWebAPIProjectNameSuffix + ".csproj"; var csprojAPITestPath = config.outputFolderPath + "\\" + webApiProjectStructure.TestProject.RootTestDirectory + "\\" + config.PackageName + "." + webApiProjectStructure.RootWebAPIProjectNameSuffix + "." + webApiProjectStructure.TestProject.TestProjectNameSuffix + "\\" + config.PackageName + "." + webApiProjectStructure.RootWebAPIProjectNameSuffix + "." + webApiProjectStructure.TestProject.TestProjectNameSuffix + ".csproj"; while (!File.Exists(csprojAPITestPath)) { } //Add API Project reference to API Test Project await CodeGenerationCoreOperations.AddProjectReference(csprojAPITestPath, csprojAPIPath); foreach (var subProject in webApiProjectStructure.SubProjects) { string csprojSubProjectPath = config.outputFolderPath + "\\src\\" + config.PackageName + "." + subProject.SubProjectPath + "\\" + config.PackageName + "." + subProject.SubProjectName + ".csproj"; while (!File.Exists(csprojSubProjectPath)) { } //Add subProjectReference to main API project await CodeGenerationCoreOperations.AddProjectReference(csprojAPIPath, csprojSubProjectPath); while (!File.Exists(csprojAPITestPath)) { } //Add subProjectReference to API Test project await CodeGenerationCoreOperations.AddProjectReference(csprojAPITestPath, csprojSubProjectPath); //Add project reference for all depedencies if (subProject.ProjectDependencies != null && subProject.ProjectDependencies.Count > 0) { foreach (var project in subProject.ProjectDependencies) { var csprojDepedentProject = config.outputFolderPath + "\\src\\" + config.PackageName + "." + project + "\\" + config.PackageName + "." + project + ".csproj"; //Add depedent project reference await CodeGenerationCoreOperations.AddProjectReference(csprojSubProjectPath, csprojDepedentProject); } } } }