Пример #1
0
        public async Task <DocumentResource> GetResource(Project project, string resourceName, string languageCode, string version)
        {
            var rawRootUrl = CalculateRawRootUrlWithLanguageCode(project.GetGitHubUrl(version), languageCode);
            var content    = await DownloadWebContentAsByteArrayAsync(
                rawRootUrl + resourceName,
                project.GetGitHubAccessTokenOrNull(),
                project.GetGithubUserAgentOrNull()
                );

            return(new DocumentResource(content));
        }
Пример #2
0
        public async Task <LanguageConfig> GetLanguageListAsync(Project project, string version)
        {
            var token     = project.GetGitHubAccessTokenOrNull();
            var rootUrl   = project.GetGitHubUrl(version);
            var userAgent = project.GetGithubUserAgentOrNull();

            var url = CalculateRawRootUrl(rootUrl) + DocsDomainConsts.LanguageConfigFileName;

            var configAsJson = await DownloadWebContentAsStringAsync(url, token, userAgent);

            if (!JsonConvertExtensions.TryDeserializeObject <LanguageConfig>(configAsJson, out var languageConfig))
            {
                throw new UserFriendlyException($"Cannot validate language config file '{DocsDomainConsts.LanguageConfigFileName}' for the project {project.Name} - v{version}.");
            }

            return(languageConfig);
        }
Пример #3
0
        public virtual async Task <Document> GetDocumentAsync(Project project, string documentName, string languageCode, string version, DateTime?lastKnownSignificantUpdateTime = null)
        {
            var token                = project.GetGitHubAccessTokenOrNull();
            var rootUrl              = project.GetGitHubUrl(version);
            var userAgent            = project.GetGithubUserAgentOrNull();
            var rawRootUrl           = CalculateRawRootUrlWithLanguageCode(rootUrl, languageCode);
            var rawDocumentUrl       = rawRootUrl + 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);
            }

            var content = await DownloadWebContentAsStringAsync(rawDocumentUrl, token, userAgent);

            var commits = await GetGitHubCommitsOrNull(project, documentName, languageCode, version);

            var documentCreationTime      = GetFirstCommitDate(commits);
            var lastUpdateTime            = GetLastCommitDate(commits);
            var lastSignificantUpdateTime = await GetLastKnownSignificantUpdateTime(project, documentName, languageCode, version, lastKnownSignificantUpdateTime, isNavigationDocument, isParameterDocument, commits, documentCreationTime);

            var document = new Document
                           (
                GuidGenerator.Create(),
                project.Id,
                documentName,
                version,
                languageCode,
                fileName,
                content,
                project.Format,
                editLink,
                rootUrl,
                rawRootUrl,
                localDirectory,
                documentCreationTime,
                lastUpdateTime,
                DateTime.Now,
                lastSignificantUpdateTime
                           );

            if (isNavigationDocument || isParameterDocument)
            {
                return(document);
            }

            var authors = GetAuthors(commits);

            foreach (var author in authors)
            {
                document.AddContributor(author.Login, author.HtmlUrl, author.AvatarUrl);
            }

            return(document);
        }