本文整理汇总了C#中Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer.FetchAttributes方法的典型用法代码示例。如果您正苦于以下问题:C# CloudBlobContainer.FetchAttributes方法的具体用法?C# CloudBlobContainer.FetchAttributes怎么用?C# CloudBlobContainer.FetchAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer
的用法示例。
在下文中一共展示了CloudBlobContainer.FetchAttributes方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Initialise
/// <summary>
/// Occurs when a storage provider operation has completed.
/// </summary>
//public event EventHandler<StorageProviderEventArgs> StorageProviderOperationCompleted;
#endregion
// Initialiser method
private void Initialise(string storageAccount, string containerName)
{
if (String.IsNullOrEmpty(containerName))
throw new ArgumentException("You must provide the base Container Name", "containerName");
ContainerName = containerName;
_account = CloudStorageAccount.Parse(storageAccount);
_blobClient = _account.CreateCloudBlobClient();
_container = _blobClient.GetContainerReference(ContainerName);
try
{
_container.FetchAttributes();
}
catch (StorageException)
{
Trace.WriteLine(string.Format("Create new container: {0}", ContainerName), "Information");
_container.Create();
// set new container's permissions
// Create a permission policy to set the public access setting for the container.
BlobContainerPermissions containerPermissions = new BlobContainerPermissions();
// The public access setting explicitly specifies that the container is private,
// so that it can't be accessed anonymously.
containerPermissions.PublicAccess = BlobContainerPublicAccessType.Off;
//Set the permission policy on the container.
_container.SetPermissions(containerPermissions);
}
}
示例2: TestAccess
private static void TestAccess(BlobContainerPublicAccessType accessType, CloudBlobContainer container, CloudBlob inputBlob)
{
StorageCredentials credentials = new StorageCredentials();
container = new CloudBlobContainer(container.Uri, credentials);
CloudPageBlob blob = new CloudPageBlob(inputBlob.Uri, credentials);
if (accessType.Equals(BlobContainerPublicAccessType.Container))
{
blob.FetchAttributes();
container.ListBlobs().ToArray();
container.FetchAttributes();
}
else if (accessType.Equals(BlobContainerPublicAccessType.Blob))
{
blob.FetchAttributes();
TestHelper.ExpectedException(
() => container.ListBlobs().ToArray(),
"List blobs while public access does not allow for listing",
HttpStatusCode.NotFound);
TestHelper.ExpectedException(
() => container.FetchAttributes(),
"Fetch container attributes while public access does not allow",
HttpStatusCode.NotFound);
}
else
{
TestHelper.ExpectedException(
() => blob.FetchAttributes(),
"Fetch blob attributes while public access does not allow",
HttpStatusCode.NotFound);
TestHelper.ExpectedException(
() => container.ListBlobs().ToArray(),
"List blobs while public access does not allow for listing",
HttpStatusCode.NotFound);
TestHelper.ExpectedException(
() => container.FetchAttributes(),
"Fetch container attributes while public access does not allow",
HttpStatusCode.NotFound);
}
}
示例3: ListContainerMetadata
public static void ListContainerMetadata(CloudBlobContainer container)
{
//Fetch container attributes in order to populate the container's properties and metadata.
container.FetchAttributes();
//Enumerate the container's metadata.
//Console.WriteLine("Container metadata:");
//foreach (var metadataItem in container.Metadata)
//{
// Console.WriteLine("\tKey: {0}", metadataItem.Key);
// Console.WriteLine("\tValue: {0}", metadataItem.Value);
//}
}
示例4: FetchContainerAttributes
/// <summary>
/// Fetch container attributes
/// </summary>
/// <param name="container">CloudBlobContainer object</param>
/// <param name="accessCondition">Access condition</param>
/// <param name="options">Blob request options</param>
/// <param name="operationContext">An object that represents the context for the current operation.</param>
public void FetchContainerAttributes(CloudBlobContainer container, AccessCondition accessCondition, BlobRequestOptions options, OperationContext operationContext)
{
container.FetchAttributes(accessCondition, options, operationContext);
}
示例5: GetLatestBlob
/// <summary>
/// Gets the latest BLOB.
/// </summary>
/// <param name="container">The container.</param>
/// <returns></returns>
private CloudBlockBlob GetLatestBlob(CloudBlobContainer container)
{
container.FetchAttributes();
var latest = container.Metadata[Constants.LastUploadedVersion];
return container.GetBlockBlobReference(latest);
}
示例6: CheckLeaseStatus
/// <summary>
/// Checks the lease status of a container, both from its attributes and from a container listing.
/// </summary>
/// <param name="container">The container 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 void CheckLeaseStatus(
CloudBlobContainer container,
LeaseStatus expectedStatus,
LeaseState expectedState,
LeaseDuration expectedDuration,
string description)
{
container.FetchAttributes();
Assert.AreEqual(expectedStatus, container.Properties.LeaseStatus, "LeaseStatus mismatch: " + description + " (from FetchAttributes)");
Assert.AreEqual(expectedState, container.Properties.LeaseState, "LeaseState mismatch: " + description + " (from FetchAttributes)");
Assert.AreEqual(expectedDuration, container.Properties.LeaseDuration, "LeaseDuration mismatch: " + description + " (from FetchAttributes)");
BlobContainerProperties propertiesInListing = (from CloudBlobContainer c in this.blobClient.ListContainers(
container.Name,
ContainerListingDetails.None)
where c.Name == container.Name
select c.Properties).Single();
Assert.AreEqual(expectedStatus, propertiesInListing.LeaseStatus, "LeaseStatus mismatch: " + description + " (from ListContainers)");
Assert.AreEqual(expectedState, propertiesInListing.LeaseState, "LeaseState mismatch: " + description + " (from ListContainers)");
Assert.AreEqual(expectedDuration, propertiesInListing.LeaseDuration, "LeaseDuration mismatch: " + description + " (from ListContainers)");
}
示例7: ContainerReadWriteExpectLeaseSuccess
/// <summary>
/// Test container reads and writes, expecting success.
/// </summary>
/// <param name="testContainer">The container.</param>
/// <param name="testAccessCondition">The access condition to use.</param>
private void ContainerReadWriteExpectLeaseSuccess(CloudBlobContainer testContainer, AccessCondition testAccessCondition)
{
testContainer.FetchAttributes(testAccessCondition, null /* options */);
testContainer.GetPermissions(testAccessCondition, null /* options */);
testContainer.SetMetadata(testAccessCondition, null /* options */);
testContainer.SetPermissions(new BlobContainerPermissions(), testAccessCondition, null /* options */);
}
示例8: ContainerReadWriteExpectLeaseFailure
/// <summary>
/// Test container reads and writes, expecting lease failure.
/// </summary>
/// <param name="testContainer">The container.</param>
/// <param name="testAccessCondition">The failing access condition to use.</param>
/// <param name="expectedErrorCode">The expected error code.</param>
/// <param name="description">The reason why these calls should fail.</param>
private void ContainerReadWriteExpectLeaseFailure(CloudBlobContainer testContainer, AccessCondition testAccessCondition, HttpStatusCode expectedStatusCode, string expectedErrorCode, string description)
{
// FetchAttributes is a HEAD request with no extended error info, so it returns with the generic ConditionFailed error code.
TestHelper.ExpectedException(
() => testContainer.FetchAttributes(testAccessCondition, null /* options */),
description + "(Fetch Attributes)",
HttpStatusCode.PreconditionFailed);
TestHelper.ExpectedException(
() => testContainer.GetPermissions(testAccessCondition, null /* options */),
description + " (Get Permissions)",
expectedStatusCode,
expectedErrorCode);
TestHelper.ExpectedException(
() => testContainer.SetMetadata(testAccessCondition, null /* options */),
description + " (Set Metadata)",
expectedStatusCode,
expectedErrorCode);
TestHelper.ExpectedException(
() => testContainer.SetPermissions(new BlobContainerPermissions(), testAccessCondition, null /* options */),
description + " (Set Permissions)",
expectedStatusCode,
expectedErrorCode);
}
示例9: ContainerAcquireRenewLeaseTest
/// <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.
/// </summary>
/// <param name="leasedContainer">The container.</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 void ContainerAcquireRenewLeaseTest(CloudBlobContainer leasedContainer, TimeSpan? duration, TimeSpan testLength, TimeSpan tolerance)
{
DateTime beginTime = DateTime.UtcNow;
while (true)
{
try
{
// Attempt to delete the container with no lease ID.
leasedContainer.Delete();
// The delete 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, "Deletes should not succeed while lease is present.");
// Since the lease has expired (and the container was deleted), the test is over.
return;
}
catch (StorageException exception)
{
if (exception.RequestInformation.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, "Deletes 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
{
throw;
}
}
// Attempt to write to and read from the container. This should always succeed.
leasedContainer.SetMetadata();
leasedContainer.FetchAttributes();
// Wait 1 second before trying again.
Thread.Sleep(TimeSpan.FromSeconds(1));
}
}
示例10: Initialise
// Initialiser method
private void Initialise(string containerName)
{
if (String.IsNullOrEmpty(containerName))
throw new ArgumentException("You must provide the base Container Name", "containerName");
ContainerName = containerName;
if (StorageProviderConfiguration.Mode == Modes.Debug)
{
_account = CloudStorageAccount.DevelopmentStorageAccount;
_blobClient = _account.CreateCloudBlobClient();
_blobClient.ServerTimeout = new TimeSpan(0, 0, 0, 5);
}
else
{
_account = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("FTP2Azure.StorageAccount"));
_blobClient = _account.CreateCloudBlobClient();
_blobClient.ServerTimeout = new TimeSpan(0, 0, 0, 5);
}
_container = _blobClient.GetContainerReference(ContainerName);
try
{
_container.FetchAttributes();
}
catch (StorageException)
{
Trace.WriteLine(string.Format("Create new container: {0}", ContainerName), "Information");
_container.Create();
// set new container's permissions
// Create a permission policy to set the public access setting for the container.
BlobContainerPermissions containerPermissions = new BlobContainerPermissions();
// The public access setting explicitly specifies that the container is private,
// so that it can't be accessed anonymously.
containerPermissions.PublicAccess = BlobContainerPublicAccessType.Off;
//Set the permission policy on the container.
_container.SetPermissions(containerPermissions);
}
}