/// <summary>
        /// Begins an asynchronous operation to delete a table.
        /// </summary>
        /// <param name="tableName">The table name.</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 request.
        /// </returns>
        public IAsyncResult BeginDeleteTable(string tableName, AsyncCallback callback, object state)
        {
            CommonUtils.CheckStringParameter(tableName, false, "tableName", Protocol.Constants.TableServiceMaxStringPropertySizeInChars);
            TableServiceUtilities.CheckTableName(tableName, "tableName");

            return(TaskImplHelper.BeginImplWithRetry(() => this.DeleteTableImpl(tableName), RetryPolicy, callback, state));
        }
示例#2
0
 /// <summary>
 /// Begins an asynchronous operation to return a result segment containing a collection of queues
 /// whose names begin with the specified prefix.
 /// </summary>
 /// <param name="prefix">The queue name prefix.</param>
 /// <param name="detailsIncluded">One of the enumeration values that indicates which details to include in the listing.</param>
 /// <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="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 BeginListQueuesSegmented(string prefix, QueueListingDetails detailsIncluded, int maxResults, ResultContinuation continuationToken, AsyncCallback callback, object state)
 {
     return(TaskImplHelper.BeginImplWithRetry <ResultSegment <CloudQueue> >(
                (setResult) => this.ListQueuesImpl(prefix, detailsIncluded, continuationToken, maxResults, setResult),
                this.RetryPolicy,
                callback,
                state));
 }
示例#3
0
 /// <summary>
 /// Begins an asynchronous operation to save changes, using the retry policy specified for the service context.
 /// </summary>
 /// <param name="options">Additional options for saving changes.</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 BeginSaveChangesWithRetries(SaveChangesOptions options, AsyncCallback callback, object state)
 {
     return(TaskImplHelper.BeginImplWithRetry <DataServiceResponse>(
                (setResult) => this.SaveChangesWithRetriesImpl(options, setResult),
                RetryPolicy,
                callback,
                state));
 }
 /// <summary>
 /// Begins an asynchronous operation to execute a query and return the results as a result segment.
 /// </summary>
 /// <param name="continuationToken">A continuation token returned by a previous listing operation.</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 BeginExecuteSegmented(ResultContinuation continuationToken, AsyncCallback callback, object state)
 {
     return(TaskImplHelper.BeginImplWithRetry <ResultSegment <TElement> >(
                (setResult) => this.ExecuteSegmentedImpl(continuationToken, setResult),
                this.RetryPolicy,
                callback,
                state));
 }
        /// <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));
        }
示例#6
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));
        }
示例#7
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));
        }
 /// <summary>
 /// Begins an asynchronous operation to return a result segment containing a collection
 /// of table names beginning with the specified prefix.
 /// </summary>
 /// <param name="prefix">The table name prefix.</param>
 /// <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="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 BeginListTablesSegmented(string prefix, int maxResults, ResultContinuation continuationToken, AsyncCallback callback, object state)
 {
     return(TaskImplHelper.BeginImplWithRetry <ResultSegment <string> >(
                (setResult) => this.ListTablesSegmentedImpl(
                    prefix,
                    maxResults,
                    continuationToken,
                    setResult),
                this.RetryPolicy,
                callback,
                state));
 }
        /// <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));
        }
示例#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));
        }
示例#12
0
        /// <summary>
        /// Begins an asynchronous operation to retrieve the next result segment.
        /// </summary>
        /// <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 BeginGetNext(AsyncCallback callback, object state)
        {
            CommonUtils.AssertSegmentResultNotComplete <TElement>(this);

            return(TaskImplHelper.BeginImplWithRetry <ResultSegment <TElement> >(this.GetNextImpl, this.retryPolicy, callback, state));
        }
 /// <summary>
 /// Begins an asychronous operation to create a table.
 /// </summary>
 /// <param name="tableName">The table name.</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 BeginCreateTable(string tableName, AsyncCallback callback, object state)
 {
     return(TaskImplHelper.BeginImplWithRetry(() => this.CreateTableImpl(tableName, null), RetryPolicy, callback, state));
 }
示例#14
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));
        }
示例#15
0
        /// <summary>
        /// Performs the read operation.
        /// </summary>
        /// <param name="buffer">The buffer to read the data into.</param>
        /// <param name="offset">The zero-based byte offset in buffer at which to begin storing the data read from the current stream.</param>
        /// <param name="count">The maximum number of bytes to be read from the current stream.</param>
        /// <param name="setResult">The action to be done upon completion to return the number of bytes read.</param>
        /// <returns>A task sequence representing the operation.</returns>
        /// <remarks>
        /// If verification is on, retrieve the blocklist.
        /// If there are downloaded blocks, read from there.
        /// Otherwise, if there's an outstanding request, wait for completion and read from there.
        /// Otherwise perform a new request.
        /// </remarks>
        private TaskSequence ReadImpl(byte[] buffer, int offset, int count, Action <int> setResult)
        {
            if (this.Blob.Properties.BlobType == BlobType.Unspecified)
            {
                this.Blob.FetchAttributes(this.options);
            }

            var origCount = count;

            // If we don't have a blocklist and need it, get it.
            if (this.Blob.Properties.BlobType == BlobType.BlockBlob && this.IntegrityControlVerificationEnabled && this.blockList == null)
            {
                var blockListTask = TaskImplHelper.GetRetryableAsyncTask <IEnumerable <ListBlockItem> >(
                    (result) =>
                {
                    return(this.Blob.ToBlockBlob.GetDownloadBlockList(
                               BlockListingFilter.Committed,
                               this.options,
                               result));
                },
                    this.options.RetryPolicy);

                yield return(blockListTask);

                this.blockList = blockListTask.Result.ToList();

                // Verify we got a blocklist and it's in valid state. This will disable verification if it's invalid state
                this.VerifyBlocks();
            }

            bool readComplete = false;

            // Clear any pending read-aheads
            if (this.readAheadResult != null && this.readAheadResult.IsCompleted)
            {
                this.readAheadResult = null;
            }

            // If we have any data, read existing data
            if (this.downloadedBlocksList.Any())
            {
                readComplete = this.ReadBufferedData(buffer, ref offset, ref count);
            }

            // If we didn't complete our read and have outstanding readAhead, wait on it
            if (!readComplete && this.readAheadResult != null && !this.readAheadResult.IsCompleted)
            {
                this.readAheadResult.AsyncWaitHandle.WaitOne();
                this.readAheadResult = null;

                // We now have more data, so we can do some read
                readComplete = this.ReadBufferedData(buffer, ref offset, ref count);
            }

            long gapStart, gapEnd;

            this.downloadedBlocksList.CalculateGapLength(this.position, count + this.readAheadSize, out gapStart, out gapEnd);

            // Figure out if we need to do a server request. There are two reasons:
            // * We have satisfied the read request, but the remaining data is low enough to warrant a ReadAhead
            // * We didn't satisfy any of the read request and therefore must do it now
            if (this.CalculateIfBufferTooLow(gapStart) || !readComplete)
            {
                long startReadAhead;
                long readAheadCount;
                this.CalculateReadAheadBounds(gapStart, gapEnd, count, out startReadAhead, out readAheadCount);

                var blocksLeft    = startReadAhead != -1;
                var outsideBounds = this.LengthAvailable && (this.Position >= this.Length || startReadAhead >= this.Length);

                // If we didn't find any blocks, that means there's no data left.
                // If we have length, we can ensure we are within bounds. This will prevent extra round trips
                if (!blocksLeft || outsideBounds)
                {
                    setResult(origCount - count);
                    yield break;
                }

                // If we are doing an optional read-ahead, save the async result for future use
                if (readComplete)
                {
                    // We should only have a single outstanding ReadAhed
                    if (this.readAheadResult == null)
                    {
                        this.readAheadResult = TaskImplHelper.BeginImplWithRetry(
                            () =>
                        {
                            return(this.ReadAheadImpl(startReadAhead, readAheadCount));
                        },
                            this.options.RetryPolicy,
                            (result) =>
                        {
                            this.EndReadAhead(result);
                        },
                            null);
                    }
                }
                else
                {
                    var task = TaskImplHelper.GetRetryableAsyncTask(() => this.ReadAheadImpl(startReadAhead, readAheadCount), this.options.RetryPolicy);

                    yield return(task);

                    var scratch = task.Result;

                    // We now have data, so we read it
                    readComplete = this.ReadBufferedData(buffer, ref offset, ref count);
                }
            }

            setResult(origCount - count);
        }
示例#16
0
 /// <summary>
 /// Begins an asynchronous operation to get the properties of the queue service.
 /// </summary>
 /// <param name="callback">The callback delegate that will receive notification when the asynchronous operation completes.</param>
 /// <param name="state">A user defined object to be passed to the callback delegate.</param>
 /// <returns>An <see cref="IAsyncResult"/> that references the asynchronous operation.</returns>
 public IAsyncResult BeginGetServiceProperties(AsyncCallback callback, object state)
 {
     return(TaskImplHelper.BeginImplWithRetry <ServiceProperties>((setResult) => this.GetServicePropertiesImpl(setResult), this.RetryPolicy, callback, state));
 }
示例#17
0
 /// <summary>
 /// Begins an asynchronous operation to set the properties of the queue service.
 /// </summary>
 /// <param name="properties">The queue service properties.</param>
 /// <param name="callback">The callback delegate that will receive notification when the asynchronous operation completes.</param>
 /// <param name="state">A user defined object to be passed to the callback delegate.</param>
 /// <returns>An <see cref="IAsyncResult"/> that references the asynchronous operation.</returns>
 public IAsyncResult BeginSetServiceProperties(ServiceProperties properties, AsyncCallback callback, object state)
 {
     return(TaskImplHelper.BeginImplWithRetry(() => this.SetServicePropertiesImpl(properties), this.RetryPolicy, callback, state));
 }
        /// <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));
        }