本文整理汇总了C#中ILoader.ConvertToDocument方法的典型用法代码示例。如果您正苦于以下问题:C# ILoader.ConvertToDocument方法的具体用法?C# ILoader.ConvertToDocument怎么用?C# ILoader.ConvertToDocument使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ILoader
的用法示例。
在下文中一共展示了ILoader.ConvertToDocument方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadFileAsync
private async Task<Document> LoadFileAsync(ILoader loader, string path, CancellationToken cancellationToken)
{
try
{
using (var file = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, 4096, true))
using (var reader = new StreamReader(file))
{
var count = 0;
var buffer = new char[4096];
while ((count = await reader.ReadAsync(buffer, 0, buffer.Length).ConfigureAwait(false)) > 0)
{
// Check for cancellation
cancellationToken.ThrowIfCancellationRequested();
// Add the data to the document
if (!loader.AddData(buffer, count))
{
throw new IOException("The data could not be added to the loader.");
}
}
return loader.ConvertToDocument();
}
}
catch
{
loader.Release();
throw;
}
}
示例2: LoadDocument
/// <summary>
/// Loads a file using background document loader, background task (outside UI thread)
/// </summary>
/// <param name="loader">ILoader instance created with CreateLoader() method</param>
/// <param name="path"></param>
/// <param name="cancellationToken"></param>
/// <param name="encoding"></param>
/// <param name="detectBOM"></param>
/// <returns></returns>
private async Task<Document> LoadDocument(ILoader loader, string path, CancellationToken cancellationToken, Encoding encoding = null, bool detectBOM = true) {
var buffer = new char[LoadingBufferSize];
var count = 0;
try {
using (var file = new FileStream(path, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite, bufferSize: LoadingBufferSize, useAsync: true)) {
if (encoding != null) Encoding = encoding;
else if (Encoding == null) Encoding = Encoding.UTF8;
using (var reader = new StreamReader(file, Encoding, detectBOM, LoadingBufferSize)) {
while ((count = await reader.ReadAsync(buffer, 0, buffer.Length).ConfigureAwait(false)) > 0) {
cancellationToken.ThrowIfCancellationRequested();
if (!loader.AddData(buffer, count)) throw new IOException("The data could not be added to the loader.");
}
return loader.ConvertToDocument();
}
}
} catch {
loader.Release();
throw;
}
}