private void ProjectSync(ProjectItem templateProjectItem, IEnumerable <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 = VSHelper.GetTemplateProjectItem(templateProjectItem.DTE, item.FirstItem, templateProjectItem); ProjectSyncPart(pi, item.OutputFiles); if (pi.Name.EndsWith("txt4")) { templatePlaceholderList.Add(VSHelper.GetProjectItemFullPath(pi)); } } // clean up bool hasDefaultItems = groupedFileNames.Where(f => String.IsNullOrEmpty(f.ProjectName) && String.IsNullOrEmpty(f.FolderName)).Count() > 0; if (hasDefaultItems == false) { ProjectSyncPart(templateProjectItem, new List <OutputFile>()); } }
/// <summary> /// Removes old template placeholders from the solution. /// </summary> private void CleanUpTemplatePlaceholders() { string[] activeTemplateFullNames = templatePlaceholderList.ToArray(); string[] allHelperTemplateFullNames = VSHelper.GetAllSolutionItems(dte) .Where(p => p.Name == VSHelper.GetTemplatePlaceholderName(templateProjectItem)) .Select(p => VSHelper.GetProjectItemFullPath(p)) .ToArray(); var delta = allHelperTemplateFullNames.Except(activeTemplateFullNames).ToArray(); var dirtyHelperTemplates = VSHelper.GetAllSolutionItems(dte) .Where(p => delta.Contains(VSHelper.GetProjectItemFullPath(p))); foreach (ProjectItem item in dirtyHelperTemplates) { if (item.ProjectItems != null) { foreach (ProjectItem subItem in item.ProjectItems) { subItem.Remove(); } } item.Remove(); } }
private void FormatProjectItems(IEnumerable <ProjectItem> items) { foreach (var item in items) { _textTransformation.WriteLine( VSHelper.ExecuteVsCommand(dte, item, "Edit.FormatDocument")); //, "Edit.RemoveAndSort")); _textTransformation.WriteLine("//-> " + item.Name); } }
/// <summary> /// Produce the template output files. /// </summary> public virtual IEnumerable <OutputFile> Process(bool split = true) { var list = new List <OutputFile>(); if (split) { EndBlock(); var headerText = _generationEnvironment.ToString(header.Start, header.Length); var footerText = _generationEnvironment.ToString(footer.Start, footer.Length); files.Reverse(); foreach (var block in files) { var outputPath = VSHelper.GetOutputPath(dte, block, Path.GetDirectoryName(_textTransformation.Host.TemplateFile)); var fileName = Path.Combine(outputPath, block.Name); var content = ReplaceParameter(headerText, block) + _generationEnvironment.ToString(block.Start, block.Length) + footerText; var file = new OutputFile { FileName = fileName, ProjectName = block.ProjectName, FolderName = block.FolderName, FileProperties = block.FileProperties, Content = content }; var isNieuwOfAangepast = CreateFile(file); _generationEnvironment.Remove(block.Start, block.Length); if (isNieuwOfAangepast || !file.FileName.EndsWith(".sql")) { list.Add(file); } } } projectSyncAction.EndInvoke(projectSyncAction.BeginInvoke(list, null, null)); CleanUpTemplatePlaceholders(); var items = VSHelper.GetOutputFilesAsProjectItems(dte, list); WriteVsProperties(items, list); if (IsAutoIndentEnabled == true && split == true) { FormatProjectItems(items); } WriteLog(list); return(list); }
/// <summary> /// Gets a list of helper templates from the log. /// </summary> /// <returns>List of generated helper templates.</returns> private string[] GetPreviousTemplatePlaceholdersFromLog() { string path = Path.GetDirectoryName(_textTransformation.Host.ResolvePath(_textTransformation.Host.TemplateFile)); string file1 = Path.GetFileNameWithoutExtension(_textTransformation.Host.TemplateFile) + ".txt"; string contentPrevious = File.ReadAllText(Path.Combine(path, file1)); var result = contentPrevious .Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries) .Select(x => x.Split(new[] { "=>" }, StringSplitOptions.RemoveEmptyEntries).First()) .Select(x => Regex.Replace(x, "//", String.Empty).Trim()) .Where(x => x.EndsWith(VSHelper.GetTemplatePlaceholderName(templateProjectItem))) .ToArray(); return(result); }
private void WriteVsProperties(IEnumerable <ProjectItem> items, IEnumerable <OutputFile> outputFiles) { foreach (var file in outputFiles) { var item = items.Where(p => p.Name == Path.GetFileName(file.FileName)).FirstOrDefault(); if (item == null) { continue; } if (String.IsNullOrEmpty(file.FileProperties.CustomTool) == false) { VSHelper.SetPropertyValue(item, "CustomTool", file.FileProperties.CustomTool); } if (String.IsNullOrEmpty(file.FileProperties.BuildActionString) == false) { VSHelper.SetPropertyValue(item, "ItemType", file.FileProperties.BuildActionString); } } }