| | 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.Storage.Files.Shares.Models; |
| | 9 | |
|
| | 10 | | #pragma warning disable SA1402 // File may only contain a single type |
| | 11 | |
|
| | 12 | | namespace Azure.Storage.Files.Shares.Models |
| | 13 | | { |
| | 14 | | internal class GetSharesAsyncCollection : StorageCollectionEnumerator<ShareItem> |
| | 15 | | { |
| | 16 | | private readonly ShareServiceClient _client; |
| | 17 | | private readonly ShareTraits _traits; |
| | 18 | | private readonly ShareStates _states; |
| | 19 | | private readonly string _prefix; |
| | 20 | |
|
| 10 | 21 | | public GetSharesAsyncCollection( |
| 10 | 22 | | ShareServiceClient client, |
| 10 | 23 | | ShareTraits traits = ShareTraits.None, |
| 10 | 24 | | ShareStates states = ShareStates.None, |
| 10 | 25 | | string prefix = default) |
| | 26 | | { |
| 10 | 27 | | _client = client; |
| 10 | 28 | | _traits = traits; |
| 10 | 29 | | _states = states; |
| 10 | 30 | | _prefix = prefix; |
| 10 | 31 | | } |
| | 32 | |
|
| | 33 | | public override async ValueTask<Page<ShareItem>> GetNextPageAsync( |
| | 34 | | string continuationToken, |
| | 35 | | int? pageSizeHint, |
| | 36 | | bool async, |
| | 37 | | CancellationToken cancellationToken) |
| | 38 | | { |
| 10 | 39 | | Response<SharesSegment> response = await _client.GetSharesInternal( |
| 10 | 40 | | continuationToken, |
| 10 | 41 | | _traits, |
| 10 | 42 | | _states, |
| 10 | 43 | | _prefix, |
| 10 | 44 | | pageSizeHint, |
| 10 | 45 | | async, |
| 10 | 46 | | cancellationToken).ConfigureAwait(false); |
| | 47 | |
|
| 8 | 48 | | return Page<ShareItem>.FromValues( |
| 8 | 49 | | response.Value.ShareItems.ToArray(), |
| 8 | 50 | | response.Value.NextMarker, |
| 8 | 51 | | response.GetRawResponse()); |
| 8 | 52 | | } |
| | 53 | | } |
| | 54 | | } |
| | 55 | |
|
| | 56 | | namespace Azure.Storage.Files.Shares |
| | 57 | | { |
| | 58 | | /// <summary> |
| | 59 | | /// File service helpers. |
| | 60 | | /// </summary> |
| | 61 | | internal static partial class ShareExtensions |
| | 62 | | { |
| | 63 | | /// <summary> |
| | 64 | | /// Convert the details into ListSharesIncludeType values. |
| | 65 | | /// </summary> |
| | 66 | | /// <returns>ListSharesIncludeType values</returns> |
| | 67 | | internal static IEnumerable<ListSharesIncludeType> AsIncludeItems(ShareTraits traits, ShareStates states) |
| | 68 | | { |
| | 69 | | // NOTE: Multiple strings MUST be appended in alphabetic order or signing the string for authentication fail |
| | 70 | | // TODO: Remove this requirement by pushing it closer to header generation. |
| | 71 | | var items = new List<ListSharesIncludeType>(); |
| | 72 | | if ((states & ShareStates.Deleted) == ShareStates.Deleted) |
| | 73 | | { |
| | 74 | | items.Add(ListSharesIncludeType.Deleted); |
| | 75 | | } |
| | 76 | | if ((traits & ShareTraits.Metadata) == ShareTraits.Metadata) |
| | 77 | | { |
| | 78 | | items.Add(ListSharesIncludeType.Metadata); |
| | 79 | | } |
| | 80 | | if ((states & ShareStates.Snapshots) == ShareStates.Snapshots) |
| | 81 | | { |
| | 82 | | items.Add(ListSharesIncludeType.Snapshots); |
| | 83 | | } |
| | 84 | | return items.Count > 0 ? items : null; |
| | 85 | | } |
| | 86 | | } |
| | 87 | | } |