예제 #1
0
 /// <summary>
 /// Downloads the file's contents as a string.
 /// </summary>
 /// <param name="accessCondition">An <see cref="AccessCondition"/> object that represents the access conditions for the file.</param>
 /// <param name="options">An object that specifies additional options for the request.</param>
 /// <param name="operationContext">An <see cref="OperationContext"/> object that represents the context for the current operation.</param>
 /// <param name="cancellationToken">A <see cref="CancellationToken"/> to observe while waiting for a task to complete.</param>
 /// <returns>The contents of the file, as a string.</returns>
 public Task<string> DownloadTextAsync(AccessCondition accessCondition, FileRequestOptions options, OperationContext operationContext, CancellationToken cancellationToken)
 {
     return Task.Run(async () =>
     {
         using (SyncMemoryStream stream = new SyncMemoryStream())
         {
             await this.DownloadToStreamAsync(stream, accessCondition, options, operationContext, cancellationToken);
             byte[] streamAsBytes = stream.ToArray();
             return Encoding.UTF8.GetString(streamAsBytes, 0, streamAsBytes.Length);
         }
     }, cancellationToken);
 }
예제 #2
0
 public IAsyncOperation<string> DownloadTextAsync(AccessCondition accessCondition, FileRequestOptions options, OperationContext operationContext)
 {
     return AsyncInfo.Run(async (token) =>
     {
         using (SyncMemoryStream stream = new SyncMemoryStream())
         {
             await this.DownloadToStreamAsync(stream.AsOutputStream(), accessCondition, options, operationContext).AsTask(token);
             byte[] streamAsBytes = stream.ToArray();
             return Encoding.UTF8.GetString(streamAsBytes, 0, streamAsBytes.Length);
         }
     });
 }