private void DownloadObjectImpl(
            string baseUri,
            Stream destination,
            DownloadObjectOptions options,
            IProgress <IDownloadProgress> progress)
        {
            // URI will definitely not be null; that's constructed internally.
            GaxPreconditions.CheckNotNull(destination, nameof(destination));
            var downloader = new HashValidatingDownloader(Service);

            options?.ModifyDownloader(downloader);
            ApplyEncryptionKey(options?.EncryptionKey, downloader);
            string uri = options == null ? baseUri : options.GetUri(baseUri);

            if (progress != null)
            {
                downloader.ProgressChanged += progress.Report;
                progress.Report(InitialDownloadProgress.Instance);
            }
            var result = downloader.Download(uri, destination);

            if (result.Status == DownloadStatus.Failed)
            {
                throw result.Exception;
            }
        }
        private void DownloadObjectImpl(
            RequestBuilder requestBuilder,
            Stream destination,
            DownloadObjectOptions options,
            IProgress <IDownloadProgress> progress)
        {
            // URI will definitely not be null; that's constructed internally.
            GaxPreconditions.CheckNotNull(destination, nameof(destination));
            var downloader = CreateDownloader(options);

            options?.ModifyRequestBuilder(requestBuilder);
            string uri = requestBuilder.BuildUri().AbsoluteUri;

            if (progress != null)
            {
                downloader.ProgressChanged += progress.Report;
                progress.Report(InitialDownloadProgress.Instance);
            }
            var result = downloader.Download(uri, destination);

            if (result.Status == DownloadStatus.Failed)
            {
                throw result.Exception;
            }
        }
        private async Task DownloadObjectAsyncImpl(
            string baseUri,
            Stream destination,
            DownloadObjectOptions options,
            CancellationToken cancellationToken,
            IProgress <IDownloadProgress> progress)
        {
            GaxPreconditions.CheckNotNull(destination, nameof(destination));
            var downloader = new HashValidatingDownloader(Service);

            options?.ModifyDownloader(downloader);
            ApplyEncryptionKey(options?.EncryptionKey, downloader);
            string uri = options == null ? baseUri : options.GetUri(baseUri);

            if (progress != null)
            {
                downloader.ProgressChanged += progress.Report;
                // Avoid reporting progress synchronously in the original call.
                await Task.Yield();

                progress.Report(InitialDownloadProgress.Instance);
            }
            var result = await downloader.DownloadAsync(uri, destination, cancellationToken).ConfigureAwait(false);

            if (result.Status == DownloadStatus.Failed)
            {
                throw result.Exception;
            }
        }
 private Task DownloadObjectAsyncImpl(
     RequestBuilder requestBuilder,
     Stream destination,
     DownloadObjectOptions options,
     CancellationToken cancellationToken,
     IProgress <IDownloadProgress> progress) =>
 // Use Task.Run to prevent reporting progress synchronously in the original call.
 // We used to await Task.Yield(), but that doesn't actually achieve what we want.
 Task.Run(async() =>
 {
     GaxPreconditions.CheckNotNull(destination, nameof(destination));
     var downloader = CreateDownloader(options);
     options?.ModifyRequestBuilder(requestBuilder);
     string uri = requestBuilder.BuildUri().AbsoluteUri;
     if (progress != null)
     {
         downloader.ProgressChanged += progress.Report;
         progress.Report(InitialDownloadProgress.Instance);
     }
     var result = await downloader.DownloadAsync(uri, destination, cancellationToken).ConfigureAwait(false);
     if (result.Status == DownloadStatus.Failed)
     {
         throw result.Exception;
     }
 });
예제 #5
0
 /// <summary>
 /// Downloads the data for an object from storage synchronously, into a specified stream.
 /// </summary>
 /// <remarks>The generation number within <paramref name="source"/> is ignored by this method.
 /// To download a specific generation, use <see cref="DownloadObjectOptions.Generation"/>.
 /// </remarks>
 /// <param name="source">Source object to download the data from. Must not be null.</param>
 /// <param name="destination">The stream to write the data into. Must not be null.</param>
 /// <param name="options">Additional options for the download. May be null, in which case appropriate
 /// defaults will be used.</param>
 /// <param name="progress">Progress reporter for the download. May be null.</param>
 public virtual void DownloadObject(
     Object source,
     Stream destination,
     DownloadObjectOptions options          = null,
     IProgress <IDownloadProgress> progress = null)
 {
     throw new NotImplementedException();
 }
예제 #6
0
 /// <summary>
 /// Downloads the data for an object from storage asynchronously, into a specified stream.
 /// </summary>
 /// <remarks>The generation number within <paramref name="source"/> is ignored by this method.
 /// To download a specific generation, use <see cref="DownloadObjectOptions.Generation"/>.
 /// </remarks>
 /// <param name="source">Source object to download the data from. Must not be null.</param>
 /// <param name="destination">The stream to write the data into. Must not be null.</param>
 /// <param name="options">Additional options for the download. May be null, in which case appropriate
 /// defaults will be used.</param>
 /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
 /// <param name="progress">Progress reporter for the download. May be null.</param>
 /// <returns>A task representing the asynchronous operation.</returns>
 public virtual Task DownloadObjectAsync(
     Object source,
     Stream destination,
     DownloadObjectOptions options          = null,
     CancellationToken cancellationToken    = default,
     IProgress <IDownloadProgress> progress = null)
 {
     throw new NotImplementedException();
 }
        private HashValidatingDownloader CreateDownloader(DownloadObjectOptions options)
        {
            var downloader = new HashValidatingDownloader(Service);

            downloader.ModifyRequest += _versionHeaderAction;
            options?.ModifyDownloader(downloader);
            ApplyEncryptionKey(options?.EncryptionKey, downloader);
            return(downloader);
        }
예제 #8
0
 /// <summary>
 /// Downloads the data for an object from storage synchronously, into a specified stream.
 /// </summary>
 /// <param name="bucket">The name of the bucket containing the object. Must not be null.</param>
 /// <param name="objectName">The name of the object within the bucket. Must not be null.</param>
 /// <param name="destination">The stream to write the data into. Must not be null.</param>
 /// <param name="options">Additional options for the download. May be null, in which case appropriate
 /// defaults will be used.</param>
 /// <param name="progress">Progress reporter for the download. May be null.</param>
 public virtual void DownloadObject(
     string bucket,
     string objectName,
     Stream destination,
     DownloadObjectOptions options          = null,
     IProgress <IDownloadProgress> progress = null)
 {
     throw new NotImplementedException();
 }
        /// <inheritdoc />
        public override void DownloadObject(
            Object source,
            Stream destination,
            DownloadObjectOptions options          = null,
            IProgress <IDownloadProgress> progress = null)
        {
            var builder = CreateRequestBuilder(source);

            DownloadObjectImpl(builder, destination, options, progress);
        }
예제 #10
0
 /// <summary>
 /// Downloads the data for an object from storage asynchronously, into a specified stream.
 /// </summary>
 /// <param name="bucket">The name of the bucket containing the object. Must not be null.</param>
 /// <param name="objectName">The name of the object within the bucket. Must not be null.</param>
 /// <param name="destination">The stream to write the data into. Must not be null.</param>
 /// <param name="options">Additional options for the download. May be null, in which case appropriate
 /// defaults will be used.</param>
 /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
 /// <param name="progress">Progress reporter for the download. May be null.</param>
 /// <returns>A task representing the asynchronous operation.</returns>
 public virtual Task DownloadObjectAsync(
     string bucket,
     string objectName,
     Stream destination,
     DownloadObjectOptions options          = null,
     CancellationToken cancellationToken    = default(CancellationToken),
     IProgress <IDownloadProgress> progress = null)
 {
     throw new NotImplementedException();
 }
        /// <inheritdoc />
        public override void DownloadObject(
            Object source,
            Stream destination,
            DownloadObjectOptions options          = null,
            IProgress <IDownloadProgress> progress = null)
        {
            var baseUri = GetBaseUri(source);

            DownloadObjectImpl(baseUri, destination, options, progress);
        }
        /// <inheritdoc />
        public override Task DownloadObjectAsync(
            Object source,
            Stream destination,
            DownloadObjectOptions options          = null,
            CancellationToken cancellationToken    = default(CancellationToken),
            IProgress <IDownloadProgress> progress = null)
        {
            var baseUri = GetBaseUri(source);

            return(DownloadObjectAsyncImpl(baseUri, destination, options, cancellationToken, progress));
        }
        /// <inheritdoc />
        public override void DownloadObject(
            string bucket,
            string objectName,
            Stream destination,
            DownloadObjectOptions options          = null,
            IProgress <IDownloadProgress> progress = null)
        {
            var baseUri = GetBaseUri(bucket, objectName);

            DownloadObjectImpl(baseUri, destination, options, progress);
        }
        /// <inheritdoc />
        public override void DownloadObject(
            string bucket,
            string objectName,
            Stream destination,
            DownloadObjectOptions options          = null,
            IProgress <IDownloadProgress> progress = null)
        {
            var builder = CreateRequestBuilder(bucket, objectName);

            DownloadObjectImpl(builder, destination, options, progress);
        }
        /// <inheritdoc />
        public override Task DownloadObjectAsync(
            Object source,
            Stream destination,
            DownloadObjectOptions options          = null,
            CancellationToken cancellationToken    = default,
            IProgress <IDownloadProgress> progress = null)
        {
            var builder = CreateRequestBuilder(source);

            return(DownloadObjectAsyncImpl(builder, destination, options, cancellationToken, progress));
        }
예제 #16
0
        /// <inheritdoc />
        public override Task DownloadObjectAsync(
            string bucket,
            string objectName,
            Stream destination,
            DownloadObjectOptions options          = null,
            CancellationToken cancellationToken    = default,
            IProgress <IDownloadProgress> progress = null)
        {
            var baseUri = GetBaseUri(bucket, objectName);

            return(DownloadObjectAsyncImpl(baseUri, destination, options, cancellationToken, progress));
        }
        private MediaDownloader CreateDownloader(DownloadObjectOptions options)
        {
            DownloadValidationMode mode = options?.DownloadValidationMode ?? DownloadValidationMode.Always;

            GaxPreconditions.CheckEnumValue(mode, nameof(DownloadObjectOptions.DownloadValidationMode));

            MediaDownloader downloader = mode == DownloadValidationMode.Never
                ? new MediaDownloader(Service) : new HashValidatingDownloader(Service);

            options?.ModifyDownloader(downloader);
            ApplyEncryptionKey(options?.EncryptionKey, downloader);
            return(downloader);
        }