internal async Task GetBlobTag(long taskId, IStorageBlobManagement localChannel, BlobBaseClient blob, bool isValidBlob) { if (!isValidBlob) { ValidatePipelineCloudBlobTrack2(blob); } IDictionary <string, string> tags = (await blob.GetTagsAsync(BlobRequestConditions, this.CmdletCancellationToken).ConfigureAwait(false)).Value.Tags; OutputStream.WriteObject(taskId, tags is null ? null : tags.ToHashtable()); }
/// <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, bool includeDeleted = false, bool includeVersion = false) { CloudBlobContainer container = null; BlobRequestOptions requestOptions = RequestOptions; AccessCondition accessCondition = null; string prefix = string.Empty; if (String.IsNullOrEmpty(blobName) || WildcardPattern.ContainsWildcardCharacters(blobName) || includeDeleted) { container = await GetCloudBlobContainerByName(localChannel, containerName).ConfigureAwait(false); prefix = NameUtil.GetNonWildcardPrefix(blobName); WildcardOptions options = WildcardOptions.IgnoreCase | WildcardOptions.Compiled; WildcardPattern wildcard = null; if (!String.IsNullOrEmpty(blobName)) { wildcard = new WildcardPattern(blobName, options); } Func <string, bool> blobFilter = (blobNameToFilte) => wildcard == null || wildcard.IsMatch(blobNameToFilte); await ListBlobsByPrefix(taskId, localChannel, containerName, prefix, blobFilter, includeDeleted, IncludeVersion).ConfigureAwait(false); } else { container = await GetCloudBlobContainerByName(localChannel, containerName, true).ConfigureAwait(false); BlobContainerClient track2container = AzureStorageContainer.GetTrack2BlobContainerClient(container, localChannel.StorageContext, ClientOptions); if (!NameUtil.IsValidBlobName(blobName)) { throw new ArgumentException(String.Format(Resources.InvalidBlobName, blobName)); } BlobBaseClient blobClient = null; if (UseTrack2Sdk()) // User Track2 SDK { blobClient = Util.GetTrack2BlobClient(track2container, blobName, localChannel.StorageContext, this.VersionId, false, this.SnapshotTime is null ? null : this.SnapshotTime.Value.ToString("o"), ClientOptions); global::Azure.Storage.Blobs.Models.BlobProperties blobProperties; try { blobProperties = blobClient.GetProperties(BlobRequestConditions, cancellationToken: CmdletCancellationToken); } catch (global::Azure.RequestFailedException e) when(e.Status == 404) { throw new ResourceNotFoundException(String.Format(Resources.BlobNotFound, blobName, containerName)); } blobClient = Util.GetTrack2BlobClient(track2container, blobName, localChannel.StorageContext, this.VersionId, blobProperties.IsLatestVersion, this.SnapshotTime is null ? null : this.SnapshotTime.Value.ToString("o"), ClientOptions, blobProperties.BlobType); AzureStorageBlob outputBlob = new AzureStorageBlob(blobClient, localChannel.StorageContext, blobProperties, ClientOptions); if (this.IncludeTag.IsPresent) { IDictionary <string, string> tags = (await blobClient.GetTagsAsync(null, this.CmdletCancellationToken).ConfigureAwait(false)).Value.Tags; if (tags != null) { outputBlob.Tags = tags.ToHashtable(); outputBlob.TagCount = tags.Count; } } OutputStream.WriteObject(taskId, outputBlob); } else // Use Track1 SDK { CloudBlob blob = await localChannel.GetBlobReferenceFromServerAsync(container, blobName, this.SnapshotTime, accessCondition, requestOptions, OperationContext, CmdletCancellationToken).ConfigureAwait(false); if (null == blob) { throw new ResourceNotFoundException(String.Format(Resources.BlobNotFound, blobName, containerName)); } else { OutputStream.WriteObject(taskId, new AzureStorageBlob(blob, localChannel.StorageContext, ClientOptions)); } } } }