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); }
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); }