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