|
1 |
| -using System; |
2 |
| -using System.Collections.Generic; |
3 |
| -using System.Linq; |
4 | 1 | using System.Runtime.CompilerServices;
|
5 |
| -using System.Threading; |
6 | 2 | using System.Threading.Channels;
|
7 |
| -using System.Threading.Tasks; |
8 | 3 | using EventStore.Client.Streams;
|
9 | 4 | using Grpc.Core;
|
10 | 5 | using static EventStore.Client.Streams.ReadResp;
|
@@ -42,23 +37,76 @@ public ReadAllStreamResult ReadAllAsync(
|
42 | 37 | Options = new() {
|
43 | 38 | ReadDirection = direction switch {
|
44 | 39 | Direction.Backwards => ReadReq.Types.Options.Types.ReadDirection.Backwards,
|
45 |
| - Direction.Forwards => ReadReq.Types.Options.Types.ReadDirection.Forwards, |
46 |
| - _ => throw InvalidOption(direction) |
| 40 | + Direction.Forwards => ReadReq.Types.Options.Types.ReadDirection.Forwards, |
| 41 | + _ => throw InvalidOption(direction) |
47 | 42 | },
|
48 | 43 | ResolveLinks = resolveLinkTos,
|
49 | 44 | All = new() {
|
50 | 45 | Position = new() {
|
51 |
| - CommitPosition = position.CommitPosition, |
| 46 | + CommitPosition = position.CommitPosition, |
52 | 47 | PreparePosition = position.PreparePosition
|
53 | 48 | }
|
54 | 49 | },
|
55 |
| - Count = (ulong)maxCount, |
56 |
| - UuidOption = new() {Structured = new()}, |
57 |
| - NoFilter = new(), |
| 50 | + Count = (ulong)maxCount, |
| 51 | + UuidOption = new() {Structured = new()}, |
| 52 | + NoFilter = new(), |
58 | 53 | ControlOption = new() {Compatibility = 1}
|
59 | 54 | }
|
60 | 55 | }, Settings, deadline, userCredentials, cancellationToken);
|
61 | 56 | }
|
| 57 | + |
| 58 | + /// <summary> |
| 59 | + /// Asynchronously reads all events with filtering. |
| 60 | + /// </summary> |
| 61 | + /// <param name="direction">The <see cref="Direction"/> in which to read.</param> |
| 62 | + /// <param name="position">The <see cref="Position"/> to start reading from.</param> |
| 63 | + /// <param name="eventFilter">The <see cref="IEventFilter"/> to apply.</param> |
| 64 | + /// <param name="maxCount">The maximum count to read.</param> |
| 65 | + /// <param name="resolveLinkTos">Whether to resolve LinkTo events automatically.</param> |
| 66 | + /// <param name="deadline"></param> |
| 67 | + /// <param name="userCredentials">The optional <see cref="UserCredentials"/> to perform operation with.</param> |
| 68 | + /// <param name="cancellationToken">The optional <see cref="System.Threading.CancellationToken"/>.</param> |
| 69 | + /// <returns></returns> |
| 70 | + public ReadAllStreamResult ReadAllAsync( |
| 71 | + Direction direction, |
| 72 | + Position position, |
| 73 | + IEventFilter eventFilter, |
| 74 | + long maxCount = long.MaxValue, |
| 75 | + bool resolveLinkTos = false, |
| 76 | + TimeSpan? deadline = null, |
| 77 | + UserCredentials? userCredentials = null, |
| 78 | + CancellationToken cancellationToken = default |
| 79 | + ) { |
| 80 | + if (maxCount <= 0) { |
| 81 | + throw new ArgumentOutOfRangeException(nameof(maxCount)); |
| 82 | + } |
| 83 | + |
| 84 | + var readReq = new ReadReq { |
| 85 | + Options = new() { |
| 86 | + ReadDirection = direction switch { |
| 87 | + Direction.Backwards => ReadReq.Types.Options.Types.ReadDirection.Backwards, |
| 88 | + Direction.Forwards => ReadReq.Types.Options.Types.ReadDirection.Forwards, |
| 89 | + _ => throw InvalidOption(direction) |
| 90 | + }, |
| 91 | + ResolveLinks = resolveLinkTos, |
| 92 | + All = new() { |
| 93 | + Position = new() { |
| 94 | + CommitPosition = position.CommitPosition, |
| 95 | + PreparePosition = position.PreparePosition |
| 96 | + } |
| 97 | + }, |
| 98 | + Count = (ulong)maxCount, |
| 99 | + UuidOption = new() { Structured = new() }, |
| 100 | + ControlOption = new() { Compatibility = 1 }, |
| 101 | + Filter = GetFilterOptions(eventFilter) |
| 102 | + } |
| 103 | + }; |
| 104 | + |
| 105 | + return new ReadAllStreamResult(async _ => { |
| 106 | + var channelInfo = await GetChannelInfo(cancellationToken).ConfigureAwait(false); |
| 107 | + return channelInfo.CallInvoker; |
| 108 | + }, readReq, Settings, deadline, userCredentials, cancellationToken); |
| 109 | + } |
62 | 110 |
|
63 | 111 | /// <summary>
|
64 | 112 | /// A class that represents the result of a read operation on the $all stream. You may either enumerate this instance directly or <see cref="Messages"/>. Do not enumerate more than once.
|
|
0 commit comments