简体   繁体   中英

OperationContext usage (Microsoft.WindowsAzure.Storage)

I'm going to download blob from Azure Blob Storage to stream and I need to specify retry policy and timeouts. That's why I use the BlobRequestOptions (WindowsAzure.Storage NuGet package) instance to specify all these settings. I also want to use the asynchronous method DownloadToStreamAsync that needs some additional parameters to be passed (AccessCondition, OperationContext). My code:

var selfieBlob = new CloudBlockBlob(GetBlobUri(requestedUrl), _credentials);
await selfieBlob.DownloadToStreamAsync(
    targetStream,
    AccessCondition.GenerateEmptyCondition(),
    _blobOptions,
    new OperationContext());

Questions:

  • Should I create a new instance of OperationContext each time?
  • Why is it a required parameter for this method? Seems I don't understand why it's so necessary.

You can invoke the method DownloadToStreamAsync with default(OperationContext) . This is the same being done by other overloads of DownloadToStreamAsync . Check here

await selfieBlob.DownloadToStreamAsync(
    targetStream,
    default(AccessCondition),
    _blobOptions,
    default(OperationContext));

It's usually used for logging correlation. Check ExcecuteAsync method implementation here .

About the OperationContext parameter, @user1672994 's answer is right.

Refer to the CloudBlob.DownloadToStreamAsync Method's description , you could know why the parameter AccessCondition is required. You could set it to be null if you don't have the condition limitation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM