Exemplo n.º 1
0
        public KDataStoreProject BuildDatabaseProject(KickstartWizardModel kickstartWizardModel, KProtoFile kProtoFile)
        {
            KDataStoreProject databaseProject = new KDataStoreProject {
                CompanyName = kickstartWizardModel.CompanyName, ProjectName = kickstartWizardModel.ProjectName, KickstartCRUDStoredProcedures = false, Kickstart = kickstartWizardModel.CreateDatabaseProject
            };

            databaseProject.GenerateStoredProcAsEmbeddedQuery = kickstartWizardModel.GenerateStoredProcAsEmbeddedQuery;
            databaseProject.ConvertToSnakeCase = kickstartWizardModel.ConvertToSnakeCase;
            databaseProject.DataStoreType      = kickstartWizardModel.DatabaseType;


            if (kickstartWizardModel.MetadataSource == MetadataSource.Grpc && !kickstartWizardModel.HasSql())
            {
                databaseProject.InferSqlFromProto(kProtoFile);
            }
            else if (kickstartWizardModel.MetadataSource == MetadataSource.SqlScripts || kickstartWizardModel.HasSql())
            {
                databaseProject.SqlTableText           = kickstartWizardModel.SqlTableText;
                databaseProject.SqlTableTypeText       = kickstartWizardModel.SqlTableTypeText;
                databaseProject.SqlStoredProcedureText = kickstartWizardModel.SqlStoredProcText;
            }


            return(databaseProject);
        }
Exemplo n.º 2
0
        public MenuPresenter(KickstartWizardModel kickstartWizardModel, IMenuView menuView)
        {
            _kickstartWizardModel = kickstartWizardModel;
            _menuView             = menuView;

            _menuView.MetadataSourceSelectionChanged += _menuView_MetadataSourceSelectionChanged;
            _menuView.DatabaseTypeChanged            += _menuView_DatabaseTypeChanged;

            _menuView.CreateDatabaseProjectChanged += _menuView_CreateDatabaseProjectChanged;
            _menuView.CreateDataAccessLayerChanged += _menuView_CreateDataAccessLayerChanged;
            _menuView.CreateGrpcServiceChanged     += _menuView_CreateGrpcProjectChanged;
            _menuView.CreateGrpcServiceTestClientProjectChanged += (a, b) =>
            {
                _kickstartWizardModel.CreateGrpcServiceTestClientProject = _menuView.CreateGrpcServiceTestClientProject;
                return(Task.CompletedTask);
            };

            _menuView.CreateGrpcUnitTestProjectChanged += (a, b) =>
            {
                _kickstartWizardModel.CreateGrpcUnitTestProject = _menuView.CreateGrpcUnitTestProject;
                return(Task.CompletedTask);
            };

            _menuView.CreateIntegrationTestProjectChanged += (a, b) =>
            {
                _kickstartWizardModel.CreateIntegrationTestProject = _menuView.CreateIntegrationTestProject;
                return(Task.CompletedTask);
            };

            _menuView.CreateWebAppProjectChanged += (a, b) =>
            {
                _kickstartWizardModel.CreateWebAppProject = _menuView.CreateWebAppProject;
                return(Task.CompletedTask);
            };
        }
Exemplo n.º 3
0
        public void IsThereSmoke2()
        {
            //Arrange
            var kickstartWizard = new KickstartWizardModel()
            {
                ProjectDirectory = @"c:\temp\",
                SolutionName     = "SmokeTest2",
                ProjectName      = "SmokeTest2"
            };

            //kickstartWizard.GenerateAsync = true;
            IServiceCollection serviceCollection = new ServiceCollection();

            serviceCollection.AddTransient <IKickstartService, KickstartService>();
            serviceCollection.AddTransient <IKickstartWizardService, KickstartWizardService>();

            var serviceProvider = serviceCollection.BuildServiceProvider();

            var kickstartService       = serviceProvider.GetRequiredService <IKickstartService>();
            var kickstartWizardService = serviceProvider.GetRequiredService <IKickstartWizardService>();
            var messageBoxMock         = new Mock <IMessageBoxDisplayService>();
            //messageBoxMock.Setup(x => x.Show(It.IsAny<string>())).Verifiable();

            var menuMock      = new MockMenuView();
            var menuPresenter = new MenuPresenter(kickstartWizard, menuMock);

            menuMock.MetadataSourceSelection = MetadataSource.Grpc;
            menuMock.DatabaseType            = DataStoreTypes.SqlServer;

            var projectViewMock        = new Mock <IProjectView>();
            var kickstartWizardMock    = new MockKickstartWizardView();// new Mock<IKickstartWizardView>();
            var protoFileView          = new Mock <MockProtoFileView>();
            var databaseSqlView        = new Mock <IDatabaseSqlView>();
            var generationView         = new Mock <IGenerationView>();
            var protoToKProtoConverter = new Mock <IProtoToKProtoConverter>();

            var presenter = new KickstartWizardPresenter(kickstartWizard, kickstartService, kickstartWizardService, messageBoxMock.Object, kickstartWizardMock, menuMock,
                                                         projectViewMock.Object, protoFileView.Object, databaseSqlView.Object, generationView.Object, protoToKProtoConverter.Object);

            //Act

            menuMock.MetadataSourceSelectionChanged(null, null);
            menuMock.DatabaseTypeChanged(null, null);
            menuMock.CreateDataAccessLayerChanged(null, null);
            menuMock.CreateDatabaseProjectChanged(null, null);
            menuMock.CreateGrpcServiceChanged(null, null);
            menuMock.CreateGrpcServiceTestClientProjectChanged(null, null);
            menuMock.CreateGrpcUnitTestProjectChanged(null, null);
            menuMock.CreateIntegrationTestProjectChanged(null, null);

            kickstartWizardMock.NextClicked(null, null).Wait();
            protoFileView.Object.ProtoTextChanged(null, null);
            kickstartWizardMock.NextClicked(null, null).Wait();
            kickstartWizardMock.NextClicked(null, null).Wait();

            //Assert
        }
Exemplo n.º 4
0
        public KDataStoreTestProject BuildDatabaseTestProject(KickstartWizardModel kickstartWizardModel, KProtoFile kProtoFile)
        {
            var databaseProject = new KDataStoreTestProject {
                CompanyName = kickstartWizardModel.CompanyName, ProjectName = kickstartWizardModel.ProjectName,
                Kickstart   = kickstartWizardModel.CreateDatabaseTestProject
            };

            databaseProject.DataStoreType = kickstartWizardModel.DatabaseType;

            return(databaseProject);
        }
Exemplo n.º 5
0
        public MegaSolutionWizardPresenter(KickstartWizardModel kickstartWizard, IKickstartService kickstartService, IKickstartWizardService kickstartWizardService, IMessageBoxDisplayService messageBoxDisplayService, IKickstartWizardView kickstartWizardView, IMenuView menuView, IProjectView projectView, IProtoFileView protoFileView, IDatabaseSqlView databaseSqlView, IGenerationView generationView, IProtoToKProtoConverter protoToKProtoConverter)
        {
            _kickstartService         = kickstartService;
            _kickstartWizardService   = kickstartWizardService;
            _messageBoxDisplayService = messageBoxDisplayService;
            _kickstartWizardView      = kickstartWizardView;
            _menuView               = menuView;
            _protoFileView          = protoFileView;
            _databaseSqlView        = databaseSqlView;
            _generationView         = generationView;
            _projectView            = projectView;
            _protoToKProtoConverter = protoToKProtoConverter;

            kickstartWizardView.Load += KickstartWizardViewLoad;

            kickstartWizardView.NextClicked  += KickstartWizardViewNextClicked;
            kickstartWizardView.PreviousStep += KickstartWizardViewPreviousStep;
            protoFileView.ProtoTextChanged   += ProtoFileViewProtoTextChanged;
            databaseSqlView.GenerateStoredProcAsEmbeddedQueryChanged += (a, b) =>
            {
                _kickstartWizardModel.GenerateStoredProcAsEmbeddedQuery = _databaseSqlView.GenerateStoredProcAsEmbeddedQuery;
                return(Task.CompletedTask);
            };

            databaseSqlView.SqlStoredProcTextChanged += (a, b) =>
            {
                _kickstartWizardModel.SqlStoredProcText = _databaseSqlView.SqlStoredProcText;
                return(Task.CompletedTask);
            };

            databaseSqlView.SqlTableTextChanged += (a, b) =>
            {
                _kickstartWizardModel.SqlTableText = _databaseSqlView.SqlTableText;
                return(Task.CompletedTask);
            };

            databaseSqlView.SqlTableTypeTextChanged += (a, b) =>
            {
                _kickstartWizardModel.SqlTableTypeText = _databaseSqlView.SqlTableTypeText;
                return(Task.CompletedTask);
            };

            _kickstartWizardModel = kickstartWizard;

            kickstartWizardView.AddView(menuView);
            kickstartWizardView.AddView(protoFileView);
            kickstartWizardView.AddView(databaseSqlView);
            kickstartWizardView.AddView(generationView);

            //where should this go in MVP ?
            _projectView.SolutionName = _kickstartWizardModel.SolutionName;
            _projectView.CompanyName  = _kickstartWizardModel.CompanyName;
            _projectView.ProjectName  = _kickstartWizardModel.ProjectName;
        }
Exemplo n.º 6
0
        private KGrpcProject BuildGrpcProject(KickstartWizardModel kickstartWizardModel, KDataStoreProject databaseProject, KDataLayerProject dataLayerProject, KProtoFile kProtoFile)
        {
            var grpcProject = new KGrpcProject()
            {
                CompanyName = kickstartWizardModel.CompanyName, ProjectName = kickstartWizardModel.ProjectName, Kickstart = kickstartWizardModel.CreateGrpcServiceProject
            };

            if (kProtoFile != null)
            {
                grpcProject.ProtoFile.Add(kProtoFile);
            }
            grpcProject.DependsOnProject.Add(databaseProject);
            grpcProject.DependsOnProject.Add(dataLayerProject);
            return(grpcProject);
        }
Exemplo n.º 7
0
 private string InferSolutionName(KickstartWizardModel kickstartWizardModel)
 {
     if (kickstartWizardModel.MetadataSource == MetadataSource.Grpc)
     {
         var grpcProject = kickstartWizardModel.SelectedTemplateSolutions.First().Project.FirstOrDefault(p => p is KGrpcProject) as KGrpcProject;
         return(InferSolutionName(grpcProject.ProtoFile.FirstOrDefault()));
     }
     else if (kickstartWizardModel.MetadataSource == MetadataSource.SqlScripts)
     {
         var databaseProject = kickstartWizardModel.SelectedTemplateSolutions.First().Project.FirstOrDefault(p => p is KDataStoreProject) as KDataStoreProject;
         return(databaseProject.InferProjectName());
     }
     else
     {
         throw new NotImplementedException();
     }
 }
Exemplo n.º 8
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.º 9
0
        public void RunStarted(object automationObject, Dictionary <string, string> replacementsDictionary, WizardRunKind runKind, object[] customParams)
        {
            var resultOfPrompt = MessageBox.Show("Use winforms?", "", MessageBoxButtons.YesNo);

            AppDomain currentDomain = AppDomain.CurrentDomain;

            currentDomain.AssemblyResolve += CurrentDomainOnAssemblyResolve;


            _dte = (DTE)automationObject;

            _projectDirectory = replacementsDictionary["$destinationdirectory$"];

            var serviceCollection = new ServiceCollection();

            serviceCollection.AddLogging();
            //var logger = new LoggerConfiguration()
            //    .CreateLogger();

            var configuration = new ConfigurationBuilder()
                                .AddJsonFile(Path.Combine(AssemblyDirectory, "appsettings.json"), false)
                                .Build();

            serviceCollection.AddSingleton(configuration);

            //serviceCollection.AddSingleton(typeof(ILogger<>), typeof(Logger<>));

            //serviceCollection.AddSingleton(typeof(Serilog.ILogger), logger);
            var serviceProvider = serviceCollection.ConfigureContainer();

            var loggerFactory = serviceProvider.GetService <ILoggerFactory>();

            ConfigureLogger(loggerFactory);

            var prereqChecker = serviceProvider.GetService <IPrereqChecker>();

            if (!prereqChecker.CheckGrpcNugets())
            {
                MessageBox.Show("Grpc tools (Nugets) have not been installed");
                throw new WizardBackoutException();
            }

            _kickstartWizardPresenter = serviceProvider.GetRequiredService <IKickstartWizardPresenter>();
            var kickstartService = serviceProvider.GetRequiredService <IKickstartService>();


            //List<KSolutionGroup> unfiliteredSolutionGroupList = service.GetSolutionGroupListFromCode(); ;
            //pass1
            //read metadata from code/sql/proto files into K objects
            //unfiliteredSolutionGroupList = service.GetSolutionGroupListFromExcel();
            var kickstartWizard = new KickstartWizardModel()
            {
                SolutionName = replacementsDictionary["$specifiedsolutionname$"],
                CompanyName  = "Company",
                ProjectName  = replacementsDictionary["$specifiedsolutionname$"],
                // _dialog.AvailableTemplateSolutions = unfiliteredSolutionGroupList.SelectMany(g => g.Solution).ToList();

                ProjectDirectory = _projectDirectory
            };

            if (resultOfPrompt == DialogResult.Yes)
            {
                _dialog = new KickstartWizardDialog();
            }
            else
            {
                _dialog = new KickstartWizardDialogWeb();
            }

            var menuView = new MenuStep();

            menuView.Tag = new MenuPresenter(kickstartWizard, menuView);

            /*   _kickstartWizardPresenter = new KickstartWizardPresenter(kickstartWizard, kickstartService,
             *     new KickstartWizardService( new ProtoToKProtoConverter(configuration), new SProtoFileToProtoFileConverter(), new KDataLayerProjectToKProtoFileConverter(), new DbToKSolutionConverter(new SqlServerTableTypeReader(), new SqlServerTableReader(), new SqlServerTableToCTableConverter(), new SqlServerViewReader(), new SqlServerViewToCViewConverter()), new DataLayerServiceFactory(null)),
             *     new MessageBoxDisplayService(), _dialog, menuView, _dialog.ProjectView, new ProtoFileStep(), new DatabaseSqlStep(), new GenerationStep(), new ProtoToKProtoConverter(configuration) );
             */
            _dialog.Tag = _kickstartWizardPresenter;
            var exclusiveProject = Boolean.Parse(replacementsDictionary["$exclusiveproject$"]);
            var parentWindow     = System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle; // Control.FromHandle(new IntPtr(_dte.ActiveWindow.HWnd));
            var result           = (DialogResult)_dialog.ShowDialog(parentWindow);

            if (result == DialogResult.Cancel)
            {
                throw new WizardBackoutException();
            }

            replacementsDictionary["$specifiedsolutionname$"] = kickstartWizard.SolutionName;

            if (exclusiveProject)
            {
                if (kickstartWizard.SelectedTemplateSolutions.Count > 1 || kickstartWizard.SelectedTemplateSolutions.Count > 1)
                {
                    //open the root "master" solution
                    var solutionName = $"{kickstartWizard.SolutionName}.sln";

                    var fullSolutionPath = Path.Combine(kickstartWizard.ProjectDirectory, solutionName);

                    _dte.Solution.Open(fullSolutionPath);
                }
                else
                {
                    _dte.Solution.Open(kickstartWizard.SelectedTemplateSolutions.First().GeneratedSolution.SolutionPath);
                }
            }
            else
            {
                foreach (var solution2 in kickstartWizard.SelectedTemplateSolutions)
                {
                    foreach (var project in solution2.GeneratedSolution.Project)
                    {
                        try
                        {
                            _dte.Solution.AddFromFile(project.Path);
                        }
                        catch
                        {
                        }
                    }
                }
            }

            throw new WizardCancelledException();
        }
Exemplo n.º 10
0
        public override async Task <KickstartSolutionResponse> KickstartSolution(KickstartSolutionRequest request, ServerCallContext context)
        {
            var workDir = GetTemporaryDirectory();
            var model   = new KickstartWizardModel
            {
                ProjectDirectory           = workDir,
                MetadataSource             = MetadataSource.Grpc,
                ConvertToSnakeCase         = request.ConvertToSnakeCase,
                CreateDataLayerProject     = request.GenerateDataLayerProject,
                CreateDatabaseProject      = request.GenerateDatabaseProject,
                CreateGrpcServiceProject   = request.GenerateGrpcServiceProject,
                CreateGrpcUnitTestProject  = request.GenerateGrpcUnitTestProject,
                CreateGrpcClientProject    = request.GenerateGrpcClientProject,
                CreateWebAppProject        = request.GenerateWebAppProject,
                CreateDockerComposeProject = request.GenerateDockerComposeProject,
                CompanyName   = request.CompanyName,
                SolutionName  = request.SolutionName,
                ProjectName   = request.ProjectName,
                DatabaseType  = (Utility.DataStoreTypes)request.DatabaseType,
                ProtoFileText = request.ProtoFileText,
                GenerateStoredProcAsEmbeddedQuery = true
            };

            try
            {
                var result = await _executor.ExecuteAsync(new BuildSolutionQuery
                {
                    KickstartModel = model
                }).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                var response = new KickstartSolutionResponse
                {
                    Succeeded    = false,
                    ErrorMessage = ex.Message
                };
                return(response);
            }
            var tempZip = Path.GetTempFileName();

            File.Delete(tempZip);
            System.IO.Compression.ZipFile.CreateFromDirectory(workDir, tempZip);

            using (MemoryStream memoryStream = new MemoryStream())
            {
                using (FileStream file = new FileStream(tempZip, FileMode.Open, FileAccess.Read))
                    file.CopyTo(memoryStream);

                File.Delete(tempZip);
                ClearFolder(workDir);
                Directory.Delete(workDir);
                var response = new KickstartSolutionResponse
                {
                    Succeeded            = true,
                    GeneratedFilesBase64 = Convert.ToBase64String(memoryStream.ToArray())
                };

                return(response);
            }
        }
Exemplo n.º 11
0
        public KSolution BuildSolution(KickstartWizardModel kickstartWizardModel)
        {
            var solution = new KSolution()
            {
                CompanyName = kickstartWizardModel.CompanyName, SolutionName = kickstartWizardModel.SolutionName
            };

            KProtoFile kProtoFile = null;

            if (kickstartWizardModel.MetadataSource == MetadataSource.Grpc)
            {
                kProtoFile = kickstartWizardModel.MetadataSource == MetadataSource.Grpc ? _protoToKProtoConverter.Convert("zzz", kickstartWizardModel.ProtoFileText) : null;

                //this will override whatever user typed on first standard VS dialog
                if (kickstartWizardModel.CurrentStep == KickstartWizardModel.Step.ProtoFile)
                {
                    kickstartWizardModel.SolutionName = InferSolutionName(kProtoFile);
                    kickstartWizardModel.ProjectName  = InferProjectName(kProtoFile);
                }
                else
                {
                }

                var databaseProject = BuildDatabaseProject(kickstartWizardModel, kProtoFile);
                solution.Project.Add(databaseProject);

                var databaseTestProject = BuildDatabaseTestProject(kickstartWizardModel, kProtoFile);
                solution.Project.Add(databaseTestProject);

                //_databaseSqlView.Bind(databaseProject);

                //if (_currentStep == Step.GenerationStart)
                {
                    var dataLayerProject = BuildDataLayerProject(kickstartWizardModel, databaseProject);
                    var grpcProject      = BuildGrpcProject(kickstartWizardModel, databaseProject, dataLayerProject, kProtoFile);
                    solution.Project.Add(grpcProject);

                    solution.Project.Add(dataLayerProject);
                }
            }
            else if (kickstartWizardModel.MetadataSource == MetadataSource.SqlScripts)
            {
                var databaseProjectStart = BuildDatabaseProject(kickstartWizardModel, null);

                var connectionString = "Server=localhost;";
                var outputRootPath   = string.Empty;

                var databaseProject = _dbToKSolutionConverter.BuildSqlMeta(connectionString, outputRootPath, databaseProjectStart);

                var dataLayerProject = BuildDataLayerProject(kickstartWizardModel, databaseProject);

                solution.Project.Add(databaseProject);
                solution.Project.Add(dataLayerProject);

                var grpcProject = BuildGrpcProject(kickstartWizardModel, databaseProject, dataLayerProject, null);
                grpcProject.CompanyName = kickstartWizardModel.CompanyName;
                solution.Project.Add(grpcProject);

                var protoFiles = _dataLayerProjectToKProtoFileConverter.Convert(databaseProject, dataLayerProject, grpcProject);
                foreach (var pf in protoFiles)
                {
                    grpcProject.ProtoFile.Add(pf);
                }
                //_databaseSqlStep.Bind(databaseProject);

                var pf3 = protoFiles.FirstOrDefault();
                if (pf3 != null)
                {
                    pf3.ProtoFileText = _protoFileToProtoFileConverter.Convert(pf3.GeneratedProtoFile);
                    // _protoFileView.Bind(pf3);
                }
            }


            if (kickstartWizardModel.CreateGrpcServiceTestClientProject)
            {
                solution.Project.Add(new KGrpcServiceClientTestProject {
                    ProjectName = kickstartWizardModel.ProjectName
                });
            }
            if (kickstartWizardModel.CreateDockerBuildProject)
            {
                solution.Project.Add(new KDockerBuildScriptProject {
                    ProjectName = kickstartWizardModel.ProjectName
                });
            }
            if (kickstartWizardModel.CreateGrpcUnitTestProject)
            {
                solution.Project.Add(new KGrpcServiceUnitTestProject {
                    ProjectName = kickstartWizardModel.ProjectName
                });
            }
            if (kickstartWizardModel.CreateIntegrationTestProject)
            {
                solution.Project.Add(new KGrpcServiceIntegrationTestProject {
                    ProjectName = kickstartWizardModel.ProjectName
                });
            }

            if (kickstartWizardModel.CreateWebAppProject)
            {
                solution.Project.Add(new KWebUIProject {
                    ProjectName = kickstartWizardModel.ProjectName
                });
            }

            if (kickstartWizardModel.CreateDockerComposeProject)
            {
                solution.Project.Add(new KDockerComposeProject()
                {
                    ProjectName = kickstartWizardModel.ProjectName
                });
            }

            if (kickstartWizardModel.CreateGrpcClientProject)
            {
                solution.Project.Add(new KGrpcClientProject()
                {
                    ProjectName = kickstartWizardModel.ProjectName
                });
            }
            return(solution);
        }