當前位置: 首頁>>代碼示例>>C#>>正文


C# CloudBlob.SetMetadata方法代碼示例

本文整理匯總了C#中Microsoft.WindowsAzure.Storage.Blob.CloudBlob.SetMetadata方法的典型用法代碼示例。如果您正苦於以下問題:C# CloudBlob.SetMetadata方法的具體用法?C# CloudBlob.SetMetadata怎麽用?C# CloudBlob.SetMetadata使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Microsoft.WindowsAzure.Storage.Blob.CloudBlob的用法示例。


在下文中一共展示了CloudBlob.SetMetadata方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: 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(CloudBlob 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();
        }
開發者ID:benaadams,項目名稱:azure-storage-net,代碼行數:73,代碼來源:LeaseTests.cs

示例2: SetBlobMetadata

 /// <summary>
 /// Set blob meta data
 /// </summary>
 /// <param name="blob">ICloud blob 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 SetBlobMetadata(CloudBlob blob, AccessCondition accessCondition, BlobRequestOptions options, OperationContext operationContext)
 {
     blob.SetMetadata(accessCondition, options, operationContext);
 }
開發者ID:nityasharma,項目名稱:azure-powershell,代碼行數:11,代碼來源:StorageBlobManagement.cs


注:本文中的Microsoft.WindowsAzure.Storage.Blob.CloudBlob.SetMetadata方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。