當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。