Beispiel #1
0
        /// <inheritdoc />
        public async IAsyncEnumerable <TIdentity> AggregateIdsAsync <TIdentity, TAggregate>(
            AggregateConfiguration <TIdentity, TAggregate> configuration,
            [EnumeratorCancellation] CancellationToken cancellationToken = default
            ) where TAggregate : Aggregate <TIdentity, TAggregate>
        {
            var constructors = configuration.Constructors;

            foreach (var(eventType, _) in constructors)
            {
                await Task.Yield();

                if (!_byEventType.TryGetValue(eventType, out var eventStream))
                {
                    continue;
                }

                foreach (var storedEvent in eventStream.Where(e => e.EventNumber == 0))
                {
                    var id = _streamNameResolver.ParseId(storedEvent.EventStreamId, configuration);
                    yield return(id);
                }
            }
        }
        ReadStreamEventsAsync <TIdentity, TAggregate>(
            AggregateConfiguration <TIdentity, TAggregate> configuration,
            long start,
            [EnumeratorCancellation] CancellationToken cancellationToken = default
            ) where TAggregate : Aggregate <TIdentity, TAggregate>
        {
            using var cursor = await _events
                               .Find(e => e.Category == configuration.Name)
                               .SortBy(e => e.Created)
                               .ThenBy(e => e.Id)
                               .Skip((int)start)
                               .ToCursorAsync(cancellationToken);

            while (await cursor.MoveNextAsync(cancellationToken))
            {
                foreach (var document in cursor.Current)
                {
                    var id            = _streamNameResolver.ParseId(document.Stream, configuration);
                    var recordedEvent = new RecordedEvent <TIdentity, TAggregate>(document, _serializer, id);
                    yield return(recordedEvent);
                }
            }
        }