public async Task <IReadOnlyCollection <ICommittedDomainEvent> > LoadCommittedEventsAsync(IIdentity id, int fromEventSequenceNumber, CancellationToken cancellationToken)
 {
     return(await(await MongoDbEventStoreCollection
                  .FindAsync(model => model.AggregateId == id.Value && model.AggregateSequenceNumber >= fromEventSequenceNumber, cancellationToken: cancellationToken)
                  .ConfigureAwait(false))
            .ToListAsync(cancellationToken)
            .ConfigureAwait(continueOnCapturedContext: false));
 }
        public async Task <AllCommittedEventsPage> LoadAllCommittedEvents(GlobalPosition globalPosition, int pageSize, CancellationToken cancellationToken)
        {
            var startPosition = globalPosition.IsStart ? 0 : long.Parse(globalPosition.Value, CultureInfo.InvariantCulture);

            var eventDataModels = await(await MongoDbEventStoreCollection
                                        .FindAsync(model => model._id >= startPosition,
                                                   new FindOptions <MongoDbEventDataModel, MongoDbEventDataModel> {
                Limit = pageSize
            }, cancellationToken)
                                        .ConfigureAwait(false))
                                  .ToListAsync(cancellationToken)
                                  .ConfigureAwait(continueOnCapturedContext: false);

            var nextPosition = eventDataModels.Any()
                ? eventDataModels.Max(e => e._id) + 1
                : startPosition;

            return(new AllCommittedEventsPage(new GlobalPosition(nextPosition.ToString(CultureInfo.InvariantCulture)), eventDataModels));
        }