/// <summary>
        /// Uploads a list of blocks to a new or existing blob.
        /// </summary>
        /// <param name="blockList">An enumerable collection of block IDs, as base64-encoded strings.</param>
        /// <param name="options">An object that specifies any additional options for the request.</param>
        public void PutBlockList(IEnumerable <string> blockList, BlobRequestOptions options)
        {
            var fullModifier = BlobRequestOptions.CreateFullModifier(this.ServiceClient, options);

            List <PutBlockListItem> items = blockList.Select(i => { return(new PutBlockListItem(i, BlockSearchMode.Latest)); }).ToList();

            TaskImplHelper.ExecuteImplWithRetry(() => { return(this.UploadBlockList(items, fullModifier)); }, fullModifier.RetryPolicy);
        }
Exemple #2
0
        /// <summary>
        /// Gets a collection of page ranges and their starting and ending bytes.
        /// </summary>
        /// <param name="options">An object that specifies any additional options for the request.</param>
        /// <returns>An enumerable collection of page ranges.</returns>
        public IEnumerable <PageRange> GetPageRanges(BlobRequestOptions options)
        {
            var fullModifiers = BlobRequestOptions.CreateFullModifier(this.ServiceClient, options);

            return(TaskImplHelper.ExecuteImplWithRetry <IEnumerable <PageRange> >(
                       (setResult) => this.GetPageRangesImpl(fullModifiers, setResult),
                       fullModifiers.RetryPolicy));
        }
        /// <summary>
        /// Begins an asynchronous operation to upload a list of blocks to a new or existing blob.
        /// </summary>
        /// <param name="blockList">An enumerable collection of block IDs, as base64-encoded strings.</param>
        /// <param name="options">An object that specifies any additional options for the request.</param>
        /// <param name="callback">The callback delegate that will receive notification when the asynchronous operation completes.</param>
        /// <param name="state">A user-defined object that will be passed to the callback delegate.</param>
        /// <returns>An <see cref="IAsyncResult"/> that references the asynchronous operation.</returns>
        public IAsyncResult BeginPutBlockList(IEnumerable <string> blockList, BlobRequestOptions options, AsyncCallback callback, object state)
        {
            var fullModifier = BlobRequestOptions.CreateFullModifier(this.ServiceClient, options);

            List <PutBlockListItem> items = blockList.Select(i => { return(new PutBlockListItem(i, BlockSearchMode.Latest)); }).ToList();

            return(TaskImplHelper.BeginImplWithRetry(() => { return this.UploadBlockList(items, fullModifier); }, fullModifier.RetryPolicy, callback, state));
        }
Exemple #4
0
        /// <summary>
        /// Begins an asynchronous operation to return a collection of page ranges and their starting and ending bytes.
        /// </summary>
        /// <param name="options">An object that specifies any additional options for the request.</param>
        /// <param name="callback">The callback delegate that will receive notification when the asynchronous operation completes.</param>
        /// <param name="state">A user-defined object that will be passed to the callback delegate.</param>
        /// <returns>An <see cref="IAsyncResult"/> that references the asynchronous operation.</returns>
        public IAsyncResult BeginGetPageRanges(BlobRequestOptions options, AsyncCallback callback, object state)
        {
            var fullModifiers = BlobRequestOptions.CreateFullModifier(this.ServiceClient, options);

            return(TaskImplHelper.BeginImplWithRetry <IEnumerable <PageRange> >(
                       (setResult) => this.GetPageRangesImpl(fullModifiers, setResult),
                       fullModifiers.RetryPolicy,
                       callback,
                       state));
        }
Exemple #5
0
        /// <summary>
        /// Begins an asynchronous operation to clear pages from a page blob.
        /// </summary>
        /// <param name="startOffset">The offset at which to begin clearing pages, in bytes. The offset must be a multiple of 512.</param>
        /// <param name="length">The length of the data range to be cleared, in bytes. The length must be a multiple of 512.</param>
        /// <param name="options">An object that specifies any additional options for the request.</param>
        /// <param name="callback">The callback delegate that will receive notification when the asynchronous operation completes.</param>
        /// <param name="state">A user-defined object that will be passed to the callback delegate.</param>
        /// <returns>An <see cref="IAsyncResult"/> that references the asynchronous operation.</returns>
        public IAsyncResult BeginClearPages(long startOffset, long length, BlobRequestOptions options, AsyncCallback callback, object state)
        {
            var fullModifiers = BlobRequestOptions.CreateFullModifier(this.ServiceClient, options);

            return(TaskImplHelper.BeginImplWithRetry(
                       () => this.ClearPageImpl(startOffset, length, fullModifiers),
                       fullModifiers.RetryPolicy,
                       callback,
                       state));
        }
        /// <summary>
        /// Returns an enumerable collection of the blob's blocks, using the specified block list filter.
        /// </summary>
        /// <param name="blockListingFilter">One of the enumeration values that indicates whether to return
        /// committed blocks, uncommitted blocks, or both.</param>
        /// <param name="options">An object that specifies any additional options for the request.</param>
        /// <returns>An enumerable collection of objects implementing <see cref="ListBlockItem"/>.</returns>
        public IEnumerable <ListBlockItem> DownloadBlockList(BlockListingFilter blockListingFilter, BlobRequestOptions options)
        {
            var fullModifier = BlobRequestOptions.CreateFullModifier(this.ServiceClient, options);

            return(TaskImplHelper.ExecuteImplWithRetry <IEnumerable <ListBlockItem> >(
                       (result) =>
            {
                return this.GetDownloadBlockList(blockListingFilter, fullModifier, result);
            },
                       fullModifier.RetryPolicy));
        }
        /// <summary>
        /// Begins an asynchronous operation to return an enumerable collection of the blob's blocks,
        /// using the specified block list filter.
        /// </summary>
        /// <param name="blockListingFilter">One of the enumeration values that indicates whether to return
        /// committed blocks, uncommitted blocks, or both.</param>
        /// <param name="options">An object that specifies any additional options for the request.</param>
        /// <param name="callback">The callback delegate that will receive notification when the asynchronous operation completes.</param>
        /// <param name="state">A user-defined object that will be passed to the callback delegate.</param>
        /// <returns>An <see cref="IAsyncResult"/> that references the asynchronous operation.</returns>
        public IAsyncResult BeginDownloadBlockList(BlockListingFilter blockListingFilter, BlobRequestOptions options, AsyncCallback callback, object state)
        {
            var fullModifier = BlobRequestOptions.CreateFullModifier(this.ServiceClient, options);

            return(TaskImplHelper.BeginImplWithRetry <IEnumerable <ListBlockItem> >(
                       (result) =>
            {
                return this.GetDownloadBlockList(blockListingFilter, fullModifier, result);
            },
                       fullModifier.RetryPolicy,
                       callback,
                       state));
        }
Exemple #8
0
        /// <summary>
        /// Writes pages to a page blob.
        /// </summary>
        /// <param name="pageData">A stream providing the page data.</param>
        /// <param name="startOffset">The offset at which to begin writing, in bytes. The offset must be a multiple of 512.</param>
        /// <param name="options">An object that specifies any additional options for the request.</param>
        public void WritePages(Stream pageData, long startOffset, BlobRequestOptions options)
        {
            var fullModifiers = BlobRequestOptions.CreateFullModifier(this.ServiceClient, options);

            long sourcePosition = pageData.CanSeek ? pageData.Position : 0;

            TaskImplHelper.ExecuteImplWithRetry(
                () =>
            {
                if (pageData.CanSeek == false)
                {
                    sourcePosition--;
                }

                return(this.WritePageImpl(pageData, startOffset, sourcePosition, fullModifiers));
            },
                fullModifiers.RetryPolicy);
        }
        /// <summary>
        /// Uploads a single block.
        /// </summary>
        /// <param name="blockId">A base64-encoded block ID that identifies the block.</param>
        /// <param name="blockData">A stream that provides the data for the block.</param>
        /// <param name="contentMD5">An optional hash value that will be used to set the <see cref="BlobProperties.ContentMD5"/> property
        /// on the blob. May be <c>null</c> or an empty string.</param>
        /// <param name="options">An object that specifies any additional options for the request.</param>
        public void PutBlock(string blockId, Stream blockData, string contentMD5, BlobRequestOptions options)
        {
            var fullModifier = BlobRequestOptions.CreateFullModifier(this.ServiceClient, options);
            var position     = blockData.Position;
            var retryPolicy  = blockData.CanSeek ? fullModifier.RetryPolicy : RetryPolicies.NoRetry();

            TaskImplHelper.ExecuteImplWithRetry(
                () =>
            {
                if (blockData.CanSeek)
                {
                    blockData.Position = position;
                }

                return(this.UploadBlock(blockData, blockId, contentMD5, fullModifier));
            },
                retryPolicy);
        }
Exemple #10
0
        /// <summary>
        /// Begins an asynchronous operation to write pages to a page blob.
        /// </summary>
        /// <param name="pageData">A stream providing the page data.</param>
        /// <param name="startOffset">The offset at which to begin writing, in bytes. The offset must be a multiple of 512.</param>
        /// <param name="options">An object that specifies any additional options for the request.</param>
        /// <param name="callback">The callback delegate that will receive notification when the asynchronous operation completes.</param>
        /// <param name="state">A user-defined object that will be passed to the callback delegate.</param>
        /// <returns>An <see cref="IAsyncResult"/> that references the asynchronous operation.</returns>
        public IAsyncResult BeginWritePages(Stream pageData, long startOffset, BlobRequestOptions options, AsyncCallback callback, object state)
        {
            var fullModifiers = BlobRequestOptions.CreateFullModifier(this.ServiceClient, options);

            long sourcePosition = pageData.CanSeek ? pageData.Position : 0;

            return(TaskImplHelper.BeginImplWithRetry(
                       () =>
            {
                if (pageData.CanSeek == false)
                {
                    sourcePosition--;
                }

                return this.WritePageImpl(pageData, startOffset, sourcePosition, fullModifiers);
            },
                       fullModifiers.RetryPolicy,
                       callback,
                       state));
        }
        /// <summary>
        /// Begins an asynchronous operation to upload a single block.
        /// </summary>
        /// <param name="blockId">A base64-encoded block ID that identifies the block.</param>
        /// <param name="blockData">A stream that provides the data for the block.</param>
        /// <param name="contentMD5">An optional hash value that will be used to set the <see cref="BlobProperties.ContentMD5"/> property
        /// on the blob. May be <c>null</c> or an empty string.</param>
        /// <param name="options">An object that specifies any additional options for the request.</param>
        /// <param name="callback">The callback delegate that will receive notification when the asynchronous operation completes.</param>
        /// <param name="state">A user-defined object that will be passed to the callback delegate.</param>
        /// <returns>An <see cref="IAsyncResult"/> that references the asynchronous operation.</returns>
        public IAsyncResult BeginPutBlock(string blockId, Stream blockData, string contentMD5, BlobRequestOptions options, AsyncCallback callback, object state)
        {
            var fullModifier = BlobRequestOptions.CreateFullModifier(this.ServiceClient, options);
            var position     = blockData.Position;
            var retryPolicy  = blockData.CanSeek ? fullModifier.RetryPolicy : RetryPolicies.NoRetry();

            return(TaskImplHelper.BeginImplWithRetry(
                       () =>
            {
                if (blockData.CanSeek)
                {
                    blockData.Position = position;
                }

                return this.UploadBlock(blockData, blockId, contentMD5, fullModifier);
            },
                       retryPolicy,
                       callback,
                       state));
        }
        /// <summary>
        /// Returns an enumerable collection of blob items in this virtual directory that is lazily retrieved, either as a flat listing or by virtual subdirectory.
        /// </summary>
        /// <param name="options">An object that specifies any additional options for the request.</param>
        /// <returns>An enumerable collection of objects that implement <see cref="IListBlobItem"/> and are retrieved lazily.</returns>
        public IEnumerable <IListBlobItem> ListBlobs(BlobRequestOptions options)
        {
            var fullModifiers = BlobRequestOptions.CreateFullModifier(this.ServiceClient, options);

            return(CommonUtils.LazyEnumerateSegmented <IListBlobItem>((setResult) => this.Container.ListBlobsImpl(this.Prefix, fullModifiers, null, null, setResult), fullModifiers.RetryPolicy));
        }
        /// <summary>
        /// Begins an asynchronous request to return a result segment containing a collection of blob items.
        /// </summary>
        /// <param name="maxResults">A non-negative integer value that indicates the maximum number of results to be returned at a time, up to the
        /// per-operation limit of 5000. If this value is zero, the maximum possible number of results will be returned, up to 5000.</param>
        /// <param name="continuationToken">A continuation token returned by a previous listing operation.</param>
        /// <param name="options">An object that specifies any additional options for the request.</param>
        /// <param name="callback">The callback delegate that will receive notification when the asynchronous operation completes.</param>
        /// <param name="state">A user-defined object that will be passed to the callback delegate.</param>
        /// <returns>An <see cref="IAsyncResult"/> that references the asynchronous operation.</returns>
        public IAsyncResult BeginListBlobsSegmented(int maxResults, ResultContinuation continuationToken, BlobRequestOptions options, AsyncCallback callback, object state)
        {
            var fullModifiers = BlobRequestOptions.CreateFullModifier(this.ServiceClient, options);

            return(TaskImplHelper.BeginImplWithRetry <ResultSegment <IListBlobItem> >((setResult) => this.Container.ListBlobsImpl(this.Prefix, fullModifiers, continuationToken, maxResults, setResult), fullModifiers.RetryPolicy, callback, state));
        }
Exemple #14
0
        /// <summary>
        /// Clears pages from a page blob.
        /// </summary>
        /// <param name="startOffset">The offset at which to begin clearing pages, in bytes. The offset must be a multiple of 512.</param>
        /// <param name="length">The length of the data range to be cleared, in bytes. The length must be a multiple of 512.</param>
        /// <param name="options">An object that specifies any additional options for the request.</param>
        public void ClearPages(long startOffset, long length, BlobRequestOptions options)
        {
            var fullModifiers = BlobRequestOptions.CreateFullModifier(this.ServiceClient, options);

            TaskImplHelper.ExecuteImplWithRetry(() => this.ClearPageImpl(startOffset, length, fullModifiers), fullModifiers.RetryPolicy);
        }
Exemple #15
0
        /// <summary>
        /// Begins an asynchronous operation to create a page blob.
        /// </summary>
        /// <param name="size">The maximum size of the blob, in bytes.</param>
        /// <param name="options">An object that specifies any additional options for the request.</param>
        /// <param name="callback">The callback delegate that will receive notification when the asynchronous operation completes.</param>
        /// <param name="state">A user-defined object that will be passed to the callback delegate.</param>
        /// <returns>An <see cref="IAsyncResult"/> that references the asynchronous operation.</returns>
        public IAsyncResult BeginCreate(long size, BlobRequestOptions options, AsyncCallback callback, object state)
        {
            var fullModifiers = BlobRequestOptions.CreateFullModifier(this.ServiceClient, options);

            return(TaskImplHelper.BeginImplWithRetry(() => this.CreateImpl(fullModifiers, size), fullModifiers.RetryPolicy, callback, state));
        }
Exemple #16
0
        /// <summary>
        /// Creates a page blob.
        /// </summary>
        /// <param name="size">The maximum size of the page blob, in bytes.</param>
        /// <param name="options">An object that specifies any additional options for the request.</param>
        public void Create(long size, BlobRequestOptions options)
        {
            var fullModifiers = BlobRequestOptions.CreateFullModifier(this.ServiceClient, options);

            TaskImplHelper.ExecuteImplWithRetry(() => this.CreateImpl(fullModifiers, size), fullModifiers.RetryPolicy);
        }
        /// <summary>
        /// Returns a result segment containing a collection of blob items.
        /// </summary>
        /// <param name="maxResults">A non-negative integer value that indicates the maximum number of results to be returned at a time, up to the
        /// per-operation limit of 5000. If this value is zero, the maximum possible number of results will be returned, up to 5000.</param>
        /// <param name="continuationToken">A continuation token returned by a previous listing operation.</param>
        /// <param name="options">An object that specifies any additional options for the request.</param>
        /// <returns>A result segment containing objects that implement <see cref="IListBlobItem"/>.</returns>
        public ResultSegment <IListBlobItem> ListBlobsSegmented(int maxResults, ResultContinuation continuationToken, BlobRequestOptions options)
        {
            var fullModifiers = BlobRequestOptions.CreateFullModifier(this.ServiceClient, options);

            return(TaskImplHelper.ExecuteImplWithRetry <ResultSegment <IListBlobItem> >((setResult) => this.Container.ListBlobsImpl(this.Prefix, fullModifiers, continuationToken, maxResults, setResult), fullModifiers.RetryPolicy));
        }