本文整理汇总了C#中ICloudBlob.FetchAttributes方法的典型用法代码示例。如果您正苦于以下问题:C# ICloudBlob.FetchAttributes方法的具体用法?C# ICloudBlob.FetchAttributes怎么用?C# ICloudBlob.FetchAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICloudBlob
的用法示例。
在下文中一共展示了ICloudBlob.FetchAttributes方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WaitForCopy
public static void WaitForCopy(ICloudBlob blob)
{
bool copyInProgress = true;
while (copyInProgress)
{
Thread.Sleep(1000);
blob.FetchAttributes();
copyInProgress = (blob.CopyState.Status == CopyStatus.Pending);
}
}
示例2: FetchBlobAttributes
/// <summary>
/// Fetch blob attributes
/// </summary>
/// <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 FetchBlobAttributes(ICloudBlob blob, AccessCondition accessCondition, BlobRequestOptions options, OperationContext operationContext)
{
blob.FetchAttributes(accessCondition, options, operationContext);
}
示例3: GenerateBlobPropertiesAndMetaData
/// <summary>
/// generate random blob properties and metadata
/// </summary>
/// <param name="blob">ICloudBlob object</param>
private void GenerateBlobPropertiesAndMetaData(ICloudBlob blob)
{
blob.Properties.ContentEncoding = Utility.GenNameString("encoding");
blob.Properties.ContentLanguage = Utility.GenNameString("lang");
int minMetaCount = 1;
int maxMetaCount = 5;
int minMetaValueLength = 10;
int maxMetaValueLength = 20;
int count = random.Next(minMetaCount, maxMetaCount);
for (int i = 0; i < count; i++)
{
string metaKey = Utility.GenNameString("metatest");
int valueLength = random.Next(minMetaValueLength, maxMetaValueLength);
string metaValue = Utility.GenNameString("metavalue-", valueLength);
blob.Metadata.Add(metaKey, metaValue);
}
blob.SetProperties();
blob.SetMetadata();
blob.FetchAttributes();
}
示例4: WaitForCopyOperationComplete
public static bool WaitForCopyOperationComplete(ICloudBlob destBlob, int maxRetry = 100)
{
int retryCount = 0;
int sleepInterval = 1000; //ms
if (destBlob == null)
{
return false;
}
do
{
if (retryCount > 0)
{
Test.Info(String.Format("{0}th check current copy state and it's {1}. Wait for copy completion", retryCount, destBlob.CopyState.Status));
}
Thread.Sleep(sleepInterval);
destBlob.FetchAttributes();
retryCount++;
}
while (destBlob.CopyState.Status == CopyStatus.Pending && retryCount < maxRetry);
Test.Info(String.Format("Final Copy status is {0}", destBlob.CopyState.Status));
return destBlob.CopyState.Status != CopyStatus.Pending;
}
示例5: AssertStopPendingCopyOperationTest
private void AssertStopPendingCopyOperationTest(ICloudBlob blob)
{
Test.Assert(blob.CopyState.Status == CopyStatus.Pending, String.Format("The copy status should be pending, actually it's {0}", blob.CopyState.Status));
string copyId = "*";
bool force = true;
Test.Assert(agent.StopAzureStorageBlobCopy(blob.Container.Name, blob.Name, copyId, force), "Stop copy operation should be successed");
blob.FetchAttributes();
Test.Assert(blob.CopyState.Status == CopyStatus.Aborted, String.Format("The copy status should be aborted, actually it's {0}", blob.CopyState.Status));
int expectedOutputCount = 1;
Test.Assert(agent.Output.Count == expectedOutputCount, String.Format("Should return {0} message, and actually it's {1}", expectedOutputCount, agent.Output.Count));
}
示例6: DownloadBlobAsync
public void DownloadBlobAsync(ICloudBlob blob, string LocalFile)
{
// The class currently stores state in class level variables so calling UploadBlobAsync or DownloadBlobAsync a second time will cause problems.
// A better long term solution would be to better encapsulate the state, but the current solution works for the needs of my primary client.
// Throw an exception if UploadBlobAsync or DownloadBlobAsync has already been called.
lock (WorkingLock)
{
if (!Working)
Working = true;
else
throw new Exception("BlobTransfer already initiated. Create new BlobTransfer object to initiate a new file transfer.");
}
// Create an async op in order to raise the events back to the client on the correct thread.
asyncOp = AsyncOperationManager.CreateOperation(blob);
TransferType = TransferTypeEnum.Download;
m_Blob = blob;
m_FileName = LocalFile;
m_Blob.FetchAttributes();
FileStream fs = new FileStream(m_FileName, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read);
ProgressStream pstream = new ProgressStream(fs);
pstream.ProgressChanged += pstream_ProgressChanged;
pstream.SetLength(m_Blob.Properties.Length);
m_Blob.ServiceClient.ParallelOperationThreadCount = 10;
asyncresult = m_Blob.BeginDownloadToStream(pstream, BlobTransferCompletedCallback, new BlobTransferAsyncState(m_Blob, pstream));
}
示例7: BlobAcquireRenewLeaseTest
/// <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 void BlobAcquireRenewLeaseTest(ICloudBlob leasedBlob, TimeSpan? duration, TimeSpan testLength, TimeSpan tolerance)
{
DateTime beginTime = DateTime.UtcNow;
bool testOver = false;
do
{
try
{
// Attempt to write to the blob with no lease ID.
leasedBlob.SetMetadata();
// 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 (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, "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.
leasedBlob.FetchAttributes();
// Wait 1 second before trying again.
if (!testOver)
{
Thread.Sleep(TimeSpan.FromSeconds(1));
}
}
while (!testOver);
// The lease expired. Write to and read from the blob once more.
leasedBlob.SetMetadata();
leasedBlob.FetchAttributes();
}
示例8: CheckLeaseStatus
/// <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 void CheckLeaseStatus(
ICloudBlob blob,
LeaseStatus expectedStatus,
LeaseState expectedState,
LeaseDuration expectedDuration,
string description)
{
blob.FetchAttributes();
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)");
BlobProperties propertiesInListing = (from ICloudBlob b in blob.Container.ListBlobs(
blob.Name,
true /* use flat blob listing */,
BlobListingDetails.None,
null /* options */)
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)");
}