本文整理汇总了C#中IStorageBlobManagement.GetBlobReferenceFromServerAsync方法的典型用法代码示例。如果您正苦于以下问题:C# IStorageBlobManagement.GetBlobReferenceFromServerAsync方法的具体用法?C# IStorageBlobManagement.GetBlobReferenceFromServerAsync怎么用?C# IStorageBlobManagement.GetBlobReferenceFromServerAsync使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IStorageBlobManagement
的用法示例。
在下文中一共展示了IStorageBlobManagement.GetBlobReferenceFromServerAsync方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ListBlobsByName
/// <summary>
/// list blobs by blob name and container name
/// </summary>
/// <param name="containerName">container name</param>
/// <param name="blobName">blob name pattern</param>
/// <returns>An enumerable collection of IListBlobItem</returns>
internal async Task ListBlobsByName(long taskId, IStorageBlobManagement localChannel, string containerName, string blobName)
{
CloudBlobContainer container = null;
BlobRequestOptions requestOptions = RequestOptions;
AccessCondition accessCondition = null;
string prefix = string.Empty;
if (String.IsNullOrEmpty(blobName) || WildcardPattern.ContainsWildcardCharacters(blobName))
{
container = await GetCloudBlobContainerByName(localChannel, containerName);
prefix = NameUtil.GetNonWildcardPrefix(blobName);
WildcardOptions options = WildcardOptions.IgnoreCase | WildcardOptions.Compiled;
WildcardPattern wildcard = null;
if (!String.IsNullOrEmpty(blobName))
{
wildcard = new WildcardPattern(blobName, options);
}
Func<CloudBlob, bool> blobFilter = (blob) => wildcard == null || wildcard.IsMatch(blob.Name);
await ListBlobsByPrefix(taskId, localChannel, containerName, prefix, blobFilter);
}
else
{
container = await GetCloudBlobContainerByName(localChannel, containerName, true);
if (!NameUtil.IsValidBlobName(blobName))
{
throw new ArgumentException(String.Format(Resources.InvalidBlobName, blobName));
}
CloudBlob blob = await localChannel.GetBlobReferenceFromServerAsync(container, blobName, accessCondition, requestOptions, OperationContext, CmdletCancellationToken);
if (null == blob)
{
throw new ResourceNotFoundException(String.Format(Resources.BlobNotFound, blobName, containerName));
}
else
{
WriteCloudBlobObject(taskId, localChannel, blob);
}
}
}
示例2: RemoveAzureBlob
/// <summary>
/// remove azure blob
/// </summary>
/// <param name="container">CloudBlobContainer object</param>
/// <param name="blobName">blob name</param>
/// <returns>true if the blob is removed successfully, false if user cancel the remove operation</returns>
internal async Task RemoveAzureBlob(long taskId, IStorageBlobManagement localChannel, CloudBlobContainer container, string blobName)
{
if (!NameUtil.IsValidBlobName(blobName))
{
throw new ArgumentException(String.Format(Resources.InvalidBlobName, blobName));
}
ValidatePipelineCloudBlobContainer(container);
AccessCondition accessCondition = null;
BlobRequestOptions requestOptions = null;
ICloudBlob blob = await localChannel.GetBlobReferenceFromServerAsync(container, blobName, accessCondition,
requestOptions, OperationContext, CmdletCancellationToken);
if (null == blob && container.ServiceClient.Credentials.IsSharedKey)
{
throw new ResourceNotFoundException(String.Format(Resources.BlobNotFound, blobName, container.Name));
}
else
{
//Construct the blob as CloudBlockBlob no matter what's the real blob type
//We can't get the blob type if Credentials only have the delete permission and don't have read permission.
blob = container.GetBlockBlobReference(blobName);
}
await RemoveAzureBlob(taskId, localChannel, blob, true);
}