Example #1
0
        private void ProjectSync(EnvDTE.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
            };

            this.templatePlaceholderList.Clear();

            foreach (var item in groupedFileNames)
            {
                EnvDTE.ProjectItem pi = VSHelper.GetTemplateProjectItem(templateProjectItem.DTE, item.FirstItem, templateProjectItem);
                ProjectSyncPart(pi, item.OutputFiles);

                if (pi.Name.EndsWith("txt4"))
                {
                    this.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>());
            }
        }
Example #2
0
        public static IEnumerable <ProjectItem> GetOutputFilesAsProjectItems(EnvDTE.DTE dte, IEnumerable <OutputFile> outputFiles)
        {
            var fileNames = (from o in outputFiles
                             select Path.GetFileName(o.FileName)).ToArray();

            return(VSHelper.GetAllSolutionItems(dte).Where(f => fileNames.Contains(f.Name)));
        }
Example #3
0
        /// <summary>
        /// Removes old template placeholders from the solution.
        /// </summary>
        private void CleanUpTemplatePlaceholders()
        {
            string[] activeTemplateFullNames    = this.templatePlaceholderList.ToArray();
            string[] allHelperTemplateFullNames = VSHelper.GetAllSolutionItems(this.dte)
                                                  .Where(p => p.Name == VSHelper.GetTemplatePlaceholderName(this.templateProjectItem))
                                                  .Select(p => VSHelper.GetProjectItemFullPath(p))
                                                  .ToArray();

            var delta = allHelperTemplateFullNames.Except(activeTemplateFullNames).ToArray();

            var dirtyHelperTemplates = VSHelper.GetAllSolutionItems(this.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();
            }
        }
Example #4
0
 private void FormatProjectItems(IEnumerable <EnvDTE.ProjectItem> items)
 {
     foreach (var item in items)
     {
         this._textTransformation.WriteLine(
             VSHelper.ExecuteVsCommand(this.dte, item, "Edit.FormatDocument")); //, "Edit.RemoveAndSort"));
         this._textTransformation.WriteLine("//-> " + item.Name);
     }
 }
Example #5
0
        /// <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    = this.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
                    };

                    CreateFile(file);
                    _generationEnvironment.Remove(block.Start, block.Length);

                    list.Add(file);
                }
            }

            projectSyncAction(list);
            this.CleanUpTemplatePlaceholders();
            var items = VSHelper.GetOutputFilesAsProjectItems(this.dte, list);

            this.WriteVsProperties(items, list);

            if (this.IsAutoIndentEnabled == true && split == true)
            {
                this.FormatProjectItems(items);
            }

            this.WriteLog(list);

            return(list);
        }
Example #6
0
        /// <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(this._textTransformation.Host.ResolvePath(this._textTransformation.Host.TemplateFile));
            string file1           = Path.GetFileNameWithoutExtension(this._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(this.templateProjectItem)))
                         .ToArray();

            return(result);
        }
Example #7
0
        private void WriteVsProperties(IEnumerable <EnvDTE.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);
                }
            }
        }