dasiths / NEventLite

NEventLite - An extensible lightweight library for .NET that manages the Aggregate lifecycle in an Event Sourced system. Supports Event and Snapshot storage providers like EventStore/Redis or SQL Server. Built with dependency injection in mind and seamlessly integrates with AspNetCore.
MIT License
132 stars 19 forks source link

Implement new Paging logic using IsEndOfStream for EventstoreEventStorageProvider #2

Closed dasiths closed 8 years ago

dasiths commented 8 years ago

Use streamEvents.IsEndOfStream() and streamEvents.NextEventNumber to implement recommended paging method.

var streamEvents = new List<ResolvedEvent>();
StreamEventsSlice currentSlice;
var nextSliceStart = StreamPosition.Start;
do
{
    currentSlice = 
    _eventStoreConnection.ReadStreamEventsForward("myStream", nextSliceStart,
                                                  200, false)
                                                  .Result;

    nextSliceStart = currentSlice.NextEventNumber;

    streamEvents.AddRange(currentSlice.Events);
} while (!currentSlice.IsEndOfStream);