| | | 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.Linq; |
| | | 8 | | using System.Threading; |
| | | 9 | | using System.Threading.Tasks; |
| | | 10 | | using Azure.Core.Pipeline; |
| | | 11 | | using Azure.Storage.Blobs.Models; |
| | | 12 | | |
| | | 13 | | namespace Azure.Storage.Blobs.Models |
| | | 14 | | { |
| | | 15 | | internal class GetBlobsAsyncCollection : StorageCollectionEnumerator<BlobItem> |
| | | 16 | | { |
| | | 17 | | private readonly BlobContainerClient _client; |
| | | 18 | | private readonly BlobTraits _traits; |
| | | 19 | | private readonly BlobStates _states; |
| | | 20 | | private readonly string _prefix; |
| | | 21 | | |
| | 146 | 22 | | public GetBlobsAsyncCollection( |
| | 146 | 23 | | BlobContainerClient client, |
| | 146 | 24 | | BlobTraits traits, |
| | 146 | 25 | | BlobStates states, |
| | 146 | 26 | | string prefix) |
| | | 27 | | { |
| | 146 | 28 | | _client = client; |
| | 146 | 29 | | _traits = traits; |
| | 146 | 30 | | _states = states; |
| | 146 | 31 | | _prefix = prefix; |
| | 146 | 32 | | } |
| | | 33 | | |
| | | 34 | | public override async ValueTask<Page<BlobItem>> GetNextPageAsync( |
| | | 35 | | string continuationToken, |
| | | 36 | | int? pageSizeHint, |
| | | 37 | | bool async, |
| | | 38 | | CancellationToken cancellationToken) |
| | | 39 | | { |
| | 146 | 40 | | Response<BlobsFlatSegment> response = await _client.GetBlobsInternal( |
| | 146 | 41 | | continuationToken, |
| | 146 | 42 | | _traits, |
| | 146 | 43 | | _states, |
| | 146 | 44 | | _prefix, |
| | 146 | 45 | | pageSizeHint, |
| | 146 | 46 | | async, |
| | 146 | 47 | | cancellationToken).ConfigureAwait(false); |
| | | 48 | | |
| | 142 | 49 | | return Page<BlobItem>.FromValues( |
| | 142 | 50 | | response.Value.BlobItems.ToBlobItems().ToArray(), |
| | 142 | 51 | | response.Value.NextMarker, |
| | 142 | 52 | | response.GetRawResponse()); |
| | 142 | 53 | | } |
| | | 54 | | } |
| | | 55 | | } |
| | | 56 | | |
| | | 57 | | namespace Azure.Storage.Blobs |
| | | 58 | | { |
| | | 59 | | /// <summary> |
| | | 60 | | /// BlobTraits/BlobStates enum methods |
| | | 61 | | /// </summary> |
| | | 62 | | internal static partial class BlobExtensions |
| | | 63 | | { |
| | | 64 | | /// <summary> |
| | | 65 | | /// Convert the details into ListBlobsIncludeItem values. |
| | | 66 | | /// </summary> |
| | | 67 | | /// <returns>ListBlobsIncludeItem values</returns> |
| | | 68 | | internal static IEnumerable<ListBlobsIncludeItem> AsIncludeItems(BlobTraits traits, BlobStates states) |
| | | 69 | | { |
| | | 70 | | // NOTE: Multiple strings MUST be appended in alphabetic order or signing the string for authentication fail |
| | | 71 | | // TODO: Remove this requirement by pushing it closer to header generation. |
| | | 72 | | var items = new List<ListBlobsIncludeItem>(); |
| | | 73 | | if ((traits & BlobTraits.CopyStatus) == BlobTraits.CopyStatus) |
| | | 74 | | { |
| | | 75 | | items.Add(ListBlobsIncludeItem.Copy); |
| | | 76 | | } |
| | | 77 | | if ((states & BlobStates.Deleted) == BlobStates.Deleted) |
| | | 78 | | { |
| | | 79 | | items.Add(ListBlobsIncludeItem.Deleted); |
| | | 80 | | } |
| | | 81 | | if ((traits & BlobTraits.Metadata) == BlobTraits.Metadata) |
| | | 82 | | { |
| | | 83 | | items.Add(ListBlobsIncludeItem.Metadata); |
| | | 84 | | } |
| | | 85 | | if ((states & BlobStates.Snapshots) == BlobStates.Snapshots) |
| | | 86 | | { |
| | | 87 | | items.Add(ListBlobsIncludeItem.Snapshots); |
| | | 88 | | } |
| | | 89 | | if ((traits & BlobTraits.Tags) == BlobTraits.Tags) |
| | | 90 | | { |
| | | 91 | | items.Add(ListBlobsIncludeItem.Tags); |
| | | 92 | | } |
| | | 93 | | if ((states & BlobStates.Uncommitted) == BlobStates.Uncommitted) |
| | | 94 | | { |
| | | 95 | | items.Add(ListBlobsIncludeItem.Uncommittedblobs); |
| | | 96 | | } |
| | | 97 | | if ((states & BlobStates.Version) == BlobStates.Version) |
| | | 98 | | { |
| | | 99 | | items.Add(ListBlobsIncludeItem.Versions); |
| | | 100 | | } |
| | | 101 | | return items.Count > 0 ? items : null; |
| | | 102 | | } |
| | | 103 | | } |
| | | 104 | | } |