Exemplo n.º 1
0
        public override async Task Start(CancellationToken cancellationToken)
        {
            if (_nextVersion == StreamVersion.End)
            {
                // Get the last stream version and subscribe from there.
                var eventsPage = await ReadOnlyEventStore.ReadStreamBackwards(
                    _streamId,
                    StreamVersion.End,
                    1,
                    cancellationToken).NotOnCapturedContext();

                //Only new events, i.e. the one after the current last one
                _nextVersion = eventsPage.LastStreamVersion + 1;
            }
            await base.Start(cancellationToken);
        }
        public override async Task Start(CancellationToken cancellationToken)
        {
            if (FromCheckpoint == Checkpoint.End)
            {
                // Get the last stream version and subscribe from there.
                var eventsPage = await ReadOnlyEventStore.ReadAllBackwards(
                    Checkpoint.End,
                    1,
                    cancellationToken).NotOnCapturedContext();

                // If fromCheckpoint = 0, we have empty store, so start from zero, otherwise, the next checkpoint is
                // one after the FromCheckpoint.
                _nextCheckpoint = eventsPage.FromCheckpoint == 0 ?  0 : eventsPage.FromCheckpoint + 1;
            }
            await base.Start(cancellationToken).NotOnCapturedContext();
        }
        protected override async Task <bool> DoFetch()
        {
            var allEventsPage = await ReadOnlyEventStore
                                .ReadAllForwards(
                _nextCheckpoint,
                PageSize,
                IsDisposed)
                                .NotOnCapturedContext();

            bool isEnd = allEventsPage.IsEnd;

            foreach (var streamEvent in allEventsPage.StreamEvents)
            {
                if (IsDisposed.IsCancellationRequested)
                {
                    return(true);
                }
                try
                {
                    await StreamEventReceived(streamEvent).NotOnCapturedContext();

                    LastCheckpoint  = streamEvent.Checkpoint;
                    _nextCheckpoint = streamEvent.Checkpoint + 1;
                }
                catch (Exception ex)
                {
                    try
                    {
                        SubscriptionDropped.Invoke(ex.Message, ex);
                    }
                    catch
                    {
                        //TODO logging
                    }
                    finally
                    {
                        Dispose();
                    }
                }
            }

            return(isEnd);
        }
Exemplo n.º 4
0
        protected override async Task <bool> DoFetch()
        {
            var streamEventsPage = await ReadOnlyEventStore
                                   .ReadStreamForwards(
                _streamId,
                _nextVersion,
                PageSize,
                IsDisposed)
                                   .NotOnCapturedContext();

            bool isEnd = streamEventsPage.IsEndOfStream;

            foreach (var streamEvent in streamEventsPage.Events)
            {
                if (IsDisposed.IsCancellationRequested)
                {
                    return(true);
                }
                _nextVersion = streamEvent.StreamVersion + 1;
                _lastVersion = streamEvent.StreamVersion;
                try
                {
                    await StreamEventReceived(streamEvent).NotOnCapturedContext();
                }
                catch (Exception ex)
                {
                    try
                    {
                        SubscriptionDropped.Invoke(ex.Message, ex);
                    }
                    catch (Exception ex2)
                    {
                        // Need to log this
                    }
                    finally
                    {
                        Dispose();
                    }
                }
            }
            return(isEnd);
        }