/// <summary> /// Implements the Create method. /// </summary> /// <param name="options">An object that specifies any additional options for the request.</param> /// <param name="sizeInBytes">The size in bytes.</param> /// <returns>A <see cref="TaskSequence"/> that creates the blob.</returns> private TaskSequence CreateImpl(BlobRequestOptions options, long sizeInBytes) { CommonUtils.AssertNotNull("options", options); this.Properties.BlobType = BlobType.PageBlob; var webRequest = ProtocolHelper.GetWebRequest( this.ServiceClient, options, (timeout) => BlobRequest.Put(this.TransformedAddress, timeout, this.Properties, BlobType.PageBlob, null, sizeInBytes)); BlobRequest.AddMetadata(webRequest, this.Metadata); this.ServiceClient.Credentials.SignRequest(webRequest); var task = webRequest.GetResponseAsyncWithTimeout(this.ServiceClient, options.Timeout); yield return(task); // Parse the response using (HttpWebResponse webResponse = task.Result as HttpWebResponse) { this.ParseSizeAndLastModified(webResponse); } }
/// <summary> /// Gets the page ranges impl. /// </summary> /// <param name="options">An object that specifies any additional options for the request.</param> /// <param name="setResult">The set result.</param> /// <returns>A <see cref="TaskSequence"/> for getting the page ranges.</returns> private TaskSequence GetPageRangesImpl(BlobRequestOptions options, Action <IEnumerable <PageRange> > setResult) { CommonUtils.AssertNotNull("options", options); var webRequest = ProtocolHelper.GetWebRequest(this.ServiceClient, options, (timeout) => BlobRequest.GetPageRanges(this.TransformedAddress, timeout, this.SnapshotTime, null)); BlobRequest.AddMetadata(webRequest, this.Metadata); this.ServiceClient.Credentials.SignRequest(webRequest); var task = webRequest.GetResponseAsyncWithTimeout(this.ServiceClient, options.Timeout); yield return(task); using (var webResponse = task.Result as HttpWebResponse) { var getPageRangesResponse = BlobResponse.GetPageRanges(webResponse); List <PageRange> pageRanges = new List <PageRange>(); // materialize response as we need to close the webResponse pageRanges.AddRange(getPageRangesResponse.PageRanges.ToList()); setResult(pageRanges); this.ParseSizeAndLastModified(webResponse); } }
/// <summary> /// Uploads the block list. /// </summary> /// <param name="blocks">The blocks to upload.</param> /// <param name="options">An object that specifies any additional options for the request.</param> /// <returns>A <see cref="TaskSequence"/> that uploads the block list.</returns> internal TaskSequence UploadBlockList(List <PutBlockListItem> blocks, BlobRequestOptions options) { if (options == null) { throw new ArgumentNullException("modifers"); } var request = ProtocolHelper.GetWebRequest(this.ServiceClient, options, (timeout) => BlobRequest.PutBlockList(this.TransformedAddress, timeout, this.Properties, null)); options.AccessCondition.ApplyCondition(request); BlobRequest.AddMetadata(request, this.Metadata); using (var memoryStream = new SmallBlockMemoryStream(Constants.DefaultBufferSize)) { BlobRequest.WriteBlockListBody(blocks, memoryStream); CommonUtils.ApplyRequestOptimizations(request, memoryStream.Length); memoryStream.Seek(0, SeekOrigin.Begin); // Compute the MD5 var md5 = System.Security.Cryptography.MD5.Create(); request.Headers[HttpRequestHeader.ContentMd5] = Convert.ToBase64String(md5.ComputeHash(memoryStream)); this.ServiceClient.Credentials.SignRequest(request); memoryStream.Seek(0, SeekOrigin.Begin); // Retrieve the stream var requestStreamTask = request.GetRequestStreamAsync(); yield return(requestStreamTask); using (Stream requestStream = requestStreamTask.Result) { // Copy the data var copyTask = new InvokeTaskSequenceTask(() => { return(memoryStream.WriteTo(requestStream)); }); yield return(copyTask); // Materialize any exceptions var scratch = copyTask.Result; Console.WriteLine(scratch); } } // Get the response var responseTask = request.GetResponseAsyncWithTimeout(this.ServiceClient, options.Timeout); yield return(responseTask); using (var response = responseTask.Result as HttpWebResponse) { ParseSizeAndLastModified(response); this.Properties.Length = 0; } }