(0) exportieren Drucken
Alle erweitern

CloudPageBlob.WritePages-Methode (Stream, Int64, BlobRequestOptions)

Writes pages to a page blob.

Namespace: Microsoft.WindowsAzure.StorageClient
Assembly: Microsoft.WindowsAzure.StorageClient (in microsoft.windowsazure.storageclient.dll)

'Usage
Dim instance As CloudPageBlob
Dim pageData As Stream
Dim startOffset As Long
Dim options As BlobRequestOptions

instance.WritePages(pageData, startOffset, options)

public void WritePages (
	Stream pageData,
	long startOffset,
	BlobRequestOptions options
)
public void WritePages (
	Stream pageData, 
	long startOffset, 
	BlobRequestOptions options
)
public function WritePages (
	pageData : Stream, 
	startOffset : long, 
	options : BlobRequestOptions
)

Parameter

pageData

A stream providing the page data.

startOffset

The offset at which to begin writing, in bytes. The offset must be a multiple of 512.

options

An object that specifies any additional options for the request.

The following code example creates a page blob, writes some pages to it, and prints out the page ranges to the console.

static void WriteToPageBlob(Uri blobEndpoint, string accountName, string accountKey)
{
    //Create service client for credentialed access to the Blob service.
    CloudBlobClient blobClient = new CloudBlobClient(blobEndpoint, new StorageCredentialsAccountAndKey(accountName, accountKey));

    // create container if it does not exist
    CloudBlobContainer cloudContainer = blobClient.GetContainerReference("mypageblobs");
    cloudContainer.CreateIfNotExist();

    //Get a reference to the page blob that will be created.
    CloudPageBlob pageBlob = cloudContainer.GetPageBlobReference("apageblob");

    //Generate some data to write.  
    byte[] data = new byte[1024];
    Random rnd = new Random();
    rnd.NextBytes(data);

    //Create a 100 MB page blob.
    pageBlob.Create(100 * 1024 * 1024);

    //Write two sets of pages. Note that you can write 4 MB per call to WritePages().
    pageBlob.WritePages(new MemoryStream(data), 0);
    pageBlob.WritePages(new MemoryStream(data), 4096);

    //Populate the page blob's attributes.
    pageBlob.FetchAttributes();
    Console.WriteLine("Blob length = {0}", pageBlob.Properties.Length);

    //Print out the current range of pages.
    PrintPageRanges("Before write to 10240:", pageBlob);

    //Write another page.
    pageBlob.WritePages(new MemoryStream(data), 10240);

    //Print out the new range of pages.
    PrintPageRanges("After write to 10240:", pageBlob);

    //Clear a page.
    pageBlob.ClearPages(4096, 1024);

    //Print out the new range of pages.
    PrintPageRanges("After clearing page at 4096:", pageBlob);

    //Delete the page blob.
    pageBlob.Delete();
}

static void PrintPageRanges(string msg, CloudPageBlob cloudBlob)
{
    //Write out the page ranges for the page blob.
    IEnumerable<PageRange> ranges = cloudBlob.GetPageRanges();
            
    Console.Write("{0}:<", msg);
            
    foreach (PageRange range in ranges)
    {
        Console.Write(" [{0}-{1}] ", range.StartOffset, range.EndOffset);
    }

    Console.WriteLine(">");
}

The WritePages method writes a range of pages to a page blob. This method can only be called on an existing page blob; it cannot be called to create a new page blob.

Each range of pages submitted with WritePages may be up to 4 MB in size. The start and end range of the page must be aligned with 512-byte boundaries.

The Blob service serializes concurrent writes to overlapping pages sequentially: the last page processed by the service determines the blob's content. Therefore, to ensure the integrity of the blob's content, you should handle writes to overlapping pages using one or more of the following approaches:

  • You can check the value of the blob's LastModifiedUtc property for each successful call to WritePages. The order of responses returned from the Blob service does not necessarily correspond to the order in which they were executed by the service. But the last modified time always indicates the order in which the service processed the requests.

  • You can perform updates conditionally based on the blob's ETag or last modified time using optimistic concurrency. This approach works well if the number of concurrent writes is relatively low. Specify an access condition using the AccessCondition property of the BlobRequestOptions class.

  • You can acquire a least on the blob to lock it against other writes. See the Lease method of the BlobRequest class.


Alle öffentlichen statischen (freigegebenen in Visual Basic) Member dieses Typs sind threadsicher. Bei Instanzmembern ist die Threadsicherheit nicht gewährleistet.

Entwicklungsplattformen

Windows XP Home Edition, Windows XP Professional, Windows Server 2003, Windows Server 2008 und Windows 2000

Zielplattformen

Community-Beiträge

Anzeigen:
© 2014 Microsoft