/// <summary> /// /// </summary> /// <param name="response"></param> /// <param name="progress"></param> /// <param name="cancellationToken"></param> /// <exception cref="OperationCanceledException"></exception> /// <returns></returns> private async Task DownloadFileFromHttpResponseMessage(IWebResponseMessage response, IProgress <DownloadProgress>?progress, CancellationToken cancellationToken) { response.EnsureSuccessStatusCode(); IWebResponseContent content = response?.Content ?? throw new InvalidOperationException("Content is null."); long?totalBytes = content.ContentLength; using (Stream contentStream = await content.ReadAsStreamAsync().ConfigureAwait(false)) await ProcessContentStream(totalBytes, contentStream, progress, cancellationToken).ConfigureAwait(false); }
/// <summary> /// Asynchronously transfers the contents of the <paramref name="webResponseContent"/> to the <see cref="DownloadContainer"/>. /// </summary> /// <param name="webResponseContent"></param> /// <param name="disposeInput"></param> /// <param name="progress"></param> /// <param name="cancellationToken"></param> /// <returns></returns> /// <exception cref="ArgumentNullException"></exception> /// <exception cref="WebClientException"></exception> /// <exception cref="NotSupportedException"></exception> /// <exception cref="ObjectDisposedException"></exception> /// <exception cref="IOException"></exception> public async virtual Task <long> ReceiveDataAsync(IWebResponseContent webResponseContent, bool disposeInput, IProgress <DownloadProgress>?progress, CancellationToken cancellationToken) { if (webResponseContent == null) { throw new ArgumentNullException(nameof(webResponseContent), $"{nameof(webResponseContent)} cannot be null for {nameof(ReceiveDataAsync)}."); } ExpectedInputLength = webResponseContent.ContentLength; return(await ReceiveDataAsync(await webResponseContent.ReadAsStreamAsync().ConfigureAwait(false), disposeInput, progress, cancellationToken).ConfigureAwait(false)); }
/// <summary> /// Asynchronously transfers the contents of the <paramref name="webResponseContent"/> to the <see cref="DownloadContainer"/>. /// </summary> /// <param name="webResponseContent"></param> /// <param name="disposeInput"></param> /// <param name="cancellationToken"></param> /// <returns></returns> /// <exception cref="ArgumentNullException"></exception> /// <exception cref="WebClientException"></exception> /// <exception cref="NotSupportedException"></exception> /// <exception cref="ObjectDisposedException"></exception> /// <exception cref="IOException"></exception> public Task <long> ReceiveDataAsync(IWebResponseContent webResponseContent, bool disposeInput, CancellationToken cancellationToken) => ReceiveDataAsync(webResponseContent, disposeInput, null, cancellationToken);
/// <summary> /// Asynchronously transfers the contents of the <paramref name="webResponseContent"/> to the <see cref="DownloadContainer"/>. /// </summary> /// <param name="webResponseContent"></param> /// <param name="cancellationToken"></param> /// <returns></returns> /// <exception cref="ArgumentNullException"></exception> /// <exception cref="WebClientException"></exception> /// <exception cref="NotSupportedException"></exception> /// <exception cref="ObjectDisposedException"></exception> /// <exception cref="IOException"></exception> public Task <long> ReceiveDataAsync(IWebResponseContent webResponseContent, CancellationToken cancellationToken) => ReceiveDataAsync(webResponseContent, false, null, cancellationToken);