Browse Source

Refactor & add logs.

pull/827/head
Halil ibrahim Kalkan 8 years ago
parent
commit
fcae5e9394
  1. 2
      modules/docs/src/Volo.Docs.Application/Volo/Docs/Documents/DocumentAppService.cs
  2. 2
      modules/docs/src/Volo.Docs.Application/Volo/Docs/Projects/ProjectAppService.cs
  3. 4
      modules/docs/src/Volo.Docs.Domain/Volo/Docs/Documents/IDocumentStore.cs
  4. 4
      modules/docs/src/Volo.Docs.Domain/Volo/Docs/FileSystem/Documents/FileSystemDocumentStore.cs
  5. 12
      modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/GithubDocumentStore.cs

2
modules/docs/src/Volo.Docs.Application/Volo/Docs/Documents/DocumentAppService.cs

@ -95,7 +95,7 @@ namespace Volo.Docs.Documents
async () => async () =>
{ {
var store = _documentStoreFactory.Create(project.DocumentStoreType); var store = _documentStoreFactory.Create(project.DocumentStoreType);
var document = await store.GetDocument(project, documentName, version); var document = await store.GetDocumentAsync(project, documentName, version);
return CreateDocumentWithDetailsDto(project, document); return CreateDocumentWithDetailsDto(project, document);
}, },

2
modules/docs/src/Volo.Docs.Application/Volo/Docs/Projects/ProjectAppService.cs

@ -68,7 +68,7 @@ namespace Volo.Docs.Projects
protected virtual async Task<List<VersionInfo>> GetVersionsAsync(Project project) protected virtual async Task<List<VersionInfo>> GetVersionsAsync(Project project)
{ {
var store = _documentStoreFactory.Create(project.DocumentStoreType); var store = _documentStoreFactory.Create(project.DocumentStoreType);
var versions = await store.GetVersions(project); var versions = await store.GetVersionsAsync(project);
if (!versions.Any()) if (!versions.Any())
{ {

4
modules/docs/src/Volo.Docs.Domain/Volo/Docs/Documents/IDocumentStore.cs

@ -7,9 +7,9 @@ namespace Volo.Docs.Documents
{ {
public interface IDocumentStore : IDomainService public interface IDocumentStore : IDomainService
{ {
Task<Document> GetDocument(Project project, string documentName, string version); Task<Document> GetDocumentAsync(Project project, string documentName, string version);
Task<List<VersionInfo>> GetVersions(Project project); Task<List<VersionInfo>> GetVersionsAsync(Project project);
Task<DocumentResource> GetResource(Project project, string resourceName, string version); Task<DocumentResource> GetResource(Project project, string resourceName, string version);
} }

4
modules/docs/src/Volo.Docs.Domain/Volo/Docs/FileSystem/Documents/FileSystemDocumentStore.cs

@ -14,7 +14,7 @@ namespace Volo.Docs.FileSystem.Documents
{ {
public const string Type = "FileSystem"; public const string Type = "FileSystem";
public async Task<Document> GetDocument(Project project, string documentName, string version) public async Task<Document> GetDocumentAsync(Project project, string documentName, string version)
{ {
var projectFolder = project.GetFileSystemPath(); var projectFolder = project.GetFileSystemPath();
var path = Path.Combine(projectFolder, documentName); var path = Path.Combine(projectFolder, documentName);
@ -41,7 +41,7 @@ namespace Volo.Docs.FileSystem.Documents
}; };
} }
public Task<List<VersionInfo>> GetVersions(Project project) public Task<List<VersionInfo>> GetVersionsAsync(Project project)
{ {
return Task.FromResult(new List<VersionInfo>()); return Task.FromResult(new List<VersionInfo>());
} }

12
modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/GithubDocumentStore.cs

@ -22,7 +22,7 @@ namespace Volo.Docs.GitHub.Documents
{ {
public const string Type = "GitHub"; public const string Type = "GitHub";
public virtual async Task<Document> GetDocument(Project project, string documentName, string version) public virtual async Task<Document> GetDocumentAsync(Project project, string documentName, string version)
{ {
var token = project.GetGitHubAccessTokenOrNull(); var token = project.GetGitHubAccessTokenOrNull();
var rootUrl = project.GetGitHubUrl(version); var rootUrl = project.GetGitHubUrl(version);
@ -56,7 +56,7 @@ namespace Volo.Docs.GitHub.Documents
}; };
} }
public async Task<List<VersionInfo>> GetVersions(Project project) public async Task<List<VersionInfo>> GetVersionsAsync(Project project)
{ {
List<VersionInfo> versions; List<VersionInfo> versions;
try try
@ -148,12 +148,15 @@ namespace Volo.Docs.GitHub.Documents
{ {
try try
{ {
Logger.LogInformation("Downloading content from Github (DownloadWebContentAsStringAsync): " + rawUrl);
using (var webClient = new WebClient()) using (var webClient = new WebClient())
{ {
if (!token.IsNullOrWhiteSpace()) if (!token.IsNullOrWhiteSpace())
{ {
webClient.Headers.Add("Authorization", "token " + token); webClient.Headers.Add("Authorization", "token " + token);
} }
webClient.Headers.Add("User-Agent", userAgent ?? ""); webClient.Headers.Add("User-Agent", userAgent ?? "");
return await webClient.DownloadStringTaskAsync(new Uri(rawUrl)); return await webClient.DownloadStringTaskAsync(new Uri(rawUrl));
@ -171,6 +174,8 @@ namespace Volo.Docs.GitHub.Documents
{ {
try try
{ {
Logger.LogInformation("Downloading content from Github (DownloadWebContentAsByteArrayAsync): " + rawUrl);
using (var webClient = new WebClient()) using (var webClient = new WebClient())
{ {
if (!token.IsNullOrWhiteSpace()) if (!token.IsNullOrWhiteSpace())
@ -219,8 +224,7 @@ namespace Volo.Docs.GitHub.Documents
{ {
Logger.LogWarning(ex.Message); Logger.LogWarning(ex.Message);
} }
return contributors; return contributors;
} }

Loading…
Cancel
Save