Exemplo n.º 1
0
        private KDataLayerProject BuildDataLayerProject(KickstartWizardModel kickstartWizardModel, KDataStoreProject databaseProject)
        {
            var dataLayerProject = new KDataLayerProject(kickstartWizardModel.DatabaseType)
            {
                CompanyName = kickstartWizardModel.CompanyName, ProjectName = kickstartWizardModel.ProjectName, KickstartBulkStore = false, Kickstart = kickstartWizardModel.CreateDataLayerProject
            };


            var allStoredProcedures = new List <CStoredProcedure>();
            var dataProject         = _dataLayerServiceFactory.Create(databaseProject.DataStoreType).BuildProject(databaseProject, dataLayerProject, allStoredProcedures,
                                                                                                                  databaseProject?.Table, databaseProject?.TableType, databaseProject?.View);

            if (databaseProject != null)
            {
                dataLayerProject.DependsOnProject.Add(databaseProject);
            }

            return(dataLayerProject);
        }
Exemplo n.º 2
0
        public void Convert(KSolution kSolution)
        {
            var solution = new CSolution {
                SolutionName = $"{kSolution.CompanyName}.{kSolution.SolutionName}"
            };
            var integrationTestSolution = new CSolution
            {
                SolutionName = $"{kSolution.CompanyName}.{kSolution.SolutionName}.IntegrationTests"
            };
            bool generatedSomething = true;

            while (generatedSomething)
            {
                generatedSomething = false;
                foreach (var kProject in kSolution.Project)
                {
                    _logger.LogInformation("Generating projects for KProject: {project}", kProject.ProjectName);
                    bool dependenciesAllGenerated = !kProject.DependsOnProject.Any(p => p.GeneratedProject == null);
                    if (dependenciesAllGenerated)
                    {
                        if (kProject.GeneratedProject != null)
                        {
                            continue;
                        }
                        if (kProject is KWebUIProject)
                        {
                            var webAppProject = kProject as KWebUIProject;
                            var webAppService =
                                new WebAppProjectService {
                            };

                            var webAppCProject = webAppService.BuildProject(webAppProject);

                            kProject.GeneratedProject = webAppCProject;
                            if (webAppProject.Kickstart)
                            {
                                solution.Project.Add(webAppCProject);
                            }
                        }

                        if (kProject is KDockerComposeProject)
                        {
                            var dockerComposeKProject = kProject as KDockerComposeProject;

                            var dockerComposeProjectService = new DockerComposeProjectService();

                            var dockerComposeCProject = dockerComposeProjectService.BuildProject(kSolution, dockerComposeKProject);

                            kProject.GeneratedProject = dockerComposeCProject;
                            if (dockerComposeCProject.Kickstart)
                            {
                                solution.Project.Add(dockerComposeCProject);
                            }
                        }

                        if (kProject is KGrpcClientProject)
                        {
                            var kGrpcClientProject = kProject as KGrpcClientProject;

                            var grpcClientProjectService = new GrpcClientProjectService();

                            var grpcClientCProject = grpcClientProjectService.BuildProject(kSolution, kGrpcClientProject);

                            kProject.GeneratedProject = grpcClientCProject;
                            if (grpcClientCProject.Kickstart)
                            {
                                solution.Project.Add(grpcClientCProject);
                            }
                        }



                        if (kProject is KDataStoreProject)
                        {
                            var      dataStoreKProject = kProject as KDataStoreProject;
                            CProject dataStoreProject  = BuildDataStoreProject(kSolution, dataStoreKProject);
                            if (dataStoreProject != null)
                            {
                                kProject.GeneratedProject = dataStoreProject;
                                if (dataStoreKProject.Kickstart && dataStoreProject.Kickstart)
                                {
                                    solution.Project.Add(dataStoreProject);
                                }
                                _logger.LogInformation("Generated data store project {project}", dataStoreProject.ProjectName);
                                generatedSomething = true;
                            }
                            else
                            {
                                kProject.GeneratedProject = new CNullProject();
                                _logger.LogInformation("Kipped data store project {project}", kProject.ProjectName);
                                generatedSomething = true; //tell a white lie
                            }
                        }
                        else if (kProject is KDataLayerProject)
                        {
                            CProject dataProject         = null;
                            var      sqlKProject         = kProject.DependsOnProject.FirstOrDefault(k => k is KDataStoreProject) as KDataStoreProject;
                            var      sqlProject          = sqlKProject?.GeneratedProject;
                            var      allStoredProcedures = new List <CStoredProcedure>();
                            if (sqlProject != null)
                            {
                                foreach (var pc in sqlProject.ProjectContent)
                                {
                                    if (pc.Content is CStoredProcedure)
                                    {
                                        allStoredProcedures.Add(pc.Content as CStoredProcedure);
                                    }
                                }
                            }


                            var dataLayerKProject = kProject as KDataLayerProject;

                            dataProject = _dataLayerServiceFactory.Create(dataLayerKProject.ConnectsToDatabaseType).BuildProject(sqlKProject, dataLayerKProject, allStoredProcedures,
                                                                                                                                 sqlKProject?.Table, sqlKProject?.TableType, sqlKProject?.View);
                            kProject.GeneratedProject = dataProject;
                            if (dataLayerKProject.Kickstart)
                            {
                                solution.Project.Add(dataProject);
                            }

                            generatedSomething = true;

                            foreach (var dbTest in kSolution.Project
                                     .OfType <KDataStoreTestProject>())
                            {
                                var dataStoreProject      = sqlKProject.GeneratedProject;
                                var kDataStoreTestProject = dbTest as KDataStoreTestProject;
                                var service = _dataStoreTestServiceFactory.Create(kDataStoreTestProject.DataStoreType);
                                if (service != null)
                                {
                                    var dbProviderInterface = dataProject.Interface.First(i =>
                                                                                          i.InheritsFrom?.InterfaceName == "IDbProvider");
                                    var dbProviderClass = dataProject.Class.First(c =>
                                                                                  c.Implements.Exists(i => i.InterfaceName == dbProviderInterface.InterfaceName));

                                    if (kDataStoreTestProject.Kickstart && kDataStoreTestProject.Kickstart)
                                    {
                                        solution.Project.Add(service.BuildProject(kSolution, sqlKProject,
                                                                                  kDataStoreTestProject, dataLayerKProject, dataStoreProject,
                                                                                  dbProviderInterface, dbProviderClass));
                                    }
                                    // kDataStoreTestProject, dataStoreProject));
                                }
                            }
                        }
                        else if (kProject is KGrpcIntegrationProject)
                        {
                            var sqlKProject = kProject.DependsOnProject.FirstOrDefault(k => k is KDataStoreProject) as KDataStoreProject;

                            var dataLayerKProject = kProject.DependsOnProject.FirstOrDefault(k => k is KDataLayerProject) as KDataLayerProject;

                            var kGrpcProject = kProject.DependsOnProject.FirstOrDefault(k => k is KGrpcProject) as KGrpcProject;

                            if (sqlKProject != null && dataLayerKProject != null)
                            {
                                var sqlProject       = sqlKProject.GeneratedProject;
                                var dataLayerProject = dataLayerKProject.GeneratedProject;

                                var grpcIntegrationProject = BuildGrpcProject(kSolution, sqlKProject, dataLayerKProject, kGrpcProject,
                                                                              solution, sqlProject, dataLayerProject);
                                kProject.GeneratedProject = grpcIntegrationProject;
                                solution.Project.Add(grpcIntegrationProject);
                            }
                            else
                            {
                                var grpcKIntegrationProject = kProject as KGrpcIntegrationProject;

                                var grpcIntegrationProject = _grpcIntegrationServiceProjectService.BuildProject(kSolution,
                                                                                                                grpcKIntegrationProject, grpcKIntegrationProject.ProtoRef);
                                kProject.GeneratedProject = grpcIntegrationProject;
                                solution.Project.Add(grpcIntegrationProject);
                            }


                            generatedSomething = true;
                        }
                        else if (kProject is KGrpcProject)
                        {
                            var sqlKProject = kProject.DependsOnProject.FirstOrDefault(k => k is KDataStoreProject) as KDataStoreProject;
                            var sqlProject  = sqlKProject?.GeneratedProject;

                            var dataLayerKProject = kProject.DependsOnProject.FirstOrDefault(k => k is KDataLayerProject) as KDataLayerProject;
                            var dataLayerProject  = dataLayerKProject?.GeneratedProject;

                            var kGrpcProject = kProject as KGrpcProject;//.DependsOnProject.First(k => k is KGrpcProject) as KGrpcProject;

                            var grpcProject = BuildGrpcProject(kSolution, sqlKProject, dataLayerKProject, kGrpcProject,
                                                               solution, sqlProject, dataLayerProject);
                            kProject.GeneratedProject = grpcProject;
                            if (kGrpcProject.Kickstart)
                            {
                                solution.Project.Add(grpcProject);
                            }

                            foreach (var grpcUnitTestProject in kSolution.Project.OfType <KGrpcServiceUnitTestProject>())
                            {
                                solution.Project.Add(_grpcServiceUnitTestProjectService.BuildProject(kGrpcProject,
                                                                                                     grpcUnitTestProject, grpcProject));
                            }

                            foreach (var grpcClientTestProject in kSolution.Project
                                     .OfType <KGrpcServiceClientTestProject>())
                            {
                                solution.Project.Add(_grpcServiceClientTestProjectService.BuildProject(kSolution, kGrpcProject,
                                                                                                       grpcClientTestProject, grpcProject));
                            }
                            foreach (var grpcIntegrationBusinessTestProject in kSolution.Project
                                     .OfType <KGrpcIntegrationBusinessTestProject>())
                            {
                                var grpcIntegrationTestBusinessProject =
                                    _grpcServiceIntegrationBusinessTestProjectService.BuildProject(
                                        grpcIntegrationBusinessTestProject, grpcProject, kGrpcProject.ProtoFile, false);
                                integrationTestSolution.Project.Add(grpcIntegrationTestBusinessProject);

                                foreach (var grpcIntegrationTestProject in kSolution.Project
                                         .OfType <KGrpcServiceIntegrationTestProject>())
                                {
                                    integrationTestSolution.Project.Add(
                                        _grpcServiceIntegrationTestProjectService.BuildProject(kGrpcProject,
                                                                                               grpcIntegrationTestProject, grpcIntegrationTestBusinessProject, false));
                                }
                            }
                            generatedSomething = true;
                        }
                    }
                }
            }

            foreach (var mDockerBuildScriptProject in kSolution.Project
                     .OfType <KDockerBuildScriptProject>())
            {
                solution.Project.Add(_buildScriptService.Execute(kSolution.SolutionName, mDockerBuildScriptProject));
            }

            solution.Project.Add(_solutionFileService.BuildSolutionFilesProject(kSolution));


            kSolution.GeneratedSolution     = solution;
            kSolution.GeneratedTestSolution = integrationTestSolution;

            int x = 1;
        }