/// <summary> /// The <see cref="DownloadToAsync(Uri, string, ContentTransferOptions, CancellationToken)"/> /// operation downloads the specified content using parallel requests, /// and writes the content to <paramref name="destinationPath"/>. /// </summary> /// <param name="sourceEndpoint"> /// A <see cref="Uri"/> with the Recording's content's url location. /// </param> /// <param name="destinationPath"> /// A file path to write the downloaded content to. /// </param> /// <param name="transferOptions"> /// Optional <see cref="ContentTransferOptions"/> to configure /// parallel transfer behavior. /// </param> /// <param name="cancellationToken"> /// Optional <see cref="CancellationToken"/> to propagate /// notifications that the operation should be cancelled. /// </param> /// <returns> /// A <see cref="Response"/> describing the operation. /// </returns> /// <remarks> /// A <see cref="RequestFailedException"/> will be thrown if /// a failure occurs. /// </remarks> public virtual async Task <Response> DownloadToAsync(Uri sourceEndpoint, string destinationPath, ContentTransferOptions transferOptions = default, CancellationToken cancellationToken = default) { using Stream destination = File.Create(destinationPath); return(await _contentDownloader.StagedDownloadAsync(sourceEndpoint, destination, transferOptions, async : true, cancellationToken : cancellationToken).ConfigureAwait(false)); }
/// <summary> /// The <see cref="DownloadTo(Uri, string, ContentTransferOptions, CancellationToken)"/> /// operation downloads the specified content using parallel requests, /// and writes the content to <paramref name="destinationPath"/>. /// </summary> /// <param name="sourceEndpoint"> /// A <see cref="Uri"/> with the Recording's content's url location. /// </param> /// <param name="destinationPath"> /// A file path to write the downloaded content to. /// </param> /// <param name="transferOptions"> /// Optional <see cref="ContentTransferOptions"/> to configure /// parallel transfer behavior. /// </param> /// <param name="cancellationToken"> /// Optional <see cref="CancellationToken"/> to propagate /// notifications that the operation should be cancelled. /// </param> /// <returns> /// A <see cref="Response"/> describing the operation. /// </returns> /// <remarks> /// A <see cref="RequestFailedException"/> will be thrown if /// a failure occurs. /// </remarks> public virtual Response DownloadTo(Uri sourceEndpoint, string destinationPath, ContentTransferOptions transferOptions = default, CancellationToken cancellationToken = default) { using Stream destination = File.Create(destinationPath); return(_contentDownloader.StagedDownloadAsync(sourceEndpoint, destination, transferOptions, async: false, cancellationToken: cancellationToken).EnsureCompleted()); }
internal PartitionedDownloader( CallingServerClient client, ContentTransferOptions transferOptions = default) { _client = client; _maxWorkerCount = transferOptions.MaximumConcurrency; _rangeSize = Math.Min(transferOptions.MaximumTransferSize, Constants.ContentDownloader.Partition.MaxDownloadBytes); _initialRangeSize = transferOptions.InitialTransferSize; }
internal async Task <Response> StagedDownloadAsync(Uri sourceEndpoint, Stream destinationStream, ContentTransferOptions transferOptions = default, bool async = true, CancellationToken cancellationToken = default) { PartitionedDownloader downloader = new(_client, transferOptions); if (async) { return(await downloader.DownloadToAsync(destinationStream, sourceEndpoint, cancellationToken).ConfigureAwait(false)); } else { return(downloader.DownloadTo(destinationStream, sourceEndpoint, cancellationToken)); } }
/// <summary> /// The <see cref="DownloadToAsync(Uri, Stream, ContentTransferOptions, CancellationToken)"/> /// operation downloads the specified content using parallel requests, /// and writes the content to <paramref name="destinationStream"/>. /// </summary> /// <param name="sourceEndpoint"> /// A <see cref="Uri"/> with the Recording's content's url location. /// </param> /// <param name="destinationStream"> /// A <see cref="Stream"/> to write the downloaded content to. /// </param> /// <param name="transferOptions"> /// Optional <see cref="ContentTransferOptions"/> to configure /// parallel transfer behavior. /// </param> /// <param name="cancellationToken"> /// Optional <see cref="CancellationToken"/> to propagate /// notifications that the operation should be cancelled. /// </param> /// <returns> /// A <see cref="Response"/> describing the operation. /// </returns> /// <remarks> /// A <see cref="RequestFailedException"/> will be thrown if /// a failure occurs. /// </remarks> public virtual async Task <Response> DownloadToAsync(Uri sourceEndpoint, Stream destinationStream, ContentTransferOptions transferOptions = default, CancellationToken cancellationToken = default) => await _contentDownloader.StagedDownloadAsync(sourceEndpoint, destinationStream, transferOptions, async : true, cancellationToken : cancellationToken).ConfigureAwait(false);
/// <summary> /// The <see cref="DownloadTo(Uri, Stream, ContentTransferOptions, CancellationToken)"/> /// operation downloads the specified content using parallel requests, /// and writes the content to <paramref name="destinationStream"/>. /// </summary> /// <param name="sourceEndpoint"> /// A <see cref="Uri"/> with the Recording's content's url location. /// </param> /// <param name="destinationStream"> /// A <see cref="Stream"/> to write the downloaded content to. /// </param> /// <param name="transferOptions"> /// Optional <see cref="ContentTransferOptions"/> to configure /// parallel transfer behavior. /// </param> /// <param name="cancellationToken"> /// Optional <see cref="CancellationToken"/> to propagate /// notifications that the operation should be cancelled. /// </param> /// <returns> /// A <see cref="Response"/> describing the operation. /// </returns> /// <remarks> /// A <see cref="RequestFailedException"/> will be thrown if /// a failure occurs. /// </remarks> public virtual Response DownloadTo(Uri sourceEndpoint, Stream destinationStream, ContentTransferOptions transferOptions = default, CancellationToken cancellationToken = default) => _contentDownloader.StagedDownloadAsync(sourceEndpoint, destinationStream, transferOptions, async: false, cancellationToken: cancellationToken).EnsureCompleted();