public static Task WritePagesAsync(this CloudPageBlob blob, byte[] pageData, int start, int count, int startOffset) { MemoryStream stream = null; return Task.Factory.FromAsync( (cb, state) => { stream = new MemoryStream(pageData, start, count); var ar = blob.BeginWritePages(stream, startOffset, null, cb, state); return ar; }, ar => { blob.EndWritePages(ar); stream.Dispose(); }, null); }
/// <summary> /// Writes pages to a page blob asynchronously. /// </summary> /// <param name="pageBlob">Cloud page blob.</param> /// <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="contentMd5"> /// An optional hash value that will be used to set the /// <see cref="P:Microsoft.WindowsAzure.Storage.Blob.BlobProperties.ContentMD5" /> /// property on the blob. May be <c>null</c> or an empty string. /// </param> /// <param name="accessCondition"> /// An <see cref="T:Microsoft.WindowsAzure.Storage.AccessCondition" /> object that represents the access conditions for the blob. If <c>null</c>, no condition is used. /// </param> /// <param name="cancellationToken">Cancellation token.</param> public static Task WritePagesAsync( this CloudPageBlob pageBlob, Stream pageData, long startOffset, string contentMd5 = null, AccessCondition accessCondition = null, CancellationToken cancellationToken = default (CancellationToken)) { ICancellableAsyncResult asyncResult = pageBlob.BeginWritePages(pageData, startOffset, contentMd5, accessCondition, null, null, null, null); CancellationTokenRegistration registration = cancellationToken.Register(p => asyncResult.Cancel(), null); return Task.Factory.FromAsync( asyncResult, result => { registration.Dispose(); pageBlob.EndWritePages(result); }); }
public static Task WritePagesAsync(this CloudPageBlob blob, Stream pageData, int startOffset) { return Task.Factory.FromAsync( (cb, state) => blob.BeginWritePages(pageData, startOffset, null, cb, state), ar => blob.EndWritePages(ar), null); }