Пример #1
0
        public static async Task <string> GetTocJsonFromGitHubApi(string owner, string repository, string pat)
        {
            var content = await ContentSniffer.DownloadGitHubApiContent(owner, repository, pat, "_kavadocs-project.json");

            if (string.IsNullOrEmpty(content))
            {
                content = await ContentSniffer.DownloadGitHubApiContent(owner, repository, pat, "_toc.json");
            }
            if (string.IsNullOrEmpty(content))
            {
                content = await ContentSniffer.DownloadGitHubApiContent(owner, repository, pat, "_kavadocs/_toc.json");
            }
            if (string.IsNullOrEmpty(content))
            {
                content = await ContentSniffer.DownloadGitHubApiContent(owner, repository, pat, "_meta/_toc.json");                                // TODO: We can get rid of this one eventually
            }
            if (!string.IsNullOrEmpty(content))
            {
                return(content);
            }

            return(string.Empty);

            // TODO: The TOC file didn't exist, so we try to scrape the repository
            //var gitHubRegularUrl = gitHubRawUrl.Replace("raw.githubusercontent.com", "github.com");
            //if (gitHubRegularUrl.EndsWith("/master/")) gitHubRegularUrl = gitHubRegularUrl.Substring(0, gitHubRegularUrl.Length - 7);
            //return await CrawlGitHubForToc(gitHubRegularUrl);
        }
Пример #2
0
        /// <summary>
        /// Gets the toc json from git hub using RAW URLs (rather than the Git API).
        /// </summary>
        /// <param name="gitHubRawUrl">The git hub raw URL.</param>
        /// <returns>Task&lt;System.String&gt;.</returns>
        public static async Task <string> GetTocJsonFromGitHubRaw(string gitHubRawUrl)
        {
            var content = await ContentSniffer.DownloadContent(DownloadMode.HttpGet, gitHubRawUrl + "_kavadocs-project.json");

            if (string.IsNullOrEmpty(content))
            {
                content = await ContentSniffer.DownloadContent(DownloadMode.HttpGet, gitHubRawUrl + "_toc.json");
            }
            if (string.IsNullOrEmpty(content))
            {
                content = await ContentSniffer.DownloadContent(DownloadMode.HttpGet, gitHubRawUrl + "_kavadocs/_toc.json");
            }
            if (string.IsNullOrEmpty(content))
            {
                content = await ContentSniffer.DownloadContent(DownloadMode.HttpGet, gitHubRawUrl + "_meta/_toc.json");                                // TODO: We can get rid of this one eventually
            }
            if (!string.IsNullOrEmpty(content))
            {
                return(content);
            }

            // The TOC file didn't exist, so we try to scrape the repository
            var gitHubRegularUrl = gitHubRawUrl.Replace("raw.githubusercontent.com", "github.com");

            if (gitHubRegularUrl.EndsWith("/master/"))
            {
                gitHubRegularUrl = gitHubRegularUrl.Substring(0, gitHubRegularUrl.Length - 7);
            }
            return(await CrawlGitHubForToc(gitHubRegularUrl));
        }