public WebApiServiceCSProjectFileTemplate(IOutputTarget project, IVisualStudioProject model)
     : base(Identifier, project, model)
 {
     //_port = project.ProjectType.Properties.FirstOrDefault(x => x.Name == "Port")?.Value;
     //bool.TryParse(project.ProjectType.Properties.FirstOrDefault(x => x.Name == "UseSsl")?.Value, out var useSsl);
     //if (useSsl)
     //{
     //    _sslPort = project.ProjectType.Properties.First(x => x.Name == "SslPort").Value;
     //}
 }
Example #2
0
 public ProjectConfig(IVisualStudioProject project)
 {
     _project = project;
     Metadata = new Dictionary <string, object>()
     {
         ["Language Version"]  = _project.LanguageVersion,
         ["Nullable Enabled"]  = _project.NullableEnabled,
         ["Target Frameworks"] = _project.TargetFrameworkVersion(),
         [MetadataKey.IsMatch] = true
     };
 }
 public void GenerateConfigurationForProject(IVisualStudioProject project, Dictionary<string, object> environment)
 {
     var exeConfig = project.OutputFile + ".config";
     var templateFile = ProjectTemplateConfig(project);
     if (templateFile != null)
     {
         var configFile = Regex.Replace(templateFile, @"\.template\.config$", ".config");
         List<string> configFiles = new List<string>();
         configFiles.Add(configFile);
         if (File.Exists(exeConfig))
         {
             configFiles.Add(exeConfig);
         }
         ConfigureFiles(templateFile, environment, configFiles);
     }
 }
        public void GenerateConfigurationForProject(IVisualStudioProject project, Dictionary <string, object> environment)
        {
            var exeConfig    = project.OutputFile + ".config";
            var templateFile = ProjectTemplateConfig(project);

            if (templateFile != null)
            {
                var           configFile  = Regex.Replace(templateFile, @"\.template\.config$", ".config");
                List <string> configFiles = new List <string>();
                configFiles.Add(configFile);
                if (File.Exists(exeConfig))
                {
                    configFiles.Add(exeConfig);
                }
                ConfigureFiles(templateFile, environment, configFiles);
            }
        }
Example #5
0
        private static List <IVisualStudioProject> Generate <T, C>(string interfaceName, CodeGenSettings settings, List <IVisualStudioProject> projects, IProjectFileRender fileRender, IEnumerable <C> tables)
        {
            List <Assembly> assemblies = ReflectionHelper <T> .LoadAssemblies(settings.CompiledTemplateLocation);

            List <T> templates = ReflectionHelper <T> .LoadTemplates(assemblies, interfaceName);


            foreach (T template in templates)
            {
                IClassMetadata classmeta        = (IClassMetadata)template;
                string         projectNamespace = classmeta.ProjectNamespace;

                IVisualStudioProject projectFile = RetrieveProject(projectNamespace, projects);
                projectFile = fileRender.Render(settings, template, tables, projectFile);
                projects    = SaveProject(projectFile, projects);
            }

            return(projects);
        }
Example #6
0
        /// <summary>
        /// Search for project in the project collection. If project is found, it saves the changes. If it's not found then it adds the project to the collection.
        /// </summary>
        /// <param name="project">Recently changed project</param>
        /// <param name="vsProjects">Collection of projects to be searched</param>
        /// <returns>A collection of projects with the project changes added to the collection</returns>
        private static List <IVisualStudioProject> SaveProject(IVisualStudioProject project, List <IVisualStudioProject> vsProjects)
        {
            bool wasFound = false;

            //Search for project
            for (int index = 0; index < vsProjects.Count; index++)
            {
                if (vsProjects[index].ProjectNamespace.ToLower() == project.ProjectNamespace.ToLower())
                {
                    vsProjects[index] = project;
                    wasFound          = true;
                    break;
                }
            }

            //if it wasn't found add it to the project collection
            if (!wasFound)
            {
                vsProjects.Add(project);
            }

            return(vsProjects);
        }
 public CoreLibraryCSProjectTemplate(IProject project, IVisualStudioProject model)
     : base(Identifier, project, model)
 {
 }
Example #8
0
 public ConsoleAppCsProjectTemplate(IProject project, IVisualStudioProject model)
     : base(Identifier, project, model)
 {
 }
 public WcfServiceCSProjectFileTemplate(IOutputTarget project, IVisualStudioProject model)
     : base(IDENTIFIER, project, model)
 {
 }
        public static NETCoreSettings GetNETCoreSettings(this IVisualStudioProject project)
        {
            var stereotype = project.GetStereotype(".NET Core Settings");

            return(stereotype != null ? new NETCoreSettings(stereotype) : null);
        }
 public static bool HasNETCoreSettings(this IVisualStudioProject project)
 {
     return(project.HasStereotype(".NET Core Settings"));
 }
Example #12
0
 public static IList <IOutputTargetRole> GetRoles(this IVisualStudioProject project)
 {
     return(project.Roles.Select(x => new ProjectOutput(x.Name, x.Folder?.Name)).Cast <IOutputTargetRole>()
            .Concat(project.Folders.SelectMany(project.GetRolesInFolder))
            .ToList());
 }
 public void GenerateConfigurationForProject(IVisualStudioProject project, string environmentUrl)
 {
     GenerateConfigurationForProject(project, LoadEnvironmentConfiguration(environmentUrl));
 }
 private string ProjectTemplateConfig(IVisualStudioProject project)
 {
     return(Directory.GetFiles(project.ProjectDirectory, "*.template.config").FirstOrDefault());
 }
        public IVisualStudioProject Render <T>(CodeGenSettings settings, object template, IEnumerable <T> collection, IVisualStudioProject projectFile)
        {
            IStaticAsset         asset           = (IStaticAsset)template;
            List <StaticContent> renderedAssests = asset.Render();


            IClassMetadata classmeta = asset;

            string projectNamespace = string.Format("{0}.{1}", settings.SolutionNamespace, classmeta.ProjectNamespace);
            string projectDirectory = string.Format(@"{0}\{1}", settings.CodeGenerationDirectory, projectNamespace);

            projectFile = ClassesLogic.SetProjectProperties(settings, classmeta, projectFile, projectDirectory);

            //create Directory if it doesn't exists
            if (!File.Exists(projectDirectory))
            {
                Directory.CreateDirectory(projectDirectory);
            }

            //Set File properties... optional Namespace, and the full file path.
            string fullProjectNamespace = projectNamespace + ClassesLogic.AddFolderNamespaces(classmeta);


            foreach (StaticContent content in renderedAssests)
            {
                string filePath         = string.Format(@"{0}\{1}{2}", projectDirectory, classmeta.ClassFilePath, content.FileName);
                string projectClassPath = (string.IsNullOrEmpty(classmeta.ClassFilePath)
                               ? content.FileName
                               : classmeta.ClassFilePath + content.FileName);

                ProjectArtifact artifact = new ProjectArtifact(projectClassPath, content.CreateGeneratedCounterpart);
                projectFile.Classes.Add(artifact);

                StaticContent _content = content;
                if (content.SetNamespace)
                {
                    _content.Content = SetNamespaceAndClass(content.Content.ToString(), fullProjectNamespace);
                }

                SaveContent(classmeta, projectDirectory, content, _content, fullProjectNamespace, filePath);
            }

            return(projectFile);
        }
Example #16
0
 public static void Configure(this IVisualStudioProject project, string environmentUrl)
 {
     new TemplateConfigurer().GenerateConfigurationForProject(project, environmentUrl);
 }
Example #17
0
 public static bool HasTemplateConfig(this IVisualStudioProject project)
 {
     return(new TemplateConfigurer().HasTemplateConfig(project));
 }
Example #18
0
 public static void Configure(this IVisualStudioProject project, Dictionary <string, object> environment)
 {
     new TemplateConfigurer().GenerateConfigurationForProject(project, environment);
 }
 public bool HasTemplateConfig(IVisualStudioProject project)
 {
     return(ProjectTemplateConfig(project) != null);
 }
Example #20
0
        public static IVisualStudioProject SetProjectProperties(CodeGenSettings settings, IClassMetadata classmeta, IVisualStudioProject projectFile, string projectDirectory)
        {
            //Set project properties
            projectFile.ProjectDirectory = projectDirectory;
            projectFile.RootNamespace    = settings.SolutionNamespace;
            projectFile.ProjectNamespace = classmeta.ProjectNamespace;

            return(projectFile);
        }
 private string ProjectTemplateConfig(IVisualStudioProject project)
 {
     return Directory.GetFiles(project.ProjectDirectory, "*.template.config").FirstOrDefault();
 }
 public bool HasTemplateConfig(IVisualStudioProject project)
 {
     return ProjectTemplateConfig(project) != null;
 }
        public IVisualStudioProject Render <T>(CodeGenSettings settings, object template, IEnumerable <T> collection, IVisualStudioProject projectFile)
        {
            ICompiledTemplate           _template = (ICompiledTemplate)template;
            IEnumerable <DatabaseTable> tables    = (IEnumerable <DatabaseTable>)collection;

            IClassMetadata classmeta = _template;

            //Creating project specific variables
            string projectNamespace = string.Format("{0}.{1}", settings.SolutionNamespace, classmeta.ProjectNamespace);
            string projectDirectory = string.Format(@"{0}\{1}", settings.CodeGenerationDirectory, projectNamespace);

            //Set the project properties. These should never change.
            ClassesLogic.SetProjectProperties(settings, classmeta, projectFile, projectDirectory);
            string fileDirectory = (string.IsNullOrEmpty(classmeta.ClassFilePath) ? projectDirectory : string.Format(@"{0}\{1}", projectDirectory, classmeta.ClassFilePath));

            //create the project and project sub directory
            CreateProjectAndClassDirectories(projectDirectory, fileDirectory);
            string fileNamespace = projectNamespace + ClassesLogic.AddFolderNamespaces(classmeta);

            //Render out the Templates by passing in the collection of Tables
            foreach (DatabaseTable table in tables)
            {
                string filename         = table.Name + classmeta.FilenameAppending;
                string projectClassPath = (string.IsNullOrEmpty(classmeta.ClassFilePath)
                                               ? filename
                                               : classmeta.ClassFilePath + filename);
                projectFile.Classes.Add(new ProjectArtifact(projectClassPath + ".cs", true));

                string fullQualifiedPathOfClass = string.Format(@"{0}\{1}.cs", fileDirectory, filename);
                string content = _template.RenderTemplate(table, settings);

                //Write out Generated code
                content = SetNamespaceAndClass(content, filename, fileNamespace);
                File.WriteAllText(fullQualifiedPathOfClass, content);
            }

            return(projectFile);
        }
Example #24
0
        private static IEnumerable <IOutputTargetRole> GetRolesInFolder(this IVisualStudioProject project, FolderModel folder)
        {
            var roles = folder.Roles.Select(x => new ProjectOutput(x.Name, x.Folder?.Name)).ToList <IOutputTargetRole>();

            return(roles);
        }
 public void GenerateConfigurationForProject(IVisualStudioProject project, string environmentUrl)
 {
     GenerateConfigurationForProject(project, LoadEnvironmentConfiguration(environmentUrl));
 }