예제 #1
0
        public override bool Run()
        {
            if (CodeInfo is null || CodePath is null)
            {
                Status.WriteLine(Severity.Error,
                                 "Application error. Must choose the code repo against which to run this report.");
            }

            try
            {
                Contract.Requires(Directory.Exists(CodePath));
                Contract.Requires(Directory.Exists(Path.Combine(CodePath, ".git")));
            }
            catch
            {
                MessageBox.Show("Invalid code directory.");
                return(false);
            }

            LinkMap.Clear();

            var helper = new RepoHelper();

            try
            {
                using (var docRepo = helper.GetRepository(DocPath))
                    using (var codeRepo = helper.GetRepository(CodePath))
                    {
                        FindRelevantCodeLinks(docRepo, codeRepo);
                        BackfillCommitDates(LinkMap.DocFileIndex.Keys, docRepo, helper);
                        BackfillCommitDates(LinkMap.CodeFileIndex.Keys, codeRepo, helper);
                    }

                if (LinkMap.IsEmpty)
                {
                    Status.WriteLine(Severity.Warning, "No code links found in this repo.");
                    return(false);
                }
                else
                {
                    Status.WriteLine(Severity.Information, "Found links to " +
                                     $"{LinkMap.CodeFileIndex.Count} code files, linked to from " +
                                     $"{LinkMap.DocFileIndex.Count} doc files.");

                    SaveDialog.Title = "Choose where to save the code link report:";
                    var result = SaveDialog.TrySave((writer) => { WriteReport(writer); });
                    Status.WriteLine(result.Sev, result.Message);
                    if (result.Reason == DialogResult.OK)
                    {
                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                Status.WriteLine(Severity.Error, $"{ex.GetType().Name}: {ex.Message}");
            }
            return(false);
        }
예제 #2
0
        public override bool Run()
        {
            base.Run();

            Contract.Requires(DocPath != null);
            Contract.Requires(Directory.Exists(DocPath));
            Contract.Requires(Directory.Exists(Path.Combine(DocPath, ".git")));
            Contract.Requires(Directory.Exists(Path.Combine(DocPath, ArticlesRoot1)));

            // try directory 1 (SDK docs) else directory 2 (Composer docs).
            LinkMap.Clear();
            string dir;

            string[] files;
            try
            {
                dir   = Path.Combine(DocPath, ArticlesRoot1);
                files = Directory.GetFiles(dir, "*.md", SearchOption.AllDirectories);
            }
            catch (IOException)
            {
                dir   = Path.Combine(DocPath, ArticlesRoot2);
                files = Directory.GetFiles(dir, "*.md", SearchOption.AllDirectories);
            }

            var links     = new HashSet <string>();
            var linkCount = 0;

            foreach (var file in files)
            {
                FindLinksInFile(links, file);
                if (links.Count > 0)
                {
                    var relPath = file.Substring(DocPath.Length);
                    LinkMap.Add(relPath, links);
                    linkCount += links.Count;
                }
            }
            if (linkCount is 0)
            {
                Status.WriteLine(Severity.Warning, "No aka links found in this repo.");
                return(false);
            }
            else
            {
                Status.WriteLine(Severity.Information, $"Found {linkCount} aka links: " +
                                 $"{LinkMap.FileIndex.Count} unique files, {LinkMap.LinkIndex.Count} unique URLs.");
                SaveDialog.Title = "Choose where to save the aka link report:";
                var result = SaveDialog.TrySave((writer) =>
                {
                    if (MessageBox.Show("Do you want to test the aka links?", "Test links?",
                                        MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        var results = new Dictionary <string, UrlTestResult>(LinkMap.LinkIndex.Count);

                        Status.WriteLine(Severity.Information, $"Attempting to resolve {LinkMap.LinkIndex.Count} links.");
                        CollectResults(results);
                        Status.WriteLine(Severity.Information, "done.");

                        WriteLongReport(writer);
                    }
                    else
                    {
                        WriteShortReport(writer);
                    }
                });
                Status.WriteLine(result.Sev, result.Message);

                return(true);
            }
        }