public void CreateTableSolution() { // Create Table solution from PrismTemplates 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.TableSolutionPath)); MessageService.WriteMessage("==================================================="); sln2.Create(Utilities.RemoveEndBackSlash(Connect.settingsObject.TableSolutionPath), Connect.settingsObject.TableSolutionName); MessageService.WriteMessage(string.Format("{0} created", Connect.settingsObject.TableSolutionName)); try { int numProjects = Connect.settingsObject.TableProjectNames.Count; for (int i = 0; i < numProjects; i++) { templatePath = sln2.GetProjectTemplate(Connect.settingsObject.ZipFileNames[i], "CSharp"); projectPath = string.Format("{0}{1}", Connect.settingsObject.TableSolutionPath, Utilities.RemoveEndBackSlash(Connect.settingsObject.TableProjectPaths[i])); sln2.AddFromTemplate(templatePath, projectPath, Utilities.RemoveEndBackSlash(Connect.settingsObject.TableProjectPaths[i]), false); MessageService.WriteMessage(string.Format("{0} created", Connect.settingsObject.TableProjectNames[i])); } } catch (Exception x) { throw x; } sln2.SaveAs(string.Format("{0}{1}", Connect.settingsObject.TableSolutionPath, Connect.settingsObject.TableSolutionName)); CloseTableSolution(); MessageService.WriteMessage(string.Format("{0} created", Connect.settingsObject.TableSolutionName)); }
public override void ProcessFolderItem(ProjectItem projectItem) { string ttFileFullName = string.Empty; string childFileFullName = string.Empty; string targetFileFullName = string.Empty; try { file = folder.ProjectItems.Item(projectItem.Name); // Add tableProject .tt child to targetProject. if (file != null) { ttFileFullName = GetLocalPath(file); childFileFullName = GetPathToT4Child(file); targetProject = FindProjectInTargetSolution(targetSolution2, project.UniqueName); targetFolder = FindFolderInTargetProject(targetProject, folder); // Add the Table .cs file to the TargetFolder. (automatically adds it to file system) targetFileFullName = string.Format(@"{0}{1}\{2}", targetProject.FullName.Substring(0, targetProject.FullName.LastIndexOf("\\") + 1), targetFolder.Name, childFileFullName.Substring(childFileFullName.LastIndexOf("\\") + 1)); if (Connect.settingsObject.RemoveEntity == true) { targetFile = targetFolder.ProjectItems.Item(childFileFullName.Substring(childFileFullName.LastIndexOf("\\") + 1)); if (targetFile != null) { targetFile.Remove(); if (File.Exists(targetFileFullName)) { File.Delete(targetFileFullName); } } } else { if (File.Exists(targetFileFullName)) { File.Delete(targetFileFullName); } File.Copy(childFileFullName, targetFileFullName); targetFolder.ProjectItems.AddFromFile(targetFileFullName); } } else { MessageService.WriteMessage(string.Format("File: {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; } } }
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 FindAndReplace() { MessageService.WriteMessage(string.Empty); MessageService.WriteMessage("==================================================="); MessageService.WriteMessage("FindAndReplace"); MessageService.WriteMessage("==================================================="); Application.DoEvents(); FindAndReplaceSolutionFiles(Connect.settingsObject.TableSolutionPath); }
public void DeleteTableSolution() { MessageService.WriteMessage(string.Empty); MessageService.WriteMessage("==================================================="); MessageService.WriteMessage(string.Format("Delete: {0}", Connect.settingsObject.DeleteTableSolutionPath)); MessageService.WriteMessage("==================================================="); Application.DoEvents(); Directory.Delete(Connect.settingsObject.DeleteTableSolutionPath, true); }
public void ReplaceInT4Templates() { MessageService.WriteMessage(string.Empty); MessageService.WriteMessage("==================================================="); MessageService.WriteMessage("ReplaceInT4Templates"); MessageService.WriteMessage("==================================================="); Application.DoEvents(); OpenTableSolution(); FindAndReplaceSolutionFiles(Connect.settingsObject.TableSolutionPath); CloseTableSolution(); }
public void RenameT4Templates() { MessageService.WriteMessage(string.Empty); MessageService.WriteMessage("==================================================="); MessageService.WriteMessage("RenameT4Templates"); MessageService.WriteMessage("==================================================="); Application.DoEvents(); OpenTableSolution(); renameT4Templates.TraverseAllProjects(); SaveTableSolution(); CloseTableSolution(); }
public override void ProcessFolderItem(ProjectItem projectItem) { string templateFileFullName = string.Empty; string templateFileFullNameRenamed = string.Empty; try { file = folder.ProjectItems.Item(projectItem.Name); // Replace the template file (.tt) with a renamed copy. if (file != null) { // Get the complete template file name including full path. templateFileFullName = GetLocalPath(file); // Replace the word 'Entity' in the template file name with the Domain EntityName. templateFileFullNameRenamed = Utilities.SearchFileNameAndReplace(templateFileFullName, "Entity", Connect.settingsObject.EntityName); // Make the copy. File.Copy(templateFileFullName, templateFileFullNameRenamed); // Delete the file that the template file (.tt) generated from the file system. DeleteT4Child(file); // Remove the template file (.tt) from the project. file.Remove(); // Delete the template file (.tt) from the file system. File.Delete(templateFileFullName); // Add the Domain named template file (.tt) to the project. (automatically adds it to file system) folder.ProjectItems.AddFromFile(templateFileFullNameRenamed); MessageService.WriteMessage(string.Format("Template renamed. {0}", templateFileFullNameRenamed)); } 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; } } }
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; } } }
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."); } } }
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); } 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; } } }
public void CopyGeneratedTableCode() { MessageService.WriteMessage(string.Empty); MessageService.WriteMessage("=================================================================================================="); MessageService.WriteMessage("CopyGeneratedTableCode"); MessageService.WriteMessage("=================================================================================================="); Application.DoEvents(); OpenTableSolution(); InitTargetDTE(); OpenTargetSolution(); copyGeneratedTableCode.targetSolution2 = targetSolution2; copyGeneratedTableCode.TraverseAllProjects(); SaveTargetSolution(); CloseTargetSolution(); QuitTargetDTE(); SaveTableSolution(); CloseTableSolution(); }
void TemplatesGenerator_T4TransformCompleted(object sender, EventArgs args) { MessageService.WriteMessage("TransformAllT4Templates completed"); // CodeGeneration Part 2 try { codeGenerator.CopyGeneratedTableCode(); codeGenerator.DeleteTableSolution(); codeGenerator.OpenTargetSolution2(); } catch (Exception ex) { MessageBox.Show(ex.Message, "CodeGeneration Part 2 failed"); } 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("===================================================================="); }
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 { OpenTableSolution(); ce = dte2.Events.CommandEvents; ce.AfterExecute += new _dispCommandEvents_AfterExecuteEventHandler(TransformAllT4Templates_AfterExecute); dte2.ExecuteCommand("Build.TransformAllT4Templates"); } catch (Exception ex) { MessageService.WriteMessage(ex.Message); } }