/// <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);
                }
            }
        }
예제 #2
0
        /// <summary>
        /// To generate DOTNET CLI Command based on the command inputs
        /// </summary>
        /// <param name="config">Class for CLI command Inputs</param>
        /// <returns></returns>
        public static string GenerateCommandForDotNetCoreProjectCreation(DotNetCoreCommandOptions config)
        {
            string command = " new ";

            if (!string.IsNullOrEmpty(config.ProjectType))
            {
                command += config.ProjectType;
            }

            if (!string.IsNullOrEmpty(config.ProjectName))
            {
                command += " -n " + config.ProjectName;
            }

            if (!string.IsNullOrEmpty(config.OutPutLocation))
            {
                command += " -o " + config.OutPutLocation;
            }

            return(command);
        }
        public async Task GenerateTestProjectCode(CodeGenConfig config, WebApiProjectStructure webApiProjectStructure)
        {
            string apiSolutionPath = config.outputFolderPath + "\\" + config.PackageName + "." + webApiProjectStructure.RootWebAPIProjectNameSuffix + ".sln";

            DirectoryInfo rootTestDirectory = new DirectoryInfo(config.outputFolderPath);

            string[] folders = System.IO.Directory.GetDirectories(config.outputFolderPath);

            if (folders != null && folders.Length > 0)
            {
                if (Directory.Exists(config.outputFolderPath))
                {
                    rootTestDirectory = Directory.CreateDirectory(config.outputFolderPath + "\\" + webApiProjectStructure.TestProject.RootTestDirectory);
                }

                var apiTestProjectDirectory = rootTestDirectory + "\\" + config.PackageName + "." + webApiProjectStructure.RootWebAPIProjectNameSuffix + "." + webApiProjectStructure.TestProject.TestProjectNameSuffix;

                if (Directory.Exists(rootTestDirectory.FullName))
                {
                    Directory.CreateDirectory(apiTestProjectDirectory);
                }

                var codeGenerationOptions = new DotNetCoreCommandOptions();
                codeGenerationOptions.ProjectName    = config.PackageName + "." + webApiProjectStructure.RootWebAPIProjectNameSuffix + "." + webApiProjectStructure.TestProject.TestProjectNameSuffix;
                codeGenerationOptions.ProjectType    = webApiProjectStructure.TestProject.TestProjectType;
                codeGenerationOptions.OutPutLocation = apiTestProjectDirectory;

                await CodeGenerationCoreOperations.CreateNewDotNetCoreProject(codeGenerationOptions);

                var csprojFilePath = codeGenerationOptions.OutPutLocation + "\\" + codeGenerationOptions.ProjectName + ".csproj";
                while (!File.Exists(csprojFilePath))
                {
                    // Console.WriteLine("Not Present" + csprojFilePath);
                }
                await CodeGenerationCoreOperations.AddProjectToSoluion(apiSolutionPath, csprojFilePath);
            }
        }
예제 #4
0
 public static async Task <ProcessResult> CreateNewDotNetCoreProject(DotNetCoreCommandOptions config)
 {
     return(await ProcessAsyncHelper.RunProcessAsync("dotnet",
                                                     CodeGenerationCoreOperations.GenerateCommandForDotNetCoreProjectCreation(config),
                                                     30000).ConfigureAwait(false));
 }