本文整理汇总了C#中Microsoft.WindowsAzure.Storage.Blob.CloudPageBlob.FetchAttributesAsync方法的典型用法代码示例。如果您正苦于以下问题:C# CloudPageBlob.FetchAttributesAsync方法的具体用法?C# CloudPageBlob.FetchAttributesAsync怎么用?C# CloudPageBlob.FetchAttributesAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.WindowsAzure.Storage.Blob.CloudPageBlob
的用法示例。
在下文中一共展示了CloudPageBlob.FetchAttributesAsync方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestAccessAsync
private static async Task TestAccessAsync(BlobContainerPublicAccessType accessType, CloudBlobContainer container, CloudBlob inputBlob)
{
StorageCredentials credentials = new StorageCredentials();
container = new CloudBlobContainer(container.Uri, credentials);
CloudPageBlob blob = new CloudPageBlob(inputBlob.Uri, credentials);
OperationContext context = new OperationContext();
BlobRequestOptions options = new BlobRequestOptions();
if (accessType.Equals(BlobContainerPublicAccessType.Container))
{
await blob.FetchAttributesAsync();
await container.ListBlobsSegmentedAsync(null, true, BlobListingDetails.All, null, null, options, context);
await container.FetchAttributesAsync();
}
else if (accessType.Equals(BlobContainerPublicAccessType.Blob))
{
await blob.FetchAttributesAsync();
await TestHelper.ExpectedExceptionAsync(
async () => await container.ListBlobsSegmentedAsync(null, true, BlobListingDetails.All, null, null, options, context),
context,
"List blobs while public access does not allow for listing",
HttpStatusCode.NotFound);
await TestHelper.ExpectedExceptionAsync(
async () => await container.FetchAttributesAsync(null, options, context),
context,
"Fetch container attributes while public access does not allow",
HttpStatusCode.NotFound);
}
else
{
await TestHelper.ExpectedExceptionAsync(
async () => await blob.FetchAttributesAsync(null, options, context),
context,
"Fetch blob attributes while public access does not allow",
HttpStatusCode.NotFound);
await TestHelper.ExpectedExceptionAsync(
async () => await container.ListBlobsSegmentedAsync(null, true, BlobListingDetails.All, null, null, options, context),
context,
"List blobs while public access does not allow for listing",
HttpStatusCode.NotFound);
await TestHelper.ExpectedExceptionAsync(
async () => await container.FetchAttributesAsync(null, options, context),
context,
"Fetch container attributes while public access does not allow",
HttpStatusCode.NotFound);
}
}
示例2: TestAccessTask
private static void TestAccessTask(BlobContainerPublicAccessType accessType, CloudBlobContainer container, ICloudBlob inputBlob)
{
StorageCredentials credentials = new StorageCredentials();
container = new CloudBlobContainer(container.Uri, credentials);
CloudPageBlob blob = new CloudPageBlob(inputBlob.Uri, credentials);
if (accessType.Equals(BlobContainerPublicAccessType.Container))
{
blob.FetchAttributesAsync().Wait();
BlobContinuationToken token = null;
do
{
BlobResultSegment results = container.ListBlobsSegmented(token);
results.Results.ToArray();
token = results.ContinuationToken;
}
while (token != null);
container.FetchAttributesAsync().Wait();
}
else if (accessType.Equals(BlobContainerPublicAccessType.Blob))
{
blob.FetchAttributesAsync().Wait();
TestHelper.ExpectedExceptionTask(
container.ListBlobsSegmentedAsync(null),
"List blobs while public access does not allow for listing",
HttpStatusCode.NotFound);
TestHelper.ExpectedExceptionTask(
container.FetchAttributesAsync(),
"Fetch container attributes while public access does not allow",
HttpStatusCode.NotFound);
}
else
{
TestHelper.ExpectedExceptionTask(
blob.FetchAttributesAsync(),
"Fetch blob attributes while public access does not allow",
HttpStatusCode.NotFound);
TestHelper.ExpectedExceptionTask(
container.ListBlobsSegmentedAsync(null),
"List blobs while public access does not allow for listing",
HttpStatusCode.NotFound);
TestHelper.ExpectedExceptionTask(
container.FetchAttributesAsync(),
"Fetch container attributes while public access does not allow",
HttpStatusCode.NotFound);
}
}
示例3: CloudPageBlobSnapshotAsync
public async Task CloudPageBlobSnapshotAsync()
{
CloudBlobContainer container = GetRandomContainerReference();
try
{
await container.CreateAsync();
MemoryStream originalData = new MemoryStream(GetRandomBuffer(1024));
CloudPageBlob blob = container.GetPageBlobReference("blob1");
await blob.UploadFromStreamAsync(originalData);
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);
CloudPageBlob snapshot1 = await blob.CreateSnapshotAsync();
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"));
CloudPageBlob snapshot2 = await blob.CreateSnapshotAsync();
Assert.IsTrue(snapshot2.SnapshotTime.Value > snapshot1.SnapshotTime.Value);
await snapshot1.FetchAttributesAsync();
await snapshot2.FetchAttributesAsync();
await blob.FetchAttributesAsync();
AssertAreEqual(snapshot1.Properties, blob.Properties);
CloudPageBlob snapshot1Clone = new CloudPageBlob(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);
CloudPageBlob snapshotCopy = container.GetPageBlobReference("blob2");
await snapshotCopy.StartCopyAsync(TestHelper.Defiddler(snapshot1.Uri));
await WaitForCopyAsync(snapshotCopy);
Assert.AreEqual(CopyStatus.Success, snapshotCopy.CopyState.Status);
await TestHelper.ExpectedExceptionAsync<InvalidOperationException>(
async () => await snapshot1.OpenWriteAsync(1024),
"Trying to write to a blob snapshot should fail");
using (Stream snapshotStream = (await snapshot1.OpenReadAsync()))
{
snapshotStream.Seek(0, SeekOrigin.End);
TestHelper.AssertStreamsAreEqual(originalData, snapshotStream);
}
await blob.CreateAsync(1024);
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(blob, (CloudBlob)blobs[2]);
AssertAreEqual(snapshotCopy, (CloudBlob)blobs[3]);
}
finally
{
container.DeleteIfExistsAsync().Wait();
}
}