| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | using System.Collections.Generic; |
| | 5 | | using System.Linq; |
| | 6 | | using System.Threading; |
| | 7 | | using System.Threading.Tasks; |
| | 8 | | using Azure.Core.Pipeline; |
| | 9 | |
|
| | 10 | | namespace Azure.Storage.Blobs.Models |
| | 11 | | { |
| | 12 | | internal class GetBlobsByHierarchyAsyncCollection : StorageCollectionEnumerator<BlobHierarchyItem> |
| | 13 | | { |
| | 14 | | private readonly BlobContainerClient _client; |
| | 15 | | private readonly BlobTraits _traits; |
| | 16 | | private readonly BlobStates _states; |
| | 17 | | private readonly string _delimiter; |
| | 18 | | private readonly string _prefix; |
| | 19 | |
|
| 426 | 20 | | public GetBlobsByHierarchyAsyncCollection( |
| 426 | 21 | | BlobContainerClient client, |
| 426 | 22 | | string delimiter, |
| 426 | 23 | | BlobTraits traits, |
| 426 | 24 | | BlobStates states, |
| 426 | 25 | | string prefix) |
| | 26 | | { |
| 426 | 27 | | _client = client; |
| 426 | 28 | | _delimiter = delimiter; |
| 426 | 29 | | _traits = traits; |
| 426 | 30 | | _states = states; |
| 426 | 31 | | _prefix = prefix; |
| 426 | 32 | | } |
| | 33 | |
|
| | 34 | | public override async ValueTask<Page<BlobHierarchyItem>> GetNextPageAsync( |
| | 35 | | string continuationToken, |
| | 36 | | int? pageSizeHint, |
| | 37 | | bool async, |
| | 38 | | CancellationToken cancellationToken) |
| | 39 | | { |
| 426 | 40 | | Response<BlobsHierarchySegment> response = await _client.GetBlobsByHierarchyInternal( |
| 426 | 41 | | continuationToken, |
| 426 | 42 | | _delimiter, |
| 426 | 43 | | _traits, |
| 426 | 44 | | _states, |
| 426 | 45 | | _prefix, |
| 426 | 46 | | pageSizeHint, |
| 426 | 47 | | async, |
| 426 | 48 | | cancellationToken).ConfigureAwait(false); |
| | 49 | |
|
| 422 | 50 | | var items = new List<BlobHierarchyItem>(); |
| 582 | 51 | | items.AddRange(response.Value.BlobPrefixes.Select(p => new BlobHierarchyItem(p.Name, null))); |
| 10618 | 52 | | items.AddRange(response.Value.BlobItems.Select(b => new BlobHierarchyItem(null, b.ToBlobItem()))); |
| 422 | 53 | | return Page<BlobHierarchyItem>.FromValues( |
| 422 | 54 | | items.ToArray(), |
| 422 | 55 | | response.Value.NextMarker, |
| 422 | 56 | | response.GetRawResponse()); |
| 422 | 57 | | } |
| | 58 | | } |
| | 59 | | } |