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


C# CloudBlockBlob.FetchAttributesAsync方法代码示例

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


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

示例1: CheckForUpdateAsync

        private async Task CheckForUpdateAsync()
        {
            var storageAccount = CloudStorageAccount.Parse(_configuration.ReferenceDataStorageAccount);
            var blobClient = storageAccount.CreateCloudBlobClient();
            var container = blobClient.GetContainerReference(_configuration.ReferenceDataStorageContainer);
            _blockBlob = container.GetBlockBlobReference(_configuration.ReferenceDataFilePath);
            
            if(!await _blockBlob.ExistsAsync())
            {
                throw new ApplicationException(string.Format(CultureInfo.InvariantCulture,
                    "Could not find blob named {0}.",
                    _configuration.ReferenceDataFilePath));
            }

            await _blockBlob.FetchAttributesAsync();

            if (_blockBlob.Properties.ETag == _blobETag)
            {
                return;
            }

            await LoadDictionaryAsync();
            _blobETag = _blockBlob.Properties.ETag;
        }
开发者ID:carloserodriguez2000,项目名称:iot-journey,代码行数:24,代码来源:BuildingLookupService.cs

示例2: CloudBlockBlobSnapshotAsync

        public async Task CloudBlockBlobSnapshotAsync()
        {
            CloudBlobContainer container = GetRandomContainerReference();
            try
            {
                await container.CreateAsync();

                MemoryStream originalData = new MemoryStream(GetRandomBuffer(1024));
                CloudBlockBlob blob = container.GetBlockBlobReference("blob1");
                await blob.UploadFromStreamAsync(originalData.AsInputStream());

                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);

                CloudBlockBlob 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"));

                CloudBlockBlob 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);

                CloudBlockBlob snapshot1Clone = new CloudBlockBlob(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);

                CloudBlockBlob snapshotCopy = container.GetBlockBlobReference("blob2");
                await snapshotCopy.StartCopyFromBlobAsync(TestHelper.Defiddler(snapshot1.Uri));
                await WaitForCopyAsync(snapshotCopy);
                Assert.AreEqual(CopyStatus.Success, snapshotCopy.CopyState.Status);

                await TestHelper.ExpectedExceptionAsync<InvalidOperationException>(
                    async () => await snapshot1.OpenWriteAsync(),
                    "Trying to write to a blob snapshot should fail");

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

                await blob.PutBlockListAsync(new List<string>());
                await blob.FetchAttributesAsync();

                using (Stream snapshotStream = (await snapshot1.OpenReadAsync()).AsStreamForRead())
                {
                    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, (ICloudBlob)blobs[0]);
                AssertAreEqual(snapshot2, (ICloudBlob)blobs[1]);
                AssertAreEqual(blob, (ICloudBlob)blobs[2]);
                AssertAreEqual(snapshotCopy, (ICloudBlob)blobs[3]);
            }
            finally
            {
                container.DeleteIfExistsAsync().AsTask().Wait();
            }
        }
开发者ID:DaC24,项目名称:azure-storage-net,代码行数:77,代码来源:CloudBlockBlobTest.cs

示例3: TestBlobSASAsync

        /// <summary>
        /// Tests a blob SAS to determine which operations it allows.
        /// </summary>
        /// <param name="sasUri">A string containing a URI with a SAS appended.</param>
        /// <param name="blobContent">A string content content to write to the blob.</param>
        /// <returns>A Task object.</returns>
        private static async Task TestBlobSASAsync(string sasUri, string blobContent)
        {
            // Try performing blob operations using the SAS provided.

            // Return a reference to the blob using the SAS URI.
            CloudBlockBlob blob = new CloudBlockBlob(new Uri(sasUri));

            // Create operation: Upload a blob with the specified name to the container.
            // If the blob does not exist, it will be created. If it does exist, it will be overwritten.
            try
            {
                MemoryStream msWrite = new MemoryStream(Encoding.UTF8.GetBytes(blobContent));
                msWrite.Position = 0;
                using (msWrite)
                {
                    await blob.UploadFromStreamAsync(msWrite);
                }

                Console.WriteLine("Create operation succeeded for SAS {0}", sasUri);
                Console.WriteLine();
            }
            catch (StorageException e)
            {
                if (e.RequestInformation.HttpStatusCode == 403)
                {
                    Console.WriteLine("Create operation failed for SAS {0}", sasUri);
                    Console.WriteLine("Additional error information: " + e.Message);
                    Console.WriteLine();
                }
                else
                {
                    Console.WriteLine(e.Message);
                    Console.ReadLine();
                    throw;
                }
            }

            // Write operation: Add metadata to the blob
            try
            {
                await blob.FetchAttributesAsync();
                string rnd = new Random().Next().ToString();
                string metadataName = "name";
                string metadataValue = "value";
                blob.Metadata.Add(metadataName, metadataValue);
                await blob.SetMetadataAsync();

                Console.WriteLine("Write operation succeeded for SAS {0}", sasUri);
                Console.WriteLine();
            }
            catch (StorageException e)
            {
                if (e.RequestInformation.HttpStatusCode == 403)
                {
                    Console.WriteLine("Write operation failed for SAS {0}", sasUri);
                    Console.WriteLine("Additional error information: " + e.Message);
                    Console.WriteLine();
                }
                else
                {
                    Console.WriteLine(e.Message);
                    Console.ReadLine();
                    throw;
                }
            }

            // Read operation: Read the contents of the blob.
            try
            {
                MemoryStream msRead = new MemoryStream();
                using (msRead)
                {
                    await blob.DownloadToStreamAsync(msRead);
                    msRead.Position = 0;
                    using (StreamReader reader = new StreamReader(msRead, true))
                    {
                        string line;
                        while ((line = reader.ReadLine()) != null)
                        {
                            Console.WriteLine(line);
                        }
                    }

                    Console.WriteLine();
                }

                Console.WriteLine("Read operation succeeded for SAS {0}", sasUri);
                Console.WriteLine();
            }
            catch (StorageException e)
            {
                if (e.RequestInformation.HttpStatusCode == 403)
                {
                    Console.WriteLine("Read operation failed for SAS {0}", sasUri);
//.........这里部分代码省略.........
开发者ID:tamram,项目名称:storage-blob-dotnet-getting-started,代码行数:101,代码来源:Advanced.cs

示例4: BlobReadExpectLeaseSuccessAsync

        /// <summary>
        /// Test blob reads, expecting success.
        /// </summary>
        /// <param name="testBlob">The blob to test.</param>
        /// <param name="targetBlob">The blob to use for the target of copy operations.</param>
        /// <param name="testAccessCondition">The access condition to use.</param>
        private async Task BlobReadExpectLeaseSuccessAsync(CloudBlockBlob testBlob, AccessCondition testAccessCondition)
        {
            await testBlob.FetchAttributesAsync(testAccessCondition, null /* options */, null);
            await (await testBlob.SnapshotAsync(null /* metadata */, testAccessCondition, null /* options */, null)).DeleteAsync();
            await DownloadTextAsync(testBlob, Encoding.UTF8, testAccessCondition, null /* options */, null);

            var readStream = await testBlob.OpenReadAsync(testAccessCondition, null /* options */, null);
            Stream stream = readStream.AsStreamForRead();
            stream.ReadByte();
        }
开发者ID:benaadams,项目名称:azure-storage-net,代码行数:16,代码来源:LeaseTests.cs

示例5: BlobReadExpectLeaseFailureAsync

        /// <summary>
        /// Test blob reads, expecting lease failure.
        /// </summary>
        /// <param name="testBlob">The blob to test.</param>
        /// <param name="targetBlob">The blob to use for the target of copy operations.</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 async Task BlobReadExpectLeaseFailureAsync(CloudBlockBlob testBlob, CloudBlockBlob targetBlob, AccessCondition testAccessCondition, HttpStatusCode expectedStatusCode, string expectedErrorCode, string description)
        {
            OperationContext operationContext = new OperationContext();

            // FetchAttributes is a HEAD request with no extended error info, so it returns with the generic ConditionFailed error code.
            await TestHelper.ExpectedExceptionAsync(
                async () => await testBlob.FetchAttributesAsync(testAccessCondition, null /* options */, operationContext),
                operationContext,
                description + "(Fetch Attributes)",
                HttpStatusCode.PreconditionFailed);

            await TestHelper.ExpectedExceptionAsync(
                async () => await testBlob.SnapshotAsync(null /* metadata */, testAccessCondition, null /* options */, operationContext),
                operationContext,
                description + " (Create Snapshot)",
                expectedStatusCode,
                expectedErrorCode);
            await TestHelper.ExpectedExceptionAsync(
                async () => await DownloadTextAsync(testBlob, Encoding.UTF8, testAccessCondition, null /* options */, operationContext),
                operationContext,
                description + " (Download Text)",
                expectedStatusCode,
                expectedErrorCode);

            await TestHelper.ExpectedExceptionAsync(
                async () => await testBlob.OpenReadAsync(testAccessCondition, null /* options */, operationContext),
                operationContext,
                description + " (Read Stream)",
                expectedStatusCode/*,
                expectedErrorCode*/);
        }
开发者ID:benaadams,项目名称:azure-storage-net,代码行数:39,代码来源:LeaseTests.cs

示例6: BlobWriteExpectLeaseSuccessAsync

        /// <summary>
        /// Test blob writing, expecting success.
        /// </summary>
        /// <param name="testBlob">The blob to test.</param>
        /// <param name="sourceBlob">A blob to use as the source of a copy.</param>
        /// <param name="testAccessCondition">The access condition to use.</param>
        private async Task BlobWriteExpectLeaseSuccessAsync(CloudBlockBlob testBlob, CloudBlob sourceBlob, AccessCondition testAccessCondition)
        {
            await testBlob.SetMetadataAsync(testAccessCondition, null /* options */, null);
            await testBlob.SetPropertiesAsync(testAccessCondition, null /* options */, null);
            await UploadTextAsync(testBlob, "No Problem", Encoding.UTF8, testAccessCondition, null /* options */, null);
            await testBlob.StartCopyAsync(TestHelper.Defiddler(sourceBlob.Uri), null /* source access condition */, testAccessCondition, null /* options */, null);

            while (testBlob.CopyState.Status == CopyStatus.Pending)
            {
                await Task.Delay(1000);
                await testBlob.FetchAttributesAsync();
            }

            var writeStream = await testBlob.OpenWriteAsync(testAccessCondition, null /* options */, null);
            Stream stream = writeStream.AsStreamForWrite();
            stream.WriteByte(0);
            await stream.FlushAsync();

            await testBlob.DeleteAsync(DeleteSnapshotsOption.None, testAccessCondition, null /* options */, null);
        }
开发者ID:benaadams,项目名称:azure-storage-net,代码行数:26,代码来源:LeaseTests.cs

示例7: TouchBlobAsync

 public static async Task TouchBlobAsync(CloudBlockBlob blob)
 {
     await blob.FetchAttributesAsync();
     blob.Metadata.Add("touch", Guid.NewGuid().ToString("N"));
     await blob.SetMetadataAsync();
 }
开发者ID:sbidy,项目名称:iot-journey,代码行数:6,代码来源:AzureStorageHelpers.cs

示例8: BlobReadExpectLeaseSuccessTask

        /// <summary>
        /// Test blob reads, expecting success.
        /// </summary>
        /// <param name="testBlob">The blob to test.</param>
        /// <param name="testAccessCondition">The access condition to use.</param>
        private void BlobReadExpectLeaseSuccessTask(CloudBlockBlob testBlob, AccessCondition testAccessCondition)
        {
            testBlob.FetchAttributesAsync(testAccessCondition, null /* options */, new OperationContext());
            testBlob.SnapshotAsync(null /* metadata */, testAccessCondition, null /* options */, new OperationContext()).Result.Delete();
            DownloadTextTask(testBlob, Encoding.UTF8, testAccessCondition, null /* options */);

            Stream stream = testBlob.OpenReadAsync(testAccessCondition, null /* options */, new OperationContext()).Result;
            stream.ReadByte();
        }
开发者ID:benaadams,项目名称:azure-storage-net,代码行数:14,代码来源:LeaseTests.cs

示例9: BlobWriteExpectLeaseSuccessTask

        /// <summary>
        /// Test blob writing, expecting success.
        /// </summary>
        /// <param name="testBlob">The blob to test.</param>
        /// <param name="sourceBlob">A blob to use as the source of a copy.</param>
        /// <param name="testAccessCondition">The access condition to use.</param>
        private void BlobWriteExpectLeaseSuccessTask(CloudBlockBlob testBlob, CloudBlob sourceBlob, AccessCondition testAccessCondition)
        {
            testBlob.SetMetadataAsync(testAccessCondition, null /* options */, new OperationContext()).Wait();
            testBlob.SetPropertiesAsync(testAccessCondition, null /* options */, new OperationContext()).Wait();
            UploadTextTask(testBlob, "No Problem", Encoding.UTF8, testAccessCondition, null /* options */, new OperationContext());
            testBlob.StartCopyAsync(
                TestHelper.Defiddler(sourceBlob.Uri),
                null /* source access condition */,
                testAccessCondition,
                null /* options */,
                new OperationContext()).Wait();

            while (testBlob.CopyState.Status == CopyStatus.Pending)
            {
                Thread.Sleep(1000);
                testBlob.FetchAttributesAsync().Wait();
            }

            Stream stream = testBlob.OpenWriteAsync(testAccessCondition, null /* options */, new OperationContext()).Result;
            stream.WriteByte(0);
            stream.Flush();

            testBlob.DeleteAsync(DeleteSnapshotsOption.None, testAccessCondition, null /* options */, new OperationContext());
        }
开发者ID:benaadams,项目名称:azure-storage-net,代码行数:30,代码来源:LeaseTests.cs

示例10: CopyDirectoryTo

        /// <summary>
        /// Copies the log directory to the 
        /// </summary>
        public async Task<CopyableBlob[]> CopyDirectoryTo(string accountName, string accountKey,
            string sourceContainerName, string directoryName, string destinationContanerName, string copyDirectoryPrefix = "")
        {
            var copyIds = new List<CopyableBlob>();
            // get a list of the source account blobs
            var sourceAccountStorageCredentials = new StorageCredentials(AccountName, AccountKey);
            var account = new CloudStorageAccount(sourceAccountStorageCredentials, true);
            var client = account.CreateCloudBlobClient();
            var sourceContainer = client.GetContainerReference(sourceContainerName);
            var blobs = sourceContainer.ListBlobs(directoryName, true);
            // get a list of the destination account blobs 
            var destinationAccountCredentials = new StorageCredentials(accountName, accountKey);
            var destinationAccount = new CloudStorageAccount(destinationAccountCredentials, true);
            var destinationClient = destinationAccount.CreateCloudBlobClient();
            var destinationContainer = destinationClient.GetContainerReference(destinationContanerName);
            destinationContainer.CreateIfNotExists();
            foreach (var blob in blobs)
            {
                var blockBlob = blob as CloudBlockBlob;
                var destinationBlockBlob =
                    destinationContainer.GetBlockBlobReference(String.Format("{0}/{1}", copyDirectoryPrefix, 
                        String.Join("", blob.Uri.Segments.Skip(3).Take(5).ToArray())));
                var sas = blockBlob.GetSharedAccessSignature(new SharedAccessBlobPolicy()
                {
                    Permissions = SharedAccessBlobPermissions.Read,
                    SharedAccessStartTime = DateTime.Now.AddMinutes(-15),
                    SharedAccessExpiryTime = DateTime.Now.AddHours(1)
                });
                blockBlob = new CloudBlockBlob(new Uri(blockBlob.Uri.AbsoluteUri + sas));
  
                copyIds.Add(new CopyableBlob()
                {
                    // the use of a SAS fubars this 
                    CopyId = await destinationBlockBlob.StartCopyFromBlobAsync(blockBlob),
                    BlobUri = destinationBlockBlob.Uri,
                    ContainerName = destinationContanerName,
                    Size = (double) blockBlob.Properties.Length/1024,
                    PercentageCopied = 0
                });
            }
            CopyingBlobs = copyIds.ToArray();

            int completed = 0;
            while (true)
            {
                foreach (var blob in copyIds)
                {
                    var blockBlob = new CloudBlockBlob(blob.BlobUri, destinationAccountCredentials);
                    await blockBlob.FetchAttributesAsync();
                    await Task.Delay(500);
                    if (blockBlob.CopyState.BytesCopied.HasValue)
                    {
                        blob.PercentageCopied =
                            Convert.ToInt32(
                                Math.Round(
                                    (double) blockBlob.CopyState.BytesCopied.Value/blockBlob.CopyState.TotalBytes.Value,
                                    2)*100);
                    }
                    if (blockBlob.CopyState.Status == CopyStatus.Success ||
                        blockBlob.CopyState.Status == CopyStatus.Failed)
                    {
                        completed++;
                    }
                    if (completed == copyIds.Count)
                        return CopyingBlobs;
                }
            }
        }
开发者ID:azurecoder,项目名称:fluent-management,代码行数:71,代码来源:BlobClient.cs

示例11: GetLastModifiedAsync

 private static async Task<DateTimeOffset> GetLastModifiedAsync(CloudBlockBlob blob)
 {
     await blob.FetchAttributesAsync().ConfigureAwait(false);
     return blob.Properties.LastModified.Value;
 }
开发者ID:smartpcr,项目名称:iot-journey,代码行数:5,代码来源:PartitionCheckpointManager.cs

示例12: StartCopyFromFile

        private async Task StartCopyFromFile(long taskId, IStorageBlobManagement destChannel, CloudFile srcFile, CloudBlockBlob destBlob)
        {
            bool destExist = true;
            try
            {
                await destBlob.FetchAttributesAsync(null, this.RequestOptions, this.OperationContext, this.CmdletCancellationToken);
            }
            catch (StorageException ex)
            {
                if (ex.IsNotFoundException())
                {
                    destExist = false;
                }
                else
                {
                    throw;
                }
            }

            if (!destExist || this.ConfirmOverwrite(srcFile.Uri.ToString(), destBlob.Uri.ToString()))
            {
                string copyId = await destBlob.StartCopyAsync(srcFile.GenerateCopySourceFile(), null, null, this.RequestOptions, this.OperationContext, this.CmdletCancellationToken);
                this.OutputStream.WriteVerbose(taskId, String.Format(Resources.CopyDestinationBlobPending, destBlob.Name, destBlob.Container.Name, copyId));
                this.WriteCloudBlobObject(taskId, destChannel, destBlob);
            }
        }
开发者ID:kjohn-msft,项目名称:azure-powershell,代码行数:26,代码来源:StartAzureStorageBlobCopy.cs


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