public override bool Execute()
        {
            Log.LogMessage("Generating template pack report using format [{0}] to file: [{1}]", ReportType, OutputFile.GetFullPath());

            if (SnippetFiles == null)
            {
                SnippetFiles = new ITaskItem[] { };
            }

            // the info that we want to show includes the following data
            // Name, Description, ProjetType, ProjectSubType?
            XNamespace ns = "http://schemas.microsoft.com/developer/vstemplate/2005";

            var allResults = from d in this.GetTemplateFilesAsDocs()
                             from r in d.Document.Root.Descendants(ns + "TemplateData")
                             orderby r.ElementSafeValue(ns + "Name")
                             orderby r.ElementSafeValue(ns + "ProjectSubType")
                             orderby r.ElementSafeValue(ns + "ProjectType")
                             orderby d.TemplateType
                             select new TemplatePackReportModel
            {
                TemplatePath   = d.TemplatePath,
                TemplateType   = d.TemplateType,
                Name           = r.ElementSafeValue(ns + "Name"),
                Description    = r.ElementSafeValue(ns + "Description"),
                ProjectType    = r.ElementSafeValue(ns + "ProjectType"),
                ProjectSubType = r.ElementSafeValue(ns + "ProjectSubType")
            };

            IList <string> snippetFilePaths = new List <string>();

            SnippetFiles.ToList().ForEach(snippetItem => {
                snippetFilePaths.Add(snippetItem.GetFullPath());
            });

            var snippets = GetAllSnippetInfo(snippetFilePaths);

            Log.LogMessage("info.count [{0}]", allResults.Count());
            ITemplatePackReportWriter reportWriter = null;

            if (_reportType == Tasks.ReportType.Text)
            {
                reportWriter = new TextTemplatePackReportWriter();
            }
            else if (_reportType == Tasks.ReportType.Xml)
            {
                reportWriter = new XmlTemplatePackReportWriter();
            }
            else
            {
                Log.LogError("Unknown value for ReportType [{0}]", ReportType);
                return(false);
            }

            reportWriter.WriteReport(OutputFile.GetFullPath(), allResults, snippets);

            return(true);
        }
Example #2
0
        private string PublishDirectory(string token)
        {
            var gh           = new GitHub(token);
            var snippetFiles = new SnippetFiles(Directory);

            return(Id.IsNullOrWhiteSpace() ?
                   gh.CreateGist(Description, snippetFiles, isPublic: !Secret).Result :
                   gh.UpdateGist(Id, Description, snippetFiles).Result);
        }
Example #3
0
        private string PublishSnippet(string token)
        {
            var gh        = new GitHub(token);
            var directory = Path.Combine(Options.SnippetPath, Snippet.Directory);

            var snippetFiles = new SnippetFiles(directory);

            if (Uri.IsWellFormedUriString(snippetFiles.Meta.GistUrl, UriKind.Absolute))
            {
                var id          = new Uri(snippetFiles.Meta.GistUrl).Segments.Last();
                var description = Description.IsNullOrWhiteSpace() ? snippetFiles.Meta.Description : Description;
                return(gh.UpdateGist(id, description, snippetFiles).Result);
            }

            return(gh.CreateGist(Description, snippetFiles, isPublic: true).Result);
        }