Browse Source

Resolved #654: Use async methods in FileSystemDocumentStore.

pull/671/head
Halil ibrahim Kalkan 8 years ago
parent
commit
c38fdd2cf4
  1. 35
      framework/src/Volo.Abp.Core/Volo/Abp/IO/FileHelper.cs
  2. 5
      modules/docs/src/Volo.Docs.Domain/Volo/Docs/FileSystem/Documents/FileSystemDocumentStore.cs

35
framework/src/Volo.Abp.Core/Volo/Abp/IO/FileHelper.cs

@ -1,4 +1,7 @@
using System.IO; using System;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using JetBrains.Annotations; using JetBrains.Annotations;
namespace Volo.Abp.IO namespace Volo.Abp.IO
@ -41,5 +44,35 @@ namespace Volo.Abp.IO
return fileNameWithExtension.Substring(lastDotIndex + 1); return fileNameWithExtension.Substring(lastDotIndex + 1);
} }
/// <summary>
/// Opens a text file, reads all lines of the file, and then closes the file.
/// </summary>
/// <param name="path">The file to open for reading.</param>
/// <returns>A string containing all lines of the file.</returns>
public static async Task<string> ReadAllTextAsync(string path)
{
using (var reader = File.OpenText(path))
{
return await reader.ReadToEndAsync();
}
}
/// <summary>
/// Opens a text file, reads all lines of the file, and then closes the file.
/// </summary>
/// <param name="path">The file to open for reading.</param>
/// <returns>A string containing all lines of the file.</returns>
public static async Task<byte[]> ReadAllBytesAsync(string path)
{
using (var stream = File.Open(path, FileMode.Open))
{
var result = new byte[stream.Length];
await stream.ReadAsync(result, 0, (int)stream.Length);
return result;
}
}
//TODO: ReadAllLinesAsync
} }
} }

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

@ -2,6 +2,7 @@
using System.IO; using System.IO;
using System.Threading.Tasks; using System.Threading.Tasks;
using Volo.Abp.Domain.Services; using Volo.Abp.Domain.Services;
using Volo.Abp.IO;
using Volo.Docs.Documents; using Volo.Docs.Documents;
using Volo.Docs.FileSystem.Projects; using Volo.Docs.FileSystem.Projects;
using Volo.Docs.Projects; using Volo.Docs.Projects;
@ -15,7 +16,7 @@ namespace Volo.Docs.FileSystem.Documents
public async Task<Document> GetDocument(Project project, string documentName, string version) public async Task<Document> GetDocument(Project project, string documentName, string version)
{ {
var path = Path.Combine(project.GetFileSystemPath(), documentName); var path = Path.Combine(project.GetFileSystemPath(), documentName);
var content = File.ReadAllText(path); //TODO: async! var content = await FileHelper.ReadAllTextAsync(path);
var localDirectory = ""; var localDirectory = "";
if (documentName.Contains("/")) if (documentName.Contains("/"))
@ -43,7 +44,7 @@ namespace Volo.Docs.FileSystem.Documents
public async Task<DocumentResource> GetResource(Project project, string resourceName, string version) public async Task<DocumentResource> GetResource(Project project, string resourceName, string version)
{ {
var path = Path.Combine(project.GetFileSystemPath(), resourceName); var path = Path.Combine(project.GetFileSystemPath(), resourceName);
return new DocumentResource(File.ReadAllBytes(path)); return new DocumentResource(await FileHelper.ReadAllBytesAsync(path));
} }
} }
} }

Loading…
Cancel
Save