public void CreateSolution() { // Create Target solution from PrismStarter Visual Studio project templates // (zip files in ..\Users\...\Documents\My Exported Templates). MessageService.WriteMessage(string.Empty); MessageService.WriteMessage("==================================================="); MessageService.WriteMessage(string.Format("Creating {0}", Connect.settingsObject.TargetSolutionPath)); MessageService.WriteMessage("==================================================="); sln2.Create(Utilities.RemoveEndBackSlash(Connect.settingsObject.TargetSolutionPath), Connect.settingsObject.TargetSolutionName); MessageService.WriteMessage(string.Format("{0} created", Connect.settingsObject.TargetSolutionName)); try { int numProjects = Connect.settingsObject.ProjectNames.Count; for (int i = 0; i < numProjects; i++) { templatePath = sln2.GetProjectTemplate(Connect.settingsObject.ZipFileNames[i], "CSharp"); projectPath = string.Format("{0}{1}", Connect.settingsObject.TargetSolutionPath, Utilities.RemoveEndBackSlash(Connect.settingsObject.ProjectPaths[i])); sln2.AddFromTemplate(templatePath, projectPath, Utilities.RemoveEndBackSlash(Connect.settingsObject.ProjectPaths[i]), false); MessageService.WriteMessage(string.Format("{0} created", Connect.settingsObject.ProjectNames[i])); } } catch (Exception x) { throw x; } sln2.SaveAs(string.Format("{0}{1}", Connect.settingsObject.TargetSolutionPath, Connect.settingsObject.TargetSolutionName)); CloseSolution(); MessageService.WriteMessage(string.Format("{0} created", Connect.settingsObject.TargetSolutionName)); }
public void FindAndReplace() { MessageService.WriteMessage(string.Empty); MessageService.WriteMessage("==================================================="); MessageService.WriteMessage("FindAndReplace"); MessageService.WriteMessage("==================================================="); Application.DoEvents(); FindAndReplaceSolutionFiles(Connect.settingsObject.TargetSolutionPath); }
protected void WalkDirectoryTree(System.IO.DirectoryInfo root, string fileSpec, List <KeyValuePair <string, string> > findReplaceList) { System.IO.FileInfo[] files = null; System.IO.DirectoryInfo[] subDirs = null; // First, process all the files directly under this folder try { files = root.GetFiles(fileSpec); } // This is thrown if even one of the files requires permissions greater // than the application provides. catch (UnauthorizedAccessException e) { // This code just writes out the message and continues to recurse. // You may decide to do something different here. For example, you // can try to elevate your privileges and access the file again. MessageService.WriteMessage(e.Message); } catch (System.IO.DirectoryNotFoundException e) { MessageService.WriteMessage(e.Message); } if (files != null) { foreach (System.IO.FileInfo fi in files) { // In this example, we only access the existing FileInfo object. If we // want to open, delete or modify the file, then // a try-catch block is required here to handle the case // where the file has been deleted since the call to TraverseTree(). MessageService.WriteMessage(fi.FullName); foreach (KeyValuePair <string, string> kvp in findReplaceList) { try { FindAndReplace(fi.FullName, kvp); } catch (Exception ex) { MessageService.WriteMessage(ex.Message); } } } // Now find all the subdirectories under this directory. subDirs = root.GetDirectories(); foreach (System.IO.DirectoryInfo dirInfo in subDirs) { // Resursive call for each subdirectory. WalkDirectoryTree(dirInfo, fileSpec, findReplaceList); } } }
public void RenameGeneratedCodeFiles() { MessageService.WriteMessage(string.Empty); MessageService.WriteMessage("=================================================================================================="); MessageService.WriteMessage("RenameGeneratedCodeFiles"); MessageService.WriteMessage("=================================================================================================="); Application.DoEvents(); OpenSolution(); renameGeneratedCode.TraverseAllProjects(); SaveProjectsAndSolution(); //CloseSolution(); }
void TemplatesGenerator_T4TransformCompleted(object sender, EventArgs args) { MessageService.WriteMessage("TransformAllT4Templates completed"); // CodeGeneration Part 2 codeGenerator.RemoveFromSolution(); codeGenerator.RenameGeneratedCodeFiles(); endTime = DateTime.Now.ToLongTimeString(); MessageBox.Show(string.Format("EndTime: {0}{1}StartTime: {2}", endTime, Environment.NewLine, startTime), "CodeGeneration Successful"); MessageService.WriteMessage(string.Empty); MessageService.WriteMessage("===================================================================="); MessageService.WriteMessage("CodeGeneration Successful"); MessageService.WriteMessage(string.Format("EndTime: {0}{1}StartTime: {2}", endTime, Environment.NewLine, startTime)); MessageService.WriteMessage("===================================================================="); }
protected void DeleteT4Child(ProjectItem templateItem) { foreach (ProjectItem childItem in templateItem.ProjectItems) { if (childItem.ProjectItems.Count == 0) { string localPath = GetLocalPath(childItem); File.Delete(localPath); MessageService.WriteMessage(string.Format("ChildFile: {0} deleted", localPath)); } else { // should not get here because templateItem should have only 1 child throw new Exception("Template File has more that 1 child."); } } }
public override void ProcessFolderItem(ProjectItem projectItem) { string templateFileFullName = string.Empty; try { file = folder.ProjectItems.Item(projectItem.Name); // Remove the template file and add its generated file to the project. if (file != null) { // Get the complete template file name including full path. templateFileFullName = GetLocalPath(file); // Make a copy of the file that's generated by the template file. string generatedFilePath = GetPathToT4Child(file); string generatedFilePathCopy = generatedFilePath + ".gc"; File.Copy(generatedFilePath, generatedFilePathCopy); // Remove the template file from the project. file.Remove(); // Delete the template file (.tt) and the file it generated from the file system. File.Delete(templateFileFullName); File.Delete(generatedFilePath); // Add the copy of the file that the template generated to the project. folder.ProjectItems.AddFromFile(generatedFilePathCopy); //MessageService.WriteMessage(string.Format("Generated file add: {0}", generatedFilePathCopy)); } else { MessageService.WriteMessage(string.Format("Template: {0} not found", projectItem.Name)); } } catch (Exception ex) { if (ex.Message == "Value does not fall within the expected range.") { MessageService.WriteMessage(string.Format("Template: {0} not found", projectItem.Name)); } else { throw ex; } } }
private void TraverseOneProject(Project project) { foreach (ProjectItem projectItem in project.ProjectItems) { if (projectItem.Kind == EnvDTEConstants.vsProjectItemKindPhysicalFolder) { folderList = new List <string>(); TraverseProjectFolders(projectItem); } else { if (projectItem.Kind == EnvDTEConstants.vsProjectItemKindPhysicalFile && IsKindT4(projectItem)) { ProcessFolderItem(projectItem); MessageService.WriteMessage(string.Empty); } } } }
public override void ProcessFolderItem(ProjectItem projectItem) { string gcFileFullName = string.Empty; string gcFileFullNameRenamed = string.Empty; try { file = folder.ProjectItems.Item(projectItem.Name); if (file != null) { // Get the generated file (.gc) name including full path. gcFileFullName = GetLocalPath(file); // Create a file name that has ".gc" stripped off. gcFileFullNameRenamed = gcFileFullName.Substring(0, gcFileFullName.Length - 3); // Make a copy of the .gc but with the .gc stripped off. File.Copy(gcFileFullName, gcFileFullNameRenamed); // Remove the .gc from the project and the file system. file.Remove(); File.Delete(gcFileFullName); // Add the generated file to the project. (automatically adds it to file system) folder.ProjectItems.AddFromFile(gcFileFullNameRenamed); MessageService.WriteMessage(string.Format("GCFile renamed. {0}", gcFileFullNameRenamed)); } else { MessageService.WriteMessage(string.Format("Template: {0} not found", projectItem.Name)); } } catch (Exception ex) { if (ex.Message == "Value does not fall within the expected range.") { MessageService.WriteMessage(string.Format("Template: {0} not found", projectItem.Name)); } else { throw ex; } } }
private void RemoveProject(string projectName) { MessageService.WriteMessage(string.Empty); MessageService.WriteMessage("=================================================================================================="); MessageService.WriteMessage(string.Format("Removing Project: {0}....Please be patient....", projectName)); MessageService.WriteMessage("=================================================================================================="); Application.DoEvents(); string projectDirectory = string.Empty; foreach (Project project in sln2.Projects) { if (project.UniqueName.IndexOf(projectName) != -1) { projectDirectory = project.FullName.Substring(0, project.FullName.LastIndexOf("\\") + 1); sln2.Remove(project); MessageService.WriteMessage(string.Format("Project: {0} removed", projectName)); break; } } Directory.Delete(projectDirectory, true); }
public void TransformAllT4Templates() { // At this point the generic .tt files have been renamed to Domain specific names and all the generic words // in the .tt files have been replaced with Domain specific words. Now run the Transform on all the // .tt files to generate Domain specific code. MessageService.WriteMessage(string.Empty); MessageService.WriteMessage("=================================================================================================="); MessageService.WriteMessage("Transforming templates....Generating Target Code....Please be patient....Takes about 30 seconds..."); MessageService.WriteMessage("=================================================================================================="); Application.DoEvents(); try { OpenSolution(); ce = dte2.Events.CommandEvents; ce.AfterExecute += new _dispCommandEvents_AfterExecuteEventHandler(TransformAllT4Templates_AfterExecute); dte2.ExecuteCommand("Build.TransformAllT4Templates"); } catch (Exception ex) { MessageService.WriteMessage(ex.Message); } }