예제 #1
0
        public void GenerateRepositoryDependencies()
        {
            var repositoryFile     = System.IO.Path.Combine(this.RepositoryComponentsDirectory, "Repository.cs");
            var repositoryTemplate = new RepositoryTemplate();

            repositoryTemplate.Namespace = this.Namespace;
            var content = repositoryTemplate.TransformText();

            System.IO.File.WriteAllText(repositoryFile, content);
        }
예제 #2
0
        public void Repository_Template_Test()
        {
            var template = new RepositoryTemplate(new SmartAppInfo {
                Id = ApplicationId
            });
            var output = template.TransformText();

            Assert.NotNull(output);
            Assert.NotEmpty(output);
            Assert.Contains($"namespace {ApplicationId}.Backend", output);
            Assert.Contains("public class Repository<T> : IRepository<T>", output);
        }
예제 #3
0
        public void GenerateDataServiceProject(DomainDataService dataService, string outputFolder)
        {
            outputFolder = Path.Combine(outputFolder, $"{dataService.Solution.NamespacePrefix}.{dataService.Name}.DataService");
            var interfacesFolder  = Path.Combine(outputFolder, "Interfaces");
            var mappingsFolder    = Path.Combine(outputFolder, "Mappings");
            var recordTypesFolder = Path.Combine(outputFolder, "RecordTypes");
            var validatorsFolder  = Path.Combine(outputFolder, "Validators");

            ReplaceDirectories(interfacesFolder, mappingsFolder, recordTypesFolder, validatorsFolder);

            var session = new Dictionary <string, object>();

            session.Add("DomainDataService", dataService);

            DataServiceProjectTemplate projectTemplate = new DataServiceProjectTemplate();

            projectTemplate.Session = session;
            projectTemplate.Initialize();
            string content = projectTemplate.TransformText();

            File.WriteAllText(Path.Combine(outputFolder, $"{dataService.Solution.NamespacePrefix}.{dataService.Name}.DataService.csproj"), content);

            IRepositoryTemplate repositoryInterfaceTemplate = new IRepositoryTemplate();

            repositoryInterfaceTemplate.Session = session;
            repositoryInterfaceTemplate.Initialize();
            content = repositoryInterfaceTemplate.TransformText();
            File.WriteAllText(Path.Combine(interfacesFolder, $"I{dataService.Name}DataServiceRespository.cs"), content);

            IDataServiceTemplate dataServiceInterfaceTemplate = new IDataServiceTemplate();

            dataServiceInterfaceTemplate.Session = session;
            dataServiceInterfaceTemplate.Initialize();
            content = dataServiceInterfaceTemplate.TransformText();
            File.WriteAllText(Path.Combine(interfacesFolder, $"I{dataService.Name}DataService.cs"), content);

            RepositoryTemplate repositoryTemplate = new RepositoryTemplate();

            repositoryTemplate.Session = session;
            repositoryTemplate.Initialize();
            content = repositoryTemplate.TransformText();
            File.WriteAllText(Path.Combine(outputFolder, $"{dataService.Name}DataServiceRespository.cs"), content);

            DataServiceTemplate dataServiceTemplate = new DataServiceTemplate();

            dataServiceTemplate.Session = session;
            dataServiceTemplate.Initialize();
            content = dataServiceTemplate.TransformText();
            File.WriteAllText(Path.Combine(outputFolder, $"{dataService.Name}DataService.cs"), content);

            KernelManipulationsTemplate kernelManipulationsTemplate = new KernelManipulationsTemplate();

            kernelManipulationsTemplate.Session = session;
            kernelManipulationsTemplate.Initialize();
            content = kernelManipulationsTemplate.TransformText();
            File.WriteAllText(Path.Combine(outputFolder, $"{dataService.Name}KernelManipulations.cs"), content);

            StartupTaskTemplate startupTaskTemplate = new StartupTaskTemplate();

            startupTaskTemplate.Session = session;
            startupTaskTemplate.Initialize();
            content = startupTaskTemplate.TransformText();
            File.WriteAllText(Path.Combine(outputFolder, $"{dataService.Name}Startup.cs"), content);

            if (!(dataService.Schemas is null))
            {
                foreach (var domainObject in dataService.Schemas.SelectMany(s => s.Objects))
                {
                    session["CurrentObject"] = domainObject;

                    MappingTemplate mappingTemplate = new MappingTemplate();
                    mappingTemplate.Session = session;
                    mappingTemplate.Initialize();
                    content = mappingTemplate.TransformText();
                    File.WriteAllText(Path.Combine(mappingsFolder, $"{domainObject.ObjectName}Mapping.cs"), content);

                    RecordTypeTemplate recordTypeTemplate = new RecordTypeTemplate();
                    recordTypeTemplate.Session = session;
                    recordTypeTemplate.Initialize();
                    content = recordTypeTemplate.TransformText();
                    File.WriteAllText(Path.Combine(recordTypesFolder, $"{domainObject.ObjectName}RecordType.cs"), content);

                    if (domainObject.SupportsIHaveId())
                    {
                        var modelValidatorsFolder = Path.Combine(validatorsFolder, domainObject.ObjectName);
                        ReplaceDirectories(modelValidatorsFolder);

                        ValidatorTemplate validatorTemplate = new ValidatorTemplate();
                        validatorTemplate.Session = session;
                        validatorTemplate.Initialize();
                        content = validatorTemplate.TransformText();
                        File.WriteAllText(Path.Combine(modelValidatorsFolder, $"{domainObject.ObjectName}Validator.cs"), content);

                        DeleteValidatorTemplate deleteValidatorTemplate = new DeleteValidatorTemplate();
                        deleteValidatorTemplate.Session = session;
                        deleteValidatorTemplate.Initialize();
                        content = deleteValidatorTemplate.TransformText();
                        File.WriteAllText(Path.Combine(modelValidatorsFolder, $"{domainObject.ObjectName}DeleteValidator.cs"), content);

                        BatchValidatorTemplate batchValidatorTemplate = new BatchValidatorTemplate();
                        batchValidatorTemplate.Session = session;
                        batchValidatorTemplate.Initialize();
                        content = batchValidatorTemplate.TransformText();
                        File.WriteAllText(Path.Combine(modelValidatorsFolder, $"{domainObject.ObjectName}BatchValidator.cs"), content);
                    }
                }
            }
        }
        public void ProjectFinishedGenerating(Project project)
        {
            DTE dte = project.DTE;

            var solItems = dte.Solution.Projects.Cast <Project>().FirstOrDefault(p => p.Name == "Solution Items" || p.Kind == EnvDTE.Constants.vsProjectItemKindSolutionItems);

            if (solItems == null)
            {
                Solution2 sol2 = (Solution2)dte.Solution;
                solItems = sol2.AddSolutionFolder("Solution Items");
                string solDir = Path.GetDirectoryName(sol2.FullName);

                if (outputRepoFile)
                {
                    RepositoryTemplate repositoryTemplate = new RepositoryTemplate {
                        Session = templateParameters
                    };
                    repositoryTemplate.Initialize();
                    string repositoryTemplateContent = repositoryTemplate.TransformText();
                    string repositoryFilePath        = $"{solDir}\\repository.json";
                    File.WriteAllText(repositoryFilePath, repositoryTemplateContent);
                    solItems.ProjectItems.AddFromFile(repositoryFilePath);
                }

                ConfigTemplate configTemplate = new ConfigTemplate {
                    Session = templateParameters
                };
                configTemplate.Initialize();
                string configTemplateContent = configTemplate.TransformText();
                string configFilePath        = $"{solDir}\\config.json";
                File.WriteAllText(configFilePath, configTemplateContent);
                solItems.ProjectItems.AddFromFile(configFilePath);

                string runtimePath = Directory.GetCurrentDirectory();
                solItems.ProjectItems.AddFromFileCopy(runtimePath + "\\.gitignore");
                solItems.ProjectItems.AddFromFileCopy(runtimePath + "\\pre_build.ps1");
                solItems.ProjectItems.AddFromFileCopy(runtimePath + "\\post_build.ps1");
                solItems.ProjectItems.AddFromFileCopy(runtimePath + "\\launch_game.ps1");

                // pre-copy references
                Directory.CreateDirectory($"{solDir}\\references");
                string referencesGitIgnorePath = $"{solDir}\\references\\.gitignore";
                File.WriteAllText(referencesGitIgnorePath, "*\n!.gitignore");

                string pre_build = $@"{solDir.Replace(@"\", @"\\")}\\pre_build.ps1";

                string argument = $@"-ExecutionPolicy Unrestricted -File ""{pre_build}"" -SolutionDir ""{solDir.Replace(@"\", @"\\")}\\""";
                if ((bool)templateParameters["UseModMenu"])
                {
                    argument += @" -ModAssemblyReferences ""blendermf.XLShredMenu\\XLShredLib.dll""";
                }
                var process = new System.Diagnostics.Process {
                    StartInfo = new System.Diagnostics.ProcessStartInfo {
                        FileName               = "powershell",
                        Arguments              = argument,
                        UseShellExecute        = false,
                        RedirectStandardOutput = false,
                        CreateNoWindow         = true
                    }
                };

                process.Start();
                process.WaitForExit();
            }
            else
            {
                var repo = solItems.ProjectItems.Cast <ProjectItem>().FirstOrDefault(p => p.Name == "repository.json");
            }

            (project.Object as VSProject)?.Refresh();

            foreach (Configuration config in project.ConfigurationManager)
            {
                config.Properties.Item("StartAction").Value           = 1; // Launch external program
                config.Properties.Item("StartProgram").Value          = @"C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe";
                config.Properties.Item("StartArguments").Value        = @"-ExecutionPolicy Unrestricted -File ""./launch_game.ps1""";
                config.Properties.Item("StartWorkingDirectory").Value = @"../../../";
            }

            project.Save(project.FileName);
        }
예제 #5
0
        public void Repository_Template_NullParameter_Test()
        {
            var template = new RepositoryTemplate(null);

            Assert.Throws <NullReferenceException>(() => template.TransformText());
        }
예제 #6
0
        private void TransformDataRepositoryTemplate(SmartAppInfo manifest)
        {
            var template = new RepositoryTemplate(manifest);

            _writingService.WriteFile(Path.Combine(_context.BasePath, template.OutputPath), template.TransformText());
        }
예제 #7
0
        static void Main(string[] args)
        {
            string dir  = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location).Replace("\\bin\\Debug", "").Replace("\\bin", "");
            string path = Path.Combine(dir, "data.xml");

            string dataProjectDir   = dir.Replace(".T4", ".Data");
            string webProjectDir    = dir.Replace(".T4", ".Admin");
            string clientProjectDir = dir.Replace(".T4", "");

            DatabaseInfo databaseInfo = new DatabaseInfo();

            var serializer = new XmlSerializer(databaseInfo.GetType());

            using (StreamReader reader = new StreamReader(path))
            {
                databaseInfo = (DatabaseInfo)serializer.Deserialize(reader);
            }

            foreach (ModelInfo model in databaseInfo.Models)
            {
                //preparing FK collection names
                model.CollectionModel = databaseInfo.Models.Where(m => m.Fields.Any(f => f.FkSingular == model.Singular)).ToList();

                //angular project

                //AngularControllerTemplate acTemplate = new AngularControllerTemplate();
                //acTemplate.Model = model;
                //string acContent = acTemplate.TransformText();
                //File.WriteAllText(Path.Combine(clientProjectDir, "Scripts\\modules\\stolarus\\controllers", model.Plural.ToLower() + ".js"), acContent);

                //AngularItemTemplate aiTemplate = new AngularItemTemplate();
                //aiTemplate.Model = model;
                //string aiContent = aiTemplate.TransformText();
                //File.WriteAllText(Path.Combine(clientProjectDir, "WebPages", model.Singular + "ListItem.html"), aiContent);


                //data project

                ModelTemplate modelTemplate = new ModelTemplate();
                modelTemplate.Model         = model;
                modelTemplate.RootNamespace = databaseInfo.RootNamespace;
                string modelContent = modelTemplate.TransformText();
                File.WriteAllText(Path.Combine(dataProjectDir, "Models", model.Singular + ".cs"), modelContent);

                MappingTemplate mapTemplate = new MappingTemplate();
                mapTemplate.Model         = model;
                mapTemplate.RootNamespace = databaseInfo.RootNamespace;
                string mapContent = mapTemplate.TransformText();
                File.WriteAllText(Path.Combine(dataProjectDir, "Models\\Mapping", model.Singular + "Map.cs"), mapContent);

                RepositoryTemplate repositoryTemplate = new RepositoryTemplate();
                repositoryTemplate.Model         = model;
                repositoryTemplate.RootNamespace = databaseInfo.RootNamespace;
                string repositoryContent = repositoryTemplate.TransformText();
                File.WriteAllText(Path.Combine(dataProjectDir, "Repository", model.Plural + "Repository.cs"), repositoryContent);

                ContractTemplate contractTemplate = new ContractTemplate();
                contractTemplate.Model         = model;
                contractTemplate.RootNamespace = databaseInfo.RootNamespace;
                string contractContent = contractTemplate.TransformText();
                File.WriteAllText(Path.Combine(dataProjectDir, "Contracts", "I" + model.Plural + "Repository.cs"), contractContent);

                //web project

                //ModelBinderTemplate modelBinderTemplate = new ModelBinderTemplate();
                //modelBinderTemplate.Model = model;
                //modelBinderTemplate.RootNamespace = databaseInfo.RootNamespace;
                //string modelBinderContent = modelBinderTemplate.TransformText();
                //File.WriteAllText(Path.Combine(webProjectDir, "ModelBinding", model.Plural + "FilterModelBinder.cs"), modelBinderContent);

                //ControllerTemplate controllerTemplate = new ControllerTemplate();
                //controllerTemplate.Model = model;
                //controllerTemplate.RootNamespace = databaseInfo.RootNamespace;
                //string controllerContent = controllerTemplate.TransformText();
                //File.WriteAllText(Path.Combine(webProjectDir, "Controllers", model.Plural + "Controller.cs"), controllerContent);

                //EditorTemplate editorTemplate = new EditorTemplate();
                //editorTemplate.Model = model;
                //editorTemplate.RootNamespace = databaseInfo.RootNamespace;
                //string editorContent = editorTemplate.TransformText();
                //File.WriteAllText(Path.Combine(webProjectDir, "Views\\Shared\\EditorTemplates", "_" + model.Singular + ".cshtml"), editorContent);

                ////client web project

                //ApiControllerTemplate apiControllerTemplate = new ApiControllerTemplate();
                //apiControllerTemplate.Model = model;
                //apiControllerTemplate.RootNamespace = databaseInfo.RootNamespace;
                //string apiControllerContent = apiControllerTemplate.TransformText();
                //File.WriteAllText(Path.Combine(clientProjectDir, "Controllers\\Api", model.Plural + "Controller.cs"), apiControllerContent);
            }

            //ContextTemplate contextTemplate = new ContextTemplate();
            //contextTemplate.RootNamespace = databaseInfo.RootNamespace;
            //contextTemplate.Models = databaseInfo.Models;
            //string contextContent = contextTemplate.TransformText();
            //File.WriteAllText(Path.Combine(dataProjectDir, "Models", databaseInfo.RootNamespace + "Context.cs"), contextContent);

            //RegisterModelBindersTemplate registerModelBindersTemplate = new RegisterModelBindersTemplate();
            //registerModelBindersTemplate.Models = databaseInfo.Models;
            //registerModelBindersTemplate.RootNamespace = databaseInfo.RootNamespace;
            //string registerModelBindersContent = registerModelBindersTemplate.TransformText();
            //File.WriteAllText(Path.Combine(webProjectDir, "App_Start", "ModelBindersConfig.cs"), registerModelBindersContent);

            //RegisterUnityTemplate registerUnityTemplate1 = new RegisterUnityTemplate();
            //registerUnityTemplate1.RootNamespace = databaseInfo.RootNamespace + ".Admin";
            //registerUnityTemplate1.Models = databaseInfo.Models;
            //string registerUnityContent1 = registerUnityTemplate1.TransformText();
            //File.WriteAllText(Path.Combine(webProjectDir, "App_Start", "UnityConfig.custom.cs"), registerUnityContent1);

            //RegisterUnityTemplate registerUnityTemplate2 = new RegisterUnityTemplate();
            //registerUnityTemplate2.RootNamespace = databaseInfo.RootNamespace;
            //registerUnityTemplate2.Models = databaseInfo.Models;
            //string registerUnityContent2 = registerUnityTemplate2.TransformText();
            //File.WriteAllText(Path.Combine(clientProjectDir, "App_Start", "UnityConfig.custom.cs"), registerUnityContent2);

            //MiscTemplate miscTemplate = new MiscTemplate();
            //miscTemplate.Models = databaseInfo.Models;
            //string miscContent = miscTemplate.TransformText();
            //File.WriteAllText(Path.Combine(webProjectDir, "Misc.txt"), miscContent);
        }