Esempio n. 1
0
 /// <summary>
 /// Loads the content from another data transfer object.
 /// </summary>
 /// <param name="source">The content source.</param>
 /// <param name="token">The token that can be used to cancel the operation.</param>
 /// <returns>The task representing asynchronous state of content loading.</returns>
 /// <exception cref="OperationCanceledException">The operation has been canceled.</exception>
 /// <exception cref="NotSupportedException">The underlying stream does not support seeking.</exception>
 public async ValueTask LoadFromAsync(IDataTransferObject source, CancellationToken token = default)
 {
     if (content.CanSeek && content.CanWrite)
     {
         try
         {
             await source.WriteToAsync(content, token : token).ConfigureAwait(false);
         }
         finally
         {
             content.Seek(0, SeekOrigin.Begin);
         }
     }
     else
     {
         throw new NotSupportedException();
     }
 }
Esempio n. 2
0
 ValueTask IBufferedMessage.LoadFromAsync(IDataTransferObject source, CancellationToken token) => source.WriteToAsync(this, BufferSize, token);