private const bool IsOffline = true; //use it when you don't want to get from GitHub (eg: I have no internet) public async Task <Document> FindDocumentByNameAsync(Project project, string documentName, string version) { var rootUrl = project.ExtraProperties["GithubRootUrl"].ToString().Replace("_version_/", version + "/") .Replace("www.", ""); var token = project.ExtraProperties["GithubAccessToken"]?.ToString(); var rawRootUrl = rootUrl.Replace("github.com", token + "raw.githubusercontent.com").Replace("/tree/", "/"); var rawUrl = rawRootUrl + documentName; var editLink = rootUrl.Replace("/tree/", "/blob/") + documentName; string localDirectory = ""; string fileName = documentName; if (documentName.Contains("/")) { localDirectory = documentName.Substring(0, documentName.LastIndexOf('/')); fileName = documentName.Substring(documentName.LastIndexOf('/') + 1, documentName.Length - documentName.LastIndexOf('/') - 1); } var content = DownloadWebContent(documentName, rawUrl); return(await Task.FromResult(new Document { Title = documentName, Content = content, EditLink = editLink, RootUrl = rootUrl, RawRootUrl = rawRootUrl, Format = project.Format, LocalDirectory = localDirectory, FileName = fileName, Version = version })); }
public async Task <Document> FindDocumentByNameAsync(Project project, string documentName, string version) { var rootUrl = project.ExtraProperties["GithubRootUrl"].ToString().Replace("_version_/", version + "/").Replace("www.", ""); var token = project.ExtraProperties["GithubAccessToken"]?.ToString(); var rawRootUrl = rootUrl.Replace("github.com", token + "raw.githubusercontent.com").Replace("/tree/", "/"); var rawUrl = rawRootUrl + $"{documentName}.md"; var editLink = rootUrl.Replace("/tree/", "/blob/") + $"{documentName}.md"; using (var webClient = new WebClient()) { string content; try { content = webClient.DownloadString(rawUrl); } catch (Exception) { content = "The Document doesn't exist."; } return(new Document { Title = documentName, Content = content, EditLink = editLink, RootUrl = rootUrl, RawRootUrl = rawRootUrl, Format = project.Format }); } }
public async Task <List <VersionInfoDto> > GetVersions(Volo.Docs.Projects.Project project) { try { var token = project.ExtraProperties["GithubAccessToken"]?.ToString(); var gitHubClient = token.IsNullOrWhiteSpace() ? new GitHubClient(new ProductHeaderValue("AbpWebSite")) : new GitHubClient(new ProductHeaderValue("AbpWebSite"), new InMemoryCredentialStore(new Credentials(token))); var url = project.ExtraProperties["GithubRootUrl"].ToString(); var releases = await gitHubClient.Repository.Release.GetAll( GetGithubOrganizationNameFromUrl(url), GetGithubRepositoryNameFromUrl(url) ); return(releases.OrderByDescending(r => r.PublishedAt).Select(r => new VersionInfoDto { Name = r.TagName, DisplayName = r.TagName }).ToList()); } catch (Exception ex) { Logger.LogError(ex.Message, ex); return(new List <VersionInfoDto>()); } }
public async Task <List <string> > GetVersions(Project project, string documentName) { var gitHubClient = new GitHubClient(new ProductHeaderValue("AbpWebSite")); var url = project.ExtraProperties["GithubRootUrl"].ToString(); var releases = await gitHubClient.Repository.Release.GetAll(GetGithubOrganizationNameFromUrl(url), GetGithubRepositoryNameFromUrl(url)); return(releases.OrderByDescending(r => r.PublishedAt).Select(r => r.TagName).ToList()); }