Exemplo n.º 1
0
        private async Task DownloadObjectAsyncImpl(
            string baseUri,
            Stream destination,
            DownloadObjectOptions options,
            CancellationToken cancellationToken,
            IProgress <IDownloadProgress> progress)
        {
            Preconditions.CheckNotNull(destination, nameof(destination));
            var downloader = new MediaDownloader(Service);

            options?.ModifyDownloader(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;
            }
        }
Exemplo n.º 2
0
        private void DownloadObjectImpl(
            string baseUri,
            Stream destination,
            DownloadObjectOptions options,
            IProgress <IDownloadProgress> progress)
        {
            // URI will definitely not be null; that's constructed internally.
            Preconditions.CheckNotNull(destination, nameof(destination));
            var downloader = new MediaDownloader(Service);

            options?.ModifyDownloader(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;
            }
        }
Exemplo n.º 3
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();
 }
Exemplo n.º 4
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(CancellationToken),
     IProgress <IDownloadProgress> progress = null)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 5
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();
 }
Exemplo n.º 6
0
        /// <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);
        }
Exemplo n.º 7
0
        /// <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));
        }
Exemplo n.º 8
0
        /// <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);
        }
Exemplo n.º 9
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 Task DownloadObjectAsync(
            string bucket,
            string objectName,
            Stream destination,
            DownloadObjectOptions options          = null,
            CancellationToken cancellationToken    = default(CancellationToken),
            IProgress <IDownloadProgress> progress = null)
        {
            var baseUri = GetBaseUri(bucket, objectName);

            return(DownloadObjectAsyncImpl(baseUri, destination, options, cancellationToken, progress));
        }