コード例 #1
0
        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();
            }
        }
コード例 #2
0
        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."
            }));
        }