本文整理汇总了C#中Microsoft.WindowsAzure.Storage.Blob.CloudBlob.FetchAttributesAsync方法的典型用法代码示例。如果您正苦于以下问题:C# CloudBlob.FetchAttributesAsync方法的具体用法?C# CloudBlob.FetchAttributesAsync怎么用?C# CloudBlob.FetchAttributesAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.WindowsAzure.Storage.Blob.CloudBlob
的用法示例。
在下文中一共展示了CloudBlob.FetchAttributesAsync方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WaitForCopyAsync
public static async Task WaitForCopyAsync(CloudBlob blob)
{
bool copyInProgress = true;
while (copyInProgress)
{
await Task.Delay(1000);
await blob.FetchAttributesAsync();
copyInProgress = (blob.CopyState.Status == CopyStatus.Pending);
}
}
示例2: WaitForCopyTask
public static void WaitForCopyTask(CloudBlob blob)
{
bool copyInProgress = true;
while (copyInProgress)
{
Thread.Sleep(1000);
blob.FetchAttributesAsync().Wait();
copyInProgress = (blob.CopyState.Status == CopyStatus.Pending);
}
}
示例3: LoadBlobBytesAsync
public async Task<byte[]> LoadBlobBytesAsync(Uri location)
{
var blob = new CloudBlob (location);
await blob.FetchAttributesAsync ();
byte[] target = new byte[blob.Properties.Length];
await blob.DownloadToByteArrayAsync (target, 0);
return target;
}
示例4: BlobAcquireRenewLeaseTestAsync
/// <summary>
/// Verifies the behavior of a lease while the lease holds. Once the lease expires, this method confirms that write operations succeed.
/// The test is cut short once the <c>testLength</c> time has elapsed. (This last feature is necessary for infinite leases.)
/// </summary>
/// <param name="leasedBlob">The blob to test.</param>
/// <param name="duration">The duration of the lease.</param>
/// <param name="testLength">The maximum length of time to run the test.</param>
/// <param name="tolerance">The allowed lease time error.</param>
internal async Task BlobAcquireRenewLeaseTestAsync(CloudBlob leasedBlob, TimeSpan? duration, TimeSpan testLength, TimeSpan tolerance)
{
OperationContext operationContext = new OperationContext();
DateTime beginTime = DateTime.UtcNow;
bool testOver = false;
do
{
try
{
// Attempt to write to the blob with no lease ID.
await leasedBlob.SetMetadataAsync(null, null, operationContext);
// The write succeeded, which means that the lease must have expired.
// If the lease was infinite then there is an error because it should not have expired.
Assert.IsNotNull(duration, "An infinite lease should not expire.");
// The lease should be past its expiration time.
Assert.IsTrue(DateTime.UtcNow - beginTime > duration - tolerance, "Writes should not succeed while lease is present.");
// Since the lease has expired, the test is over.
testOver = true;
}
catch (Exception)
{
if (operationContext.LastResult.ExtendedErrorInformation.ErrorCode == BlobErrorCodeStrings.LeaseIdMissing)
{
// We got this error because the lease has not expired yet.
// Make sure the lease is not past its expiration time yet.
DateTime currentTime = DateTime.UtcNow;
if (duration.HasValue)
{
Assert.IsTrue(currentTime - beginTime < duration + tolerance, "Writes should succeed after a lease expires.");
}
// End the test early if necessary.
if (currentTime - beginTime > testLength)
{
// The lease has not expired, but we're not waiting any longer.
return;
}
}
else
{
// Some other error occurred. Rethrow the exception.
throw;
}
}
// Attempt to read from the blob. This should always succeed.
await leasedBlob.FetchAttributesAsync();
// Wait 1 second before trying again.
if (!testOver)
{
await Task.Delay(TimeSpan.FromSeconds(1));
}
}
while (!testOver);
// The lease expired. Write to and read from the blob once more.
await leasedBlob.SetMetadataAsync();
await leasedBlob.FetchAttributesAsync();
}
示例5: CheckLeaseStatusAsync
/// <summary>
/// Checks the lease status of a blob, both from its attributes and from a blob listing.
/// </summary>
/// <param name="blob">The blob to test.</param>
/// <param name="expectedStatus">The expected lease status.</param>
/// <param name="expectedState">The expected lease state.</param>
/// <param name="expectedDuration">The expected lease duration.</param>
/// <param name="description">A description of the circumstances that lead to the expected status.</param>
private async Task CheckLeaseStatusAsync(
CloudBlob blob,
LeaseStatus expectedStatus,
LeaseState expectedState,
LeaseDuration expectedDuration,
string description)
{
await blob.FetchAttributesAsync();
Assert.AreEqual(expectedStatus, blob.Properties.LeaseStatus, "LeaseStatus mismatch: " + description + " (from FetchAttributes)");
Assert.AreEqual(expectedState, blob.Properties.LeaseState, "LeaseState mismatch: " + description + " (from FetchAttributes)");
Assert.AreEqual(expectedDuration, blob.Properties.LeaseDuration, "LeaseDuration mismatch: " + description + " (from FetchAttributes)");
BlobResultSegment blobs = await blob.Container.ListBlobsSegmentedAsync(blob.Name, true, BlobListingDetails.None, null, null, null, null);
BlobProperties propertiesInListing = (from CloudBlob b in blobs.Results
where b.Name == blob.Name
select b.Properties).Single();
Assert.AreEqual(expectedStatus, propertiesInListing.LeaseStatus, "LeaseStatus mismatch: " + description + " (from ListBlobs)");
Assert.AreEqual(expectedState, propertiesInListing.LeaseState, "LeaseState mismatch: " + description + " (from ListBlobs)");
Assert.AreEqual(expectedDuration, propertiesInListing.LeaseDuration, "LeaseDuration mismatch: " + description + " (from ListBlobs)");
}
示例6: StartCopyFromUri
private async Task StartCopyFromUri(long taskId, IStorageBlobManagement destChannel, Uri srcUri, CloudBlob destBlob)
{
bool destExist = true;
try
{
await destBlob.FetchAttributesAsync(null, this.RequestOptions, this.OperationContext, this.CmdletCancellationToken);
}
catch (StorageException ex)
{
if (ex.IsNotFoundException())
{
destExist = false;
}
else
{
throw;
}
}
if (!destExist || this.ConfirmOverwrite(srcUri.AbsoluteUri.ToString(), destBlob.Uri.ToString()))
{
string copyId = await destChannel.StartCopyAsync(destBlob, srcUri, null, null, this.RequestOptions, this.OperationContext, this.CmdletCancellationToken);
this.OutputStream.WriteVerbose(taskId, String.Format(Resources.CopyDestinationBlobPending, destBlob.Name, destBlob.Container.Name, copyId));
this.WriteCloudBlobObject(taskId, destChannel, destBlob);
}
}
示例7: FetchBlobAttributesAsync
/// <summary>
/// Return a task that asynchronously fetch blob attributes
/// </summary>
/// <param name="blob">ICloud blob object</param>
/// <param name="accessCondition">Access condition</param>
/// <param name="options">Blob request options</param>
/// <param name="operationContext">Operation context</param>
/// <param name="cmdletCancellationToken">Cancellation token</param>
/// <returns>Return a task that asynchronously fetch blob attributes</returns>
public Task FetchBlobAttributesAsync(CloudBlob blob, AccessCondition accessCondition, BlobRequestOptions options, OperationContext operationContext, CancellationToken cancellationToken)
{
return blob.FetchAttributesAsync(accessCondition, options, operationContext, cancellationToken);
}
示例8: CloudBlobSnapshotAsync
public async Task CloudBlobSnapshotAsync()
{
CloudBlobContainer container = GetRandomContainerReference();
try
{
await container.CreateAsync();
MemoryStream originalData = new MemoryStream(GetRandomBuffer(1024));
CloudAppendBlob appendBlob = container.GetAppendBlobReference(BlobName);
await appendBlob.CreateOrReplaceAsync();
await appendBlob.AppendBlockAsync(originalData, null);
CloudBlob blob = container.GetBlobReference(BlobName);
await blob.FetchAttributesAsync();
Assert.IsFalse(blob.IsSnapshot);
Assert.IsNull(blob.SnapshotTime, "Root blob has SnapshotTime set");
Assert.IsFalse(blob.SnapshotQualifiedUri.Query.Contains("snapshot"));
Assert.AreEqual(blob.Uri, blob.SnapshotQualifiedUri);
CloudBlob snapshot1 = await blob.SnapshotAsync();
Assert.AreEqual(blob.Properties.ETag, snapshot1.Properties.ETag);
Assert.AreEqual(blob.Properties.LastModified, snapshot1.Properties.LastModified);
Assert.IsTrue(snapshot1.IsSnapshot);
Assert.IsNotNull(snapshot1.SnapshotTime, "Snapshot does not have SnapshotTime set");
Assert.AreEqual(blob.Uri, snapshot1.Uri);
Assert.AreNotEqual(blob.SnapshotQualifiedUri, snapshot1.SnapshotQualifiedUri);
Assert.AreNotEqual(snapshot1.Uri, snapshot1.SnapshotQualifiedUri);
Assert.IsTrue(snapshot1.SnapshotQualifiedUri.Query.Contains("snapshot"));
CloudBlob snapshot2 = await blob.SnapshotAsync();
Assert.IsTrue(snapshot2.SnapshotTime.Value > snapshot1.SnapshotTime.Value);
await snapshot1.FetchAttributesAsync();
await snapshot2.FetchAttributesAsync();
await blob.FetchAttributesAsync();
AssertAreEqual(snapshot1.Properties, blob.Properties);
CloudBlob snapshot1Clone = new CloudBlob(new Uri(blob.Uri + "?snapshot=" + snapshot1.SnapshotTime.Value.ToString("O")), blob.ServiceClient.Credentials);
Assert.IsNotNull(snapshot1Clone.SnapshotTime, "Snapshot clone does not have SnapshotTime set");
Assert.AreEqual(snapshot1.SnapshotTime.Value, snapshot1Clone.SnapshotTime.Value);
await snapshot1Clone.FetchAttributesAsync();
AssertAreEqual(snapshot1.Properties, snapshot1Clone.Properties, false);
CloudAppendBlob snapshotCopy = container.GetAppendBlobReference("blob2");
await snapshotCopy.StartCopyAsync((TestHelper.Defiddler(snapshot1.Uri)));
await WaitForCopyAsync(snapshotCopy);
Assert.AreEqual(CopyStatus.Success, snapshotCopy.CopyState.Status);
using (Stream snapshotStream = (await snapshot1.OpenReadAsync()))
{
snapshotStream.Seek(0, SeekOrigin.End);
TestHelper.AssertStreamsAreEqual(originalData, snapshotStream);
}
await appendBlob.CreateOrReplaceAsync();
await appendBlob.FetchAttributesAsync(); // This is needed as cache settings are not updated with create call above.
await blob.FetchAttributesAsync();
using (Stream snapshotStream = (await snapshot1.OpenReadAsync()))
{
snapshotStream.Seek(0, SeekOrigin.End);
TestHelper.AssertStreamsAreEqual(originalData, snapshotStream);
}
BlobResultSegment resultSegment = await container.ListBlobsSegmentedAsync(null, true, BlobListingDetails.All, null, null, null, null);
List<IListBlobItem> blobs = resultSegment.Results.ToList();
Assert.AreEqual(4, blobs.Count);
AssertAreEqual(snapshot1, (CloudBlob)blobs[0]);
AssertAreEqual(snapshot2, (CloudBlob)blobs[1]);
AssertAreEqual(appendBlob, (CloudBlob)blobs[2]);
AssertAreEqual(snapshotCopy, (CloudBlob)blobs[3]);
}
finally
{
container.DeleteIfExistsAsync().Wait();
}
}