Пример #1
0
        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);
        }
Пример #2
0
        public async Task AddPackagesForWebApiProjects(CodeGenConfig config, WebApiProjectStructure webApiProjectStructure)
        {
            //Add Project Reference for API project
            var    outPutCodePath    = config.outputFolderPath; //@"D:\E-Comm\Modernization\CodeGeneratorAPI\CodeGeneratorAPI\Output";//config.outputFolderPath;
            string csprojAPIPath     = outPutCodePath + "\\src\\" + config.PackageName + "." + webApiProjectStructure.RootWebAPIProjectNameSuffix + "\\" + config.PackageName + "." + webApiProjectStructure.RootWebAPIProjectNameSuffix + ".csproj";
            var    csprojAPITestPath = outPutCodePath + "\\" + webApiProjectStructure.TestProject.RootTestDirectory + "\\" + config.PackageName + "." + webApiProjectStructure.RootWebAPIProjectNameSuffix + "." + webApiProjectStructure.TestProject.TestProjectNameSuffix + "\\" + config.PackageName + "." + webApiProjectStructure.RootWebAPIProjectNameSuffix + "." + webApiProjectStructure.TestProject.TestProjectNameSuffix + ".csproj";

            string fileContent = File.ReadAllText(csprojAPIPath);

            if (fileContent.Contains("netcoreapp2.2"))
            {
                fileContent = fileContent.Replace("netcoreapp2.2", "netcoreapp3.1");
                var replaceValue = @"<PackageReference Include=""Microsoft.AspNetCore.App"" />"; //To DO
                fileContent = fileContent.Replace(replaceValue, "");
            }

            await File.WriteAllTextAsync(csprojAPIPath, fileContent);

            //Delete Unwanted Files from Root Folder
            var deleteBuildBatFile = outPutCodePath + "\\" + "build.bat";
            var deleteBuildshFile  = outPutCodePath + "\\" + "build.sh";

            if (File.Exists(deleteBuildBatFile))
            {
                File.Delete(deleteBuildBatFile);
            }

            if (File.Exists(deleteBuildshFile))
            {
                File.Delete(deleteBuildshFile);
            }

            //Delete Filter Files
            var           filterFolderPath = outPutCodePath + "\\src\\" + config.PackageName + "." + webApiProjectStructure.RootWebAPIProjectNameSuffix + "\\" + "Filters";
            DirectoryInfo filterDir        = new DirectoryInfo(filterFolderPath);

            foreach (FileInfo file in filterDir.GetFiles())
            {
                file.Delete();
            }

            while (!File.Exists(csprojAPIPath))
            {
            }

            //Add package to Web API Project
            foreach (var package in webApiProjectStructure.WebApiPackages)
            {
                await CodeGenerationCoreOperations.AddPackageToProject(csprojAPIPath, package.PackageName, package.Version);
            }

            //Add package to Web API Sub Projects
            foreach (var subProject in webApiProjectStructure.SubProjects)
            {
                string csprojSubProjectPath = outPutCodePath + "\\src\\" + config.PackageName + "." + subProject.SubProjectPath + "\\" + config.PackageName + "." + subProject.SubProjectName + ".csproj";

                while (!File.Exists(csprojSubProjectPath))
                {
                }

                foreach (var package in subProject.ProjectPackages)
                {
                    await CodeGenerationCoreOperations.AddPackageToProject(csprojSubProjectPath, package.PackageName, package.Version);
                }
            }

            while (!File.Exists(csprojAPITestPath))
            {
            }
            //Add package to Web API Test Project
            foreach (var package in webApiProjectStructure.TestProject.ProjectPackages)
            {
                await CodeGenerationCoreOperations.AddPackageToProject(csprojAPITestPath, package.PackageName, package.Version);
            }
        }