private FileProcessor(object textTransformation) { if (textTransformation == null) { throw new ArgumentNullException("textTransformation"); } var dynamictextTransformation = DynamicTextTransformation2.Create(textTransformation); _templateFile = dynamictextTransformation.Host.TemplateFile; var hostServiceProvider = dynamictextTransformation.Host.AsIServiceProvider(); if (hostServiceProvider == null) { throw new ArgumentNullException("Could not obtain hostServiceProvider"); } _dte = (DTE)hostServiceProvider.GetService(typeof(DTE)); if (_dte == null) { throw new ArgumentNullException("Could not obtain DTE from host"); } var dteServiceProvider = new ServiceProvider((Microsoft.VisualStudio.OLE.Interop.IServiceProvider)_dte); OutputPaneManager.Activate(dteServiceProvider); ProgressBarManager.Activate(dteServiceProvider); _templateProjectItem = _dte.Solution.FindProjectItem(_templateFile); _vsManager = new VsManager(_dte); _opResolver = new OutputPathResolver(_vsManager); }
internal void RemoveUnusedTemplateFiles() { var solutionItems = VsManager.GetAllSolutionItems(_dte); var activeTemplateFullNames = _placeholders.Values.Select(x => VsManager.GetProjectItemFullPath(x)); var allHelperTemplateFullNames = solutionItems.Where(p => p.Name == VsManager.GetTemplatePlaceholderName(_templateProjectItem)) .Select(VsManager.GetProjectItemFullPath); var delta = new HashSet <string>(allHelperTemplateFullNames.Except(activeTemplateFullNames)); //Nalopen hier ligt misschien het issue var dirtyHelperTemplates = solutionItems.Where(p => delta.Contains(VsManager.GetProjectItemFullPath(p))); foreach (ProjectItem item in dirtyHelperTemplates) { if (item.ProjectItems != null) { foreach (ProjectItem subItem in item.ProjectItems) { subItem.Remove(); } } item.Remove(); } }
public virtual void Process(IEnumerable <OutputFile> files) { var filesToProcess = new List <OutputFile>(); foreach (var file in files) { var outputPath = VsManager.GetOutputPath(_dte, file, Path.GetDirectoryName(_templateFile)); file.FileName = Path.Combine(outputPath, file.Name) + "_Generated" + GetFileTypeExtension(file); var isNewOrAdjusted = IsNewFile(file); if (isNewOrAdjusted || !file.FileName.EndsWith(".sql")) { OutputPaneManager.WriteToOutputPane($"File {file.Name} shall be processed"); filesToProcess.Add(file); } else { OutputPaneManager.WriteToOutputPane($"File {file.Name} shall not be processed."); } } ProjectSync(_templateProjectItem, filesToProcess); CleanUpTemplatePlaceholders(); var items = VsManager.GetOutputFilesAsProjectItems(_dte, filesToProcess); WriteVsProperties(items, filesToProcess); filesToProcess = null; }
private void CleanUpTemplatePlaceholders() { string[] activeTemplateFullNames = _templatePlaceholderList.ToArray(); string[] allHelperTemplateFullNames = VsManager.GetAllSolutionItems(_dte) .Where(p => p.Name == VsManager.GetTemplatePlaceholderName(_templateProjectItem)) .Select(VsManager.GetProjectItemFullPath) .ToArray(); var delta = allHelperTemplateFullNames.Except(activeTemplateFullNames).ToArray(); var dirtyHelperTemplates = VsManager.GetAllSolutionItems(_dte) .Where(p => delta.Contains(VsManager.GetProjectItemFullPath(p))); foreach (ProjectItem item in dirtyHelperTemplates) { if (item.ProjectItems != null) { foreach (ProjectItem subItem in item.ProjectItems) { subItem.Remove(); } } item.Remove(); } }
internal FileProcessor(DTE dte, string templateFile, ProjectItem templateProjectItem) { _dte = dte; _templateFile = templateFile; _defaultPath = Path.GetDirectoryName(_templateFile); _templateProjectItem = templateProjectItem; _placeholders = new Dictionary <string, ProjectItem>(); _processedFileNames = new Dictionary <string, HashSet <string> >(); _vsManager = new VsManager(dte); _opResolver = new OutputPathResolver(_vsManager); }
internal void ProcessClassFile(OutputFile outputFile) { var outputPath = VsManager.GetOutputPath(_dte, outputFile, _defaultPath); outputFile.FileName = Path.Combine(outputPath, outputFile.FullName); ProjectItem placeHolder = GetPlaceholder(outputFile); if (!FileExist(outputFile) || IsFileContentDifferent(outputFile)) { OutputPaneManager.WriteToOutputPane($"Process {outputFile.Name}"); ProcessFile(outputFile, placeHolder); } RegisterProcessedFile(outputFile); }
private ProjectItem GetPlaceholder(OutputFile outputFile) { var key = GetKey(outputFile); if (_placeholders.ContainsKey(key)) { return(_placeholders[key]); } else { ProjectItem pi = VsManager.GetTemplateProjectItem(_templateProjectItem.DTE, outputFile, _templateProjectItem); _placeholders.Add(key, pi); return(pi); } }
private void WriteVsProperties(IEnumerable <ProjectItem> items, IEnumerable <OutputFile> outputFiles) { foreach (var file in outputFiles) { var item = items.FirstOrDefault(p => p.Name == Path.GetFileName(file.FileName)); if (item == null) { continue; } if (string.IsNullOrEmpty(file.FileProperties.CustomTool) == false) { VsManager.SetPropertyValue(item, "CustomTool", file.FileProperties.CustomTool); } if (string.IsNullOrEmpty(file.FileProperties.BuildActionString) == false) { VsManager.SetPropertyValue(item, "ItemType", file.FileProperties.BuildActionString); } } }
private void ProjectSync(ProjectItem templateProjectItem, IEnumerable <FileBuilder.OutputFile> keepFileNames) { var groupedFileNames = from f in keepFileNames group f by new { f.ProjectName, f.FolderName } into l select new { ProjectName = l.Key.ProjectName, FolderName = l.Key.FolderName, FirstItem = l.First(), OutputFiles = l }; _templatePlaceholderList.Clear(); foreach (var item in groupedFileNames) { ProjectItem pi = VsManager.GetTemplateProjectItem(templateProjectItem.DTE, item.FirstItem, templateProjectItem); ProjectSyncPart(pi, item.OutputFiles); if (UseAutoFormatting) { FormatDocument(pi.ProjectItems); } if (pi.Name.EndsWith("txt4")) { _templatePlaceholderList.Add(VsManager.GetProjectItemFullPath(pi)); } } // clean up bool hasDefaultItems = groupedFileNames.Any(f => string.IsNullOrEmpty(f.ProjectName) && string.IsNullOrEmpty(f.FolderName)); if (hasDefaultItems == false) { ProjectSyncPart(templateProjectItem, new List <OutputFile>()); } }