Esempio n. 1
0
        public virtual async Task <Document> GetDocumentAsync(Project project, string documentName, string languageCode, string version)
        {
            var token                = project.GetGitHubAccessTokenOrNull();
            var rootUrl              = project.GetGitHubUrl(version);
            var userAgent            = project.GetGithubUserAgentOrNull();
            var rawRootUrl           = CalculateRawRootUrlWithLanguageCode(rootUrl, languageCode);
            var rawDocumentUrl       = rawRootUrl + documentName;
            var commitHistoryUrl     = project.GetGitHubUrlForCommitHistory() + documentName;
            var isNavigationDocument = documentName == project.NavigationDocumentName;
            var isParameterDocument  = documentName == project.ParametersDocumentName;
            var editLink             = rootUrl.ReplaceFirst("/tree/", "/blob/") + languageCode + "/" + documentName;
            var localDirectory       = "";
            var fileName             = documentName;

            if (documentName.Contains("/"))
            {
                localDirectory = documentName.Substring(0, documentName.LastIndexOf('/'));
                fileName       = documentName.Substring(documentName.LastIndexOf('/') + 1);
            }

            return(new Document
            {
                Title = documentName,
                EditLink = editLink,
                RootUrl = rootUrl,
                RawRootUrl = rawRootUrl,
                Format = project.Format,
                LocalDirectory = localDirectory,
                FileName = fileName,
                Contributors = new List <DocumentContributor>(),
                //Contributors = !isNavigationDocument && !isParameterDocument ? await GetContributors(commitHistoryUrl, token, userAgent): new List<DocumentContributor>(),
                Version = version,
                Content = await DownloadWebContentAsStringAsync(rawDocumentUrl, token, userAgent)
            });
        }
Esempio n. 2
0
        public virtual async Task <Document> GetDocument(Project project, string documentName, string version)
        {
            var token            = project.GetGitHubAccessTokenOrNull();
            var rootUrl          = project.GetGitHubUrl(version);
            var rawRootUrl       = CalculateRawRootUrl(rootUrl);
            var rawDocumentUrl   = rawRootUrl + documentName;
            var commitHistoryUrl = project.GetGitHubUrlForCommitHistory() + documentName;
            var editLink         = rootUrl.ReplaceFirst("/tree/", "/blob/") + documentName;
            var localDirectory   = "";
            var fileName         = documentName;

            if (documentName.Contains("/"))
            {
                localDirectory = documentName.Substring(0, documentName.LastIndexOf('/'));
                fileName       = documentName.Substring(documentName.LastIndexOf('/') + 1);
            }

            return(new Document
            {
                Title = documentName,
                EditLink = editLink,
                RootUrl = rootUrl,
                RawRootUrl = rawRootUrl,
                Format = project.Format,
                LocalDirectory = localDirectory,
                FileName = fileName,
                Contributors = await GetContributors(commitHistoryUrl, token),
                Version = version,
                Content = await DownloadWebContentAsStringAsync(rawDocumentUrl, token)
            });
        }