/// <summary> /// Begins an asynchronous request to return a result segment containing a collection of blob items. /// </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 BeginListBlobsSegmented(BlobRequestOptions options, AsyncCallback callback, object state) { return(this.BeginListBlobsSegmented(0, null, options, 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)); }
/// <summary> /// Returns a result segment containing a collection of blob items. /// </summary> /// <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(BlobRequestOptions options) { return(this.ListBlobsSegmented(0, null, options)); }
/// <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)); }
/// <summary> /// Implementation method for the WritePage methods. /// </summary> /// <param name="pageData">The page data.</param> /// <param name="startOffset">The start offset.</param> /// <param name="sourceStreamPosition">The beginning position of the source stream prior to execution, negative if stream is unseekable.</param> /// <param name="options">An object that specifies any additional options for the request.</param> /// <returns>A <see cref="TaskSequence"/> that writes the pages.</returns> private TaskSequence WritePageImpl(Stream pageData, long startOffset, long sourceStreamPosition, BlobRequestOptions options) { CommonUtils.AssertNotNull("options", options); long length = pageData.Length; // Logic to rewind stream on a retry // For non seekable streams we need a way to detect the retry iteration so as to only attempt to execute once. // The first attempt will have SourceStreamPosition = -1, which means the first iteration on a non seekable stream. // The second attempt will have SourceStreamPosition = -2, anything below -1 is considered an abort. Since the Impl method // does not have an execution context to be aware of what iteration is used the SourceStreamPosition is utilized as counter to // differentiate between the first attempt and a retry. if (sourceStreamPosition >= 0 && pageData.CanSeek) { if (sourceStreamPosition != pageData.Position) { pageData.Seek(sourceStreamPosition, 0); } } else if (sourceStreamPosition < -1) { // TODO : Need to rewrite this to support buffering in XSCL2 so that retries can work on non seekable streams throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, SR.CannotRetryNonSeekableStreamError)); } if (startOffset % Protocol.Constants.PageSize != 0) { CommonUtils.ArgumentOutOfRange("startOffset", startOffset); } // TODO should reuse sourceStreamPoisition when the HACK above is removed, for readability using a new local variable long rangeStreamOffset = pageData.CanSeek ? pageData.Position : 0; PutPageProperties properties = new PutPageProperties() { Range = new PageRange(startOffset, startOffset + length - rangeStreamOffset - 1), PageWrite = PageWrite.Update, }; if ((1 + properties.Range.EndOffset - properties.Range.StartOffset) % Protocol.Constants.PageSize != 0 || (1 + properties.Range.EndOffset - properties.Range.StartOffset) == 0) { CommonUtils.ArgumentOutOfRange("pageData", pageData); } var webRequest = ProtocolHelper.GetWebRequest( this.ServiceClient, options, (timeout) => BlobRequest.PutPage(this.TransformedAddress, timeout, properties, null)); ////BlobRequest.AddMetadata(webRequest, this.Metadata); // Retrieve the stream var requestStreamTask = webRequest.GetRequestStreamAsync(); yield return(requestStreamTask); // Copy the data using (var outputStream = requestStreamTask.Result) { var copyTask = new InvokeTaskSequenceTask(() => { return(pageData.WriteTo(outputStream)); }); yield return(copyTask); // Materialize any exceptions var scratch = copyTask.Result; } // signing request needs Size to be set this.ServiceClient.Credentials.SignRequest(webRequest); // Get the response var responseTask = webRequest.GetResponseAsyncWithTimeout(this.ServiceClient, options.Timeout); yield return(responseTask); // Parse the response using (HttpWebResponse webResponse = responseTask.Result as HttpWebResponse) { this.ParseSizeAndLastModified(webResponse); } }
/// <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> /// Uploads a file from the file system to a blob. /// </summary> /// <param name="fileName">The path and file name of the file to upload.</param> /// <param name="options">An object that specifies any additional options for the request.</param> /// <exception cref="NotSupportedException">This operation is not supported on objects of type <see cref="CloudPageBlob"/>.</exception> public override void UploadFile(string fileName, BlobRequestOptions options) { throw ThisCreationMethodNotSupportedException(); }
/// <summary> /// Uploads an array of bytes to a blob. /// </summary> /// <param name="content">The array of bytes to upload.</param> /// <param name="options">An object that specifies any additional options for the request.</param> /// <exception cref="NotSupportedException">This operation is not supported on objects of type <see cref="CloudPageBlob"/>.</exception> public override void UploadByteArray(byte[] content, BlobRequestOptions options) { throw ThisCreationMethodNotSupportedException(); }
/// <summary> /// Begins an asynchronous operation to upload a blob from a stream. /// </summary> /// <param name="source">The data stream to upload.</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> /// <exception cref="NotSupportedException">This operation is not supported on objects of type <see cref="CloudPageBlob"/>.</exception> public override IAsyncResult BeginUploadFromStream(Stream source, BlobRequestOptions options, AsyncCallback callback, object state) { throw ThisCreationMethodNotSupportedException(); }
/// <summary> /// Uploads a string of text to a blob. /// </summary> /// <param name="content">The text to upload.</param> /// <param name="encoding">An object indicating the text encoding to use.</param> /// <param name="options">An object that specifies any additional options for the request.</param> /// <exception cref="NotSupportedException">This operation is not supported on objects of type <see cref="CloudPageBlob"/>.</exception> public override void UploadText(string content, Encoding encoding, BlobRequestOptions options) { throw ThisCreationMethodNotSupportedException(); }
/// <summary> /// Uploads a blob from a stream. /// </summary> /// <param name="source">A stream that provides the blob content.</param> /// <param name="options">An object that specifies any additional options for the request.</param> /// <exception cref="NotSupportedException">This operation is not supported on objects of type <see cref="CloudPageBlob"/>.</exception> public override void UploadFromStream(Stream source, BlobRequestOptions options) { throw ThisCreationMethodNotSupportedException(); }
/// <summary> /// Opens a stream for writing to the blob. /// </summary> /// <param name="options">An object that specifies any additional options for the request.</param> /// <returns>A stream for writing to the blob.</returns> /// <exception cref="NotSupportedException">This operation is not supported on objects of type <see cref="CloudPageBlob"/>.</exception> public override BlobStream OpenWrite(BlobRequestOptions options) { throw ThisCreationMethodNotSupportedException(); }
/// <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); }
/// <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)); }
/// <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); }