public async Task <IReadOnlyCollection <ICommittedDomainEvent> > LoadCommittedEventsAsync(IIdentity id, int fromEventSequenceNumber, CancellationToken cancellationToken) { return(await MongoDbEventStoreCollection .Find(model => model.AggregateId == id.Value && model.AggregateSequenceNumber >= fromEventSequenceNumber) .ToListAsync(cancellationToken) .ConfigureAwait(continueOnCapturedContext: false)); }
public async Task <AllCommittedEventsPage> LoadAllCommittedEvents(GlobalPosition globalPosition, int pageSize, CancellationToken cancellationToken) { long startPosition = globalPosition.IsStart ? 0 : long.Parse(globalPosition.Value); long endPosition = startPosition + pageSize; List <MongoDbEventDataModel> eventDataModels = await MongoDbEventStoreCollection .Find(model => model._id >= startPosition && model._id <= endPosition) .ToListAsync(cancellationToken) .ConfigureAwait(continueOnCapturedContext: false); long nextPosition = eventDataModels.Any() ? eventDataModels.Max(e => e._id) + 1 : startPosition; return(new AllCommittedEventsPage(new GlobalPosition(nextPosition.ToString()), eventDataModels)); }