public async Task GetEventsAsync(Func <StoredEvent, Task> callback, string streamFilter = null, string position = null, CancellationToken cancellationToken = default(CancellationToken)) { var streamName = await connection.CreateProjectionAsync(projectionsManager, prefix, streamFilter); var sliceStart = ProjectionHelper.ParsePosition(position); StreamEventsSlice currentSlice; do { currentSlice = await connection.ReadStreamEventsForwardAsync(streamName, sliceStart, ReadPageSize, true); if (currentSlice.Status == SliceReadStatus.Success) { sliceStart = currentSlice.NextEventNumber; foreach (var resolved in currentSlice.Events) { var storedEvent = Formatter.Read(resolved); await callback(storedEvent); } } }while (!currentSlice.IsEndOfStream && !cancellationToken.IsCancellationRequested); }
public GetEventStoreSubscription( IEventStoreConnection eventStoreConnection, IEventSubscriber eventSubscriber, ProjectionsManager projectionsManager, string prefix, string position, string streamFilter) { Guard.NotNull(eventSubscriber, nameof(eventSubscriber)); this.eventStoreConnection = eventStoreConnection; this.eventSubscriber = eventSubscriber; this.position = ProjectionHelper.ParsePositionOrNull(position); var streamName = eventStoreConnection.CreateProjectionAsync(projectionsManager, prefix, streamFilter).Result; subscription = SubscribeToStream(streamName); }