| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | #pragma warning disable SA1402 // File may only contain a single type |
| | 5 | |
|
| | 6 | | using System.Collections.Generic; |
| | 7 | | using System.Diagnostics; |
| | 8 | | using System.Linq; |
| | 9 | | using System.Threading; |
| | 10 | | using System.Threading.Tasks; |
| | 11 | | using Azure.Core.Pipeline; |
| | 12 | | using Azure.Storage.Blobs.Models; |
| | 13 | |
|
| | 14 | | namespace Azure.Storage.Blobs.Models |
| | 15 | | { |
| | 16 | | internal class GetBlobContainersAsyncCollection : StorageCollectionEnumerator<BlobContainerItem> |
| | 17 | | { |
| | 18 | | private readonly BlobServiceClient _client; |
| | 19 | | private readonly BlobContainerTraits _traits; |
| | 20 | | private readonly BlobContainerStates _states; |
| | 21 | | private readonly string _prefix; |
| | 22 | |
|
| 68 | 23 | | public GetBlobContainersAsyncCollection( |
| 68 | 24 | | BlobServiceClient client, |
| 68 | 25 | | BlobContainerTraits traits, |
| 68 | 26 | | BlobContainerStates states, |
| 68 | 27 | | string prefix = default) |
| | 28 | | { |
| 68 | 29 | | _client = client; |
| 68 | 30 | | _traits = traits; |
| 68 | 31 | | _states = states; |
| 68 | 32 | | _prefix = prefix; |
| 68 | 33 | | } |
| | 34 | |
|
| | 35 | | public override async ValueTask<Page<BlobContainerItem>> GetNextPageAsync( |
| | 36 | | string continuationToken, |
| | 37 | | int? pageSizeHint, |
| | 38 | | bool async, |
| | 39 | | CancellationToken cancellationToken) |
| | 40 | | { |
| | 41 | |
|
| 68 | 42 | | Response<BlobContainersSegment> response = await _client.GetBlobContainersInternal( |
| 68 | 43 | | continuationToken, |
| 68 | 44 | | _traits, |
| 68 | 45 | | _states, |
| 68 | 46 | | _prefix, |
| 68 | 47 | | pageSizeHint, |
| 68 | 48 | | async, |
| 68 | 49 | | cancellationToken).ConfigureAwait(false); |
| | 50 | |
|
| 64 | 51 | | return Page<BlobContainerItem>.FromValues( |
| 64 | 52 | | response.Value.BlobContainerItems.ToArray(), |
| 64 | 53 | | response.Value.NextMarker, |
| 64 | 54 | | response.GetRawResponse()); |
| 64 | 55 | | } |
| | 56 | | } |
| | 57 | | } |
| | 58 | |
|
| | 59 | | namespace Azure.Storage.Blobs |
| | 60 | | { |
| | 61 | | /// <summary> |
| | 62 | | /// BlobContainerTraits/BlobContianerStates enum methods. |
| | 63 | | /// </summary> |
| | 64 | | internal static partial class BlobExtensions |
| | 65 | | { |
| | 66 | | /// <summary> |
| | 67 | | /// Convert the details into ListContainersIncludeType values. |
| | 68 | | /// </summary> |
| | 69 | | /// <returns>ListContainersIncludeType values</returns> |
| | 70 | | internal static IEnumerable<ListContainersIncludeType> AsIncludeItems(BlobContainerTraits traits, BlobContainerS |
| | 71 | | { |
| | 72 | | // Remove this line |
| | 73 | | Debug.Assert(states == BlobContainerStates.None); |
| | 74 | | var items = new List<ListContainersIncludeType>(); |
| | 75 | | // Uncomment when feature is re-enabled. |
| | 76 | | //if ((states & BlobContainerStates.Deleted) == BlobContainerStates.Deleted) |
| | 77 | | //{ |
| | 78 | | // items.Add(ListContainersIncludeType.Deleted); |
| | 79 | | //} |
| | 80 | | if ((traits & BlobContainerTraits.Metadata) == BlobContainerTraits.Metadata) |
| | 81 | | { |
| | 82 | | items.Add(ListContainersIncludeType.Metadata); |
| | 83 | | } |
| | 84 | |
|
| | 85 | | return items.Count > 0 ? items : null; |
| | 86 | | } |
| | 87 | | } |
| | 88 | | } |