当前位置: 首页>>代码示例>>C#>>正文


C# CloudBlob.FetchAttributes方法代码示例

本文整理汇总了C#中Microsoft.WindowsAzure.Storage.Blob.CloudBlob.FetchAttributes方法的典型用法代码示例。如果您正苦于以下问题:C# CloudBlob.FetchAttributes方法的具体用法?C# CloudBlob.FetchAttributes怎么用?C# CloudBlob.FetchAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.WindowsAzure.Storage.Blob.CloudBlob的用法示例。


在下文中一共展示了CloudBlob.FetchAttributes方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: WaitForCopy

 public static void WaitForCopy(CloudBlob blob)
 {
     bool copyInProgress = true;
     while (copyInProgress)
     {
         Thread.Sleep(1000);
         blob.FetchAttributes();
         copyInProgress = (blob.CopyState.Status == CopyStatus.Pending);
     }
 }
开发者ID:Gajendra-Bahakar,项目名称:azure-storage-net,代码行数:10,代码来源:BlobTestBase.cs

示例2: CreateVideo

        private Video CreateVideo(CloudBlob blob)
        {
            if (blob == null)
            {
                return null;
            }

            blob.FetchAttributes();

            return new Video
            {
                Title = blob.Metadata[NameField],
                Name = blob.Name,
                StorageUrl = blob.Uri.ToString(),
                ContentDeliveryNetworkUrl = $"https://{_config.CdnEndpointName}.vo.msecnd.net/{ContainerName}/{blob.Name}"
            };
        }
开发者ID:kpi-ua,项目名称:MediaHack,代码行数:17,代码来源:Cloud.cs

示例3: GetBlobReferenceFromServer

        private static CloudBlob GetBlobReferenceFromServer(
            CloudBlob blob,
            AccessCondition accessCondition = null,
            BlobRequestOptions options = null,
            OperationContext operationContext = null)
        {
            try
            {
                blob.FetchAttributes(accessCondition, options, operationContext);
            }
            catch (StorageException se)
            {
                if (se.RequestInformation == null ||
                    (se.RequestInformation.HttpStatusCode != (int)HttpStatusCode.NotFound))
                {
                    throw;
                }

                return null;
            }

            return GetCorrespondingTypeBlobReference(blob);
        }
开发者ID:docschmidt,项目名称:azure-powershell,代码行数:23,代码来源:Util.cs

示例4: CloudBlobSASSharedProtocolsQueryParam

        public void CloudBlobSASSharedProtocolsQueryParam()
        {
            CloudBlobContainer container = GetRandomContainerReference();
            try
            {
                container.Create();
                CloudBlob blob;
                SharedAccessBlobPolicy policy = new SharedAccessBlobPolicy()
                {
                    Permissions = SharedAccessBlobPermissions.Read,
                    SharedAccessStartTime = DateTimeOffset.UtcNow.AddMinutes(-5),
                    SharedAccessExpiryTime = DateTimeOffset.UtcNow.AddMinutes(30),
                };

                CloudBlockBlob blockBlob = container.GetBlockBlobReference("bb");
                blockBlob.PutBlockList(new string[] { });

                foreach (SharedAccessProtocol? protocol in new SharedAccessProtocol?[] { null, SharedAccessProtocol.HttpsOrHttp, SharedAccessProtocol.HttpsOnly })
                {
                    string blockBlobToken = blockBlob.GetSharedAccessSignature(policy, null, null, protocol, null);
                    StorageCredentials blockBlobSAS = new StorageCredentials(blockBlobToken);
                    Uri blockBlobSASUri = new Uri(blockBlob.Uri + blockBlobSAS.SASToken);
                    StorageUri blockBlobSASStorageUri = new StorageUri(new Uri(blockBlob.StorageUri.PrimaryUri + blockBlobSAS.SASToken), new Uri(blockBlob.StorageUri.SecondaryUri + blockBlobSAS.SASToken));

                    int httpPort = blockBlobSASUri.Port;
                    int securePort = 443;

                    if (!string.IsNullOrEmpty(TestBase.TargetTenantConfig.BlobSecurePortOverride))
                    {
                        securePort = Int32.Parse(TestBase.TargetTenantConfig.BlobSecurePortOverride);
                    }

                    var schemesAndPorts = new[] {
                        new { scheme = Uri.UriSchemeHttp, port = httpPort},
                        new { scheme = Uri.UriSchemeHttps, port = securePort}
                    };
                    
                    foreach (var item in schemesAndPorts)
                    {
                        blockBlobSASUri = TransformSchemeAndPort(blockBlobSASUri, item.scheme, item.port);
                        blockBlobSASStorageUri = new StorageUri(TransformSchemeAndPort(blockBlobSASStorageUri.PrimaryUri, item.scheme, item.port), TransformSchemeAndPort(blockBlobSASStorageUri.SecondaryUri, item.scheme, item.port));

                        if (protocol.HasValue && protocol.Value == SharedAccessProtocol.HttpsOnly && string.CompareOrdinal(item.scheme, Uri.UriSchemeHttp) == 0)
                        {
                            blob = new CloudBlob(blockBlobSASUri);
                            TestHelper.ExpectedException(() => blob.FetchAttributes(), "Access a blob using SAS with a shared protocols that does not match", HttpStatusCode.Unused);

                            blob = new CloudBlob(blockBlobSASStorageUri, null, null);
                            TestHelper.ExpectedException(() => blob.FetchAttributes(), "Access a blob using SAS with a shared protocols that does not match", HttpStatusCode.Unused);
                        }
                        else
                        {
                            blob = new CloudBlob(blockBlobSASUri);
                            blob.FetchAttributes();
                            Assert.AreEqual(blob.BlobType, BlobType.BlockBlob);

                            blob = new CloudBlob(blockBlobSASStorageUri, null, null);
                            blob.FetchAttributes();
                            Assert.AreEqual(blob.BlobType, BlobType.BlockBlob);
                        }
                    }
                }
            }
            finally
            {
                container.DeleteIfExists();
            }
        }
开发者ID:benaadams,项目名称:azure-storage-net,代码行数:68,代码来源:SASTests.cs

示例5: CloudBlobSASApiVersionQueryParam

        public void CloudBlobSASApiVersionQueryParam()
        {
            CloudBlobContainer container = GetRandomContainerReference();
            try
            {
                container.Create();
                CloudBlob blob;

                SharedAccessBlobPolicy policy = new SharedAccessBlobPolicy()
                {
                    Permissions = SharedAccessBlobPermissions.Read,
                    SharedAccessStartTime = DateTimeOffset.UtcNow.AddMinutes(-5),
                    SharedAccessExpiryTime = DateTimeOffset.UtcNow.AddMinutes(30),
                };

                CloudBlockBlob blockBlob = container.GetBlockBlobReference("bb");
                blockBlob.PutBlockList(new string[] { });

                CloudPageBlob pageBlob = container.GetPageBlobReference("pb");
                pageBlob.Create(0);

                CloudAppendBlob appendBlob = container.GetAppendBlobReference("ab");
                appendBlob.CreateOrReplace();

                string blockBlobToken = blockBlob.GetSharedAccessSignature(policy);
                StorageCredentials blockBlobSAS = new StorageCredentials(blockBlobToken);
                Uri blockBlobSASUri = blockBlobSAS.TransformUri(blockBlob.Uri);
                StorageUri blockBlobSASStorageUri = blockBlobSAS.TransformUri(blockBlob.StorageUri);

                string pageBlobToken = pageBlob.GetSharedAccessSignature(policy);
                StorageCredentials pageBlobSAS = new StorageCredentials(pageBlobToken);
                Uri pageBlobSASUri = pageBlobSAS.TransformUri(pageBlob.Uri);
                StorageUri pageBlobSASStorageUri = pageBlobSAS.TransformUri(pageBlob.StorageUri);

                string appendBlobToken = appendBlob.GetSharedAccessSignature(policy);
                StorageCredentials appendBlobSAS = new StorageCredentials(appendBlobToken);
                Uri appendBlobSASUri = appendBlobSAS.TransformUri(appendBlob.Uri);
                StorageUri appendBlobSASStorageUri = appendBlobSAS.TransformUri(appendBlob.StorageUri);

                OperationContext apiVersionCheckContext = new OperationContext();
                apiVersionCheckContext.SendingRequest += (sender, e) =>
                {
                    Assert.IsTrue(e.Request.RequestUri.Query.Contains("api-version"));
                };

                blob = new CloudBlob(blockBlobSASUri);
                blob.FetchAttributes(operationContext: apiVersionCheckContext);
                Assert.AreEqual(blob.BlobType, BlobType.BlockBlob);
                Assert.IsTrue(blob.StorageUri.PrimaryUri.Equals(blockBlob.Uri));
                Assert.IsNull(blob.StorageUri.SecondaryUri);

                blob = new CloudBlob(pageBlobSASUri);
                blob.FetchAttributes(operationContext: apiVersionCheckContext);
                Assert.AreEqual(blob.BlobType, BlobType.PageBlob);
                Assert.IsTrue(blob.StorageUri.PrimaryUri.Equals(pageBlob.Uri));
                Assert.IsNull(blob.StorageUri.SecondaryUri);

                blob = new CloudBlob(blockBlobSASStorageUri, null, null);
                blob.FetchAttributes(operationContext: apiVersionCheckContext);
                Assert.AreEqual(blob.BlobType, BlobType.BlockBlob);
                Assert.IsTrue(blob.StorageUri.Equals(blockBlob.StorageUri));

                blob = new CloudBlob(pageBlobSASStorageUri, null, null);
                blob.FetchAttributes(operationContext: apiVersionCheckContext);
                Assert.AreEqual(blob.BlobType, BlobType.PageBlob);
                Assert.IsTrue(blob.StorageUri.Equals(pageBlob.StorageUri));

            }
            finally
            {
                container.DeleteIfExists();
            }
        }
开发者ID:benaadams,项目名称:azure-storage-net,代码行数:73,代码来源:SASTests.cs

示例6: 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

示例7: 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(
            CloudBlob 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 CloudBlob 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)");
        }
开发者ID:benaadams,项目名称:azure-storage-net,代码行数:32,代码来源:LeaseTests.cs

示例8: 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(CloudBlob blob, AccessCondition accessCondition, BlobRequestOptions options, OperationContext operationContext)
 {
     blob.FetchAttributes(accessCondition, options, operationContext);
 }
开发者ID:nityasharma,项目名称:azure-powershell,代码行数:10,代码来源:StorageBlobManagement.cs

示例9: CloudBlobSnapshot

        public void CloudBlobSnapshot()
        {
            CloudBlobContainer container = GetRandomContainerReference();
            try
            {
                container.Create();

                // Upload some data to the blob.
                MemoryStream originalData = new MemoryStream(GetRandomBuffer(1024));
                CloudAppendBlob appendBlob = container.GetAppendBlobReference(BlobName);
                appendBlob.CreateOrReplace();
                appendBlob.AppendBlock(originalData, null);

                CloudBlob blob = container.GetBlobReference(BlobName);
                blob.FetchAttributes();
                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 = blob.Snapshot();
                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 = blob.Snapshot();
                Assert.IsTrue(snapshot2.SnapshotTime.Value > snapshot1.SnapshotTime.Value);

                snapshot1.FetchAttributes();
                snapshot2.FetchAttributes();
                blob.FetchAttributes();
                AssertAreEqual(snapshot1.Properties, blob.Properties, false);

                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);
                snapshot1Clone.FetchAttributes();
                AssertAreEqual(snapshot1.Properties, snapshot1Clone.Properties, false);

                CloudBlob snapshotCopy = container.GetBlobReference("blob2");
                snapshotCopy.StartCopy(TestHelper.Defiddler(snapshot1.Uri));
                WaitForCopy(snapshotCopy);
                Assert.AreEqual(CopyStatus.Success, snapshotCopy.CopyState.Status);

                using (Stream snapshotStream = snapshot1.OpenRead())
                {
                    snapshotStream.Seek(0, SeekOrigin.End);
                    TestHelper.AssertStreamsAreEqual(originalData, snapshotStream);
                }

                appendBlob.CreateOrReplace();
                blob.FetchAttributes();

                using (Stream snapshotStream = snapshot1.OpenRead())
                {
                    snapshotStream.Seek(0, SeekOrigin.End);
                    TestHelper.AssertStreamsAreEqual(originalData, snapshotStream);
                }

                List<IListBlobItem> blobs = container.ListBlobs(null, true, BlobListingDetails.All, null, null).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.DeleteIfExists();
            }
        }
开发者ID:benaadams,项目名称:azure-storage-net,代码行数:76,代码来源:CloudBlobTest.cs

示例10: OverwriteFile

        private static bool OverwriteFile(string sourceUri, string destinationUri, CloudStorageAccount sourceAccount, CloudStorageAccount destinationAccount, bool isIncremental)
        {
            // If Incremental backup only copy if source is newer
            if (isIncremental)
            {
                CloudBlob sourceBlob = new CloudBlob(new Uri(sourceUri), sourceAccount.Credentials);
                CloudBlob destinationBlob = new CloudBlob(new Uri(destinationUri), destinationAccount.Credentials);

                sourceBlob.FetchAttributes(null, _blobRequestOptions, _opContext);
                destinationBlob.FetchAttributes(null, _blobRequestOptions, _opContext);

                // Source date is newer (larger) than destination date
                return (sourceBlob.Properties.LastModified > destinationBlob.Properties.LastModified);
            }
            else
            {
                // Full backup, overwrite file no matter what
                return true;
            }
        }
开发者ID:markjbrown,项目名称:AzureDmlBackup,代码行数:20,代码来源:Functions.cs


注:本文中的Microsoft.WindowsAzure.Storage.Blob.CloudBlob.FetchAttributes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。