本文整理汇总了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();
}
}
}
示例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;
}
}
}
示例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();
}
示例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);
}