| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | using System; |
| | 5 | | using System.Collections.Generic; |
| | 6 | |
|
| | 7 | | namespace Azure.Storage.Blobs.ChangeFeed |
| | 8 | | { |
| | 9 | | /// <summary> |
| | 10 | | /// BlobChangeFeedPagableAsync. |
| | 11 | | /// </summary> |
| | 12 | | internal class BlobChangeFeedAsyncPageable : AsyncPageable<BlobChangeFeedEvent> |
| | 13 | | { |
| | 14 | | private readonly ChangeFeedFactory _changeFeedFactory; |
| | 15 | | private readonly DateTimeOffset? _startTime; |
| | 16 | | private readonly DateTimeOffset? _endTime; |
| | 17 | | private readonly string _continuation; |
| | 18 | |
|
| | 19 | | /// <summary> |
| | 20 | | /// Internal constructor. |
| | 21 | | /// </summary> |
| 44 | 22 | | internal BlobChangeFeedAsyncPageable( |
| 44 | 23 | | BlobServiceClient blobServiceClient, |
| 44 | 24 | | DateTimeOffset? startTime = default, |
| 44 | 25 | | DateTimeOffset? endTime = default) |
| | 26 | | { |
| 44 | 27 | | _changeFeedFactory = new ChangeFeedFactory(blobServiceClient); |
| 44 | 28 | | _startTime = startTime; |
| 44 | 29 | | _endTime = endTime; |
| 44 | 30 | | } |
| | 31 | |
|
| 32 | 32 | | internal BlobChangeFeedAsyncPageable( |
| 32 | 33 | | BlobServiceClient blobServiceClient, |
| 32 | 34 | | string continuation) |
| | 35 | | { |
| 32 | 36 | | _changeFeedFactory = new ChangeFeedFactory(blobServiceClient); |
| 32 | 37 | | _continuation = continuation; |
| 32 | 38 | | } |
| | 39 | |
|
| | 40 | | /// <summary> |
| | 41 | | /// Returns <see cref="BlobChangeFeedEvent"/>s as Pages. |
| | 42 | | /// </summary> |
| | 43 | | /// <param name="continuationToken"> |
| | 44 | | /// Throws an <see cref="ArgumentException"/>. To use contination, call |
| | 45 | | /// <see cref="BlobChangeFeedClient.GetChangesAsync(string)"/>. |
| | 46 | | /// </param> |
| | 47 | | /// <param name="pageSizeHint"> |
| | 48 | | /// Page size. |
| | 49 | | /// </param> |
| | 50 | | /// <returns> |
| | 51 | | /// <see cref="IAsyncEnumerable{Page}"/>. |
| | 52 | | /// </returns> |
| | 53 | | public override async IAsyncEnumerable<Page<BlobChangeFeedEvent>> AsPages( |
| | 54 | | string continuationToken = null, |
| | 55 | | int? pageSizeHint = null) |
| | 56 | | { |
| 76 | 57 | | if (continuationToken != null) |
| | 58 | | { |
| 0 | 59 | | throw new ArgumentException($"{nameof(continuationToken)} not supported. Use BlobChangeFeedClient.GetCh |
| | 60 | | } |
| | 61 | |
|
| 76 | 62 | | ChangeFeed changeFeed = await _changeFeedFactory.BuildChangeFeed( |
| 76 | 63 | | _startTime, |
| 76 | 64 | | _endTime, |
| 76 | 65 | | _continuation, |
| 76 | 66 | | async: true, |
| 76 | 67 | | cancellationToken: default) |
| 76 | 68 | | .ConfigureAwait(false); |
| | 69 | |
|
| 180 | 70 | | while (changeFeed.HasNext()) |
| | 71 | | { |
| 132 | 72 | | yield return await changeFeed.GetPage( |
| 132 | 73 | | async: true, |
| 132 | 74 | | pageSize: pageSizeHint ?? Constants.ChangeFeed.DefaultPageSize).ConfigureAwait(false); |
| | 75 | | } |
| 76 | 76 | | } |
| | 77 | | } |
| | 78 | | } |