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 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 fileCommits = await GetFileCommitsAsync(project, version, $"docs/{languageCode}/{documentName}"); var document = new Document(GuidGenerator.Create(), project.Id, documentName, version, languageCode, fileName, await DownloadWebContentAsStringAsync(rawDocumentUrl, token, userAgent), project.Format, editLink, rootUrl, rawRootUrl, localDirectory, fileCommits.LastOrDefault()?.Commit.Author.Date.DateTime ?? DateTime.MinValue, fileCommits.FirstOrDefault()?.Commit.Author.Date.DateTime ?? DateTime.MinValue, DateTime.Now); var authors = fileCommits .Where(x => x.Author != null) .Select(x => x.Author) .GroupBy(x => x.Id) .OrderByDescending(x => x.Count()) .Select(x => x.FirstOrDefault()).ToList(); if (!isNavigationDocument && !isParameterDocument) { foreach (var author in authors) { document.AddContributor(author.Login, author.HtmlUrl, author.AvatarUrl); } } return(document); }
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/").EnsureEndsWith('/') + 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); }