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


C# CloudBlobContainer.GetBlobReferenceFromServerAsync方法代码示例

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


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

示例1: EnsureCopiedToContainerAsync

        private static async Task EnsureCopiedToContainerAsync(ILeasedLogFile logFile, CloudBlobContainer targetContainer, Exception e = null)
        {
            var archivedBlob = targetContainer.GetBlockBlobReference(logFile.Blob.Name);
            if (!await archivedBlob.ExistsAsync())
            {
                await archivedBlob.StartCopyFromBlobAsync(logFile.Blob);

                archivedBlob = (CloudBlockBlob)await targetContainer.GetBlobReferenceFromServerAsync(logFile.Blob.Name);

                while (archivedBlob.CopyState.Status == CopyStatus.Pending)
                {
                    Task.Delay(TimeSpan.FromSeconds(1)).Wait();
                    archivedBlob = (CloudBlockBlob)await targetContainer.GetBlobReferenceFromServerAsync(logFile.Blob.Name);
                }

                await archivedBlob.FetchAttributesAsync();

                if (e != null)
                {
                    // add the job error to the blob's metadata
                    if (archivedBlob.Metadata.ContainsKey("JobError"))
                    {
                        archivedBlob.Metadata["JobError"] = e.ToString().Replace("\r\n", string.Empty);
                    }
                    else
                    {
                        archivedBlob.Metadata.Add("JobError", e.ToString().Replace("\r\n", string.Empty));
                    }
                    await archivedBlob.SetMetadataAsync();
                }
                else if (archivedBlob.Metadata.ContainsKey("JobError"))
                {
                    archivedBlob.Metadata.Remove("JobError");
                    await archivedBlob.SetMetadataAsync();
                }
            }
        }
开发者ID:girish,项目名称:NuGet.Jobs,代码行数:37,代码来源:LogFileProcessor.cs

示例2: GetBlobReferenceFromServerAsync

 /// <summary>
 /// Return a task that asynchronously get the blob reference from server
 /// </summary>
 /// <param name="container">CloudBlobContainer object</param>
 /// <param name="blobName">Blob name</param>
 /// <param name="accessCondition">Access condition</param>
 /// <param name="options">Blob request options</param>
 /// <param name="operationContext">Operation context</param>
 /// <param name="cmdletCancellationToken">Cancellation token</param>
 /// <returns>A task object that asynchronously get the blob reference from server</returns>
 public async Task<ICloudBlob> GetBlobReferenceFromServerAsync(CloudBlobContainer container, string blobName, AccessCondition accessCondition, BlobRequestOptions options, OperationContext operationContext, CancellationToken cancellationToken)
 {
     try
     {
         ICloudBlob blob = await container.GetBlobReferenceFromServerAsync(blobName, accessCondition, options, operationContext, cancellationToken);
         return blob;
     }
     catch (StorageException e)
     {
         if (e.IsNotFoundException())
         {
             return null;
         }
         else
         {
             throw;
         }
     }
 }
开发者ID:NordPool,项目名称:azure-sdk-tools,代码行数:29,代码来源:StorageBlobManagement.cs

示例3: GetExistingBlobReferenceAsync

        /// <summary>
        /// Gets a reference to a blob by making a request to the service.
        /// </summary>
        /// <param name="container">The container.</param>
        /// <param name="blobName">The blob name.</param>
        /// <returns>A Task object.</returns>
        private static async Task GetExistingBlobReferenceAsync(CloudBlobContainer container, string blobName)
        {
            try
            {
                // Get a reference to a blob with a request to the server.
                // If the blob does not exist, this call will fail with a 404 (Not Found).
                ICloudBlob blob = await container.GetBlobReferenceFromServerAsync(blobName);

                // The previous call gets the blob's properties, so it's not necessary to call FetchAttributes
                // to read a property.
                Console.WriteLine("Blob {0} was last modified at {1} local time.", blobName,
                    blob.Properties.LastModified.Value.LocalDateTime);
            }
            catch (StorageException e)
            {
                if (e.RequestInformation.HttpStatusCode == 404)
                {
                    Console.WriteLine("Blob {0} does not exist.", blobName);
                    Console.WriteLine("Additional error information: " + e.Message);
                }
                else
                {
                    Console.WriteLine(e.Message);
                    Console.ReadLine();
                    throw;
                }
            }

            Console.WriteLine();
        }
开发者ID:tamram,项目名称:storage-blob-dotnet-getting-started,代码行数:36,代码来源:Advanced.cs

示例4: TransferBlob

        private async Task TransferBlob(
            CloudBlobContainer fromContainer,
            CloudBlobContainer toContainer,
            string blobName,
            CancellationToken cancellationToken)
        {
            var requestOptions = new BlobRequestOptions()
            {
                RetryPolicy = new LinearRetry(TimeSpan.FromSeconds(2), 5)
            };

            var destBlobRef = toContainer.GetBlobReference(blobName);
            var blob = fromContainer.GetBlobReference(blobName);

            await destBlobRef.StartCopyAsync(
                               blob.Uri,
                               AccessCondition.GenerateEmptyCondition(),
                               AccessCondition.GenerateEmptyCondition(),
                               requestOptions,
                               null,
                               cancellationToken);

            var allCopied = false;
            var copyFailed = false;

            do
            {
                var blobRef = await toContainer.GetBlobReferenceFromServerAsync(blobName, cancellationToken);
                if (blobRef.CopyState.Status == CopyStatus.Aborted || blobRef.CopyState.Status == CopyStatus.Failed)
                {
                    this.logger.LogError($"Cannot copy {blobRef.Uri}");
                    copyFailed = true;
                }

                allCopied = blobRef.CopyState.Status != CopyStatus.Pending;
            }
            while (!allCopied || copyFailed);

            await blob.DeleteAsync(cancellationToken);
        }
开发者ID:Ercenk,项目名称:toprak,代码行数:40,代码来源:ImageRepository.cs


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