Example #1
0
 public ProjectionGroupState(
     string name,
     bool suspended               = false,
     Exception exception          = null,
     AllStreamPosition checkpoint = default(AllStreamPosition))
 {
     Name       = name;
     Suspended  = suspended;
     Exception  = exception;
     Checkpoint = checkpoint;
 }
Example #2
0
 public ReadAllPage(
     AllStreamPosition fromPosition,
     AllStreamPosition nextPosition,
     bool isEnd,
     IReadOnlyCollection <Envelope> messages
     )
 {
     FromPosition = fromPosition;
     NextPosition = nextPosition;
     IsEnd        = isEnd;
     Messages     = messages;
 }
Example #3
0
        public async Task Project(Envelope message, CancellationToken cancellationToken = default(CancellationToken))
        {
            var checkpoint = message.Checkpoint;

            if (_lastCheckpoint == null || checkpoint > _lastCheckpoint)
            {
                await _inner.Project(message, cancellationToken).ConfigureAwait(false);

                _lastCheckpoint = checkpoint;
                _notifyCheckpoint?.Invoke(AllStreamPosition.FromNullableInt64(_lastCheckpoint));
            }
        }
Example #4
0
        public CheckpointProjection(
            IStatefulProjection inner,
            CheckpointStore checkpointStore,
            Action <AllStreamPosition> notifyCheckpoint = null)
        {
            _inner            = inner;
            _checkpointStore  = checkpointStore;
            _notifyCheckpoint = notifyCheckpoint;

            _lastCheckpoint = _checkpointStore.Read();
            _notifyCheckpoint?.Invoke(AllStreamPosition.FromNullableInt64(_lastCheckpoint));
        }
        public GenericSubscription(
            ReadAllPageFunc readAllPage,
            AllStreamPosition fromPosition,
            Func <CancellationToken, Task> waitForEvent,
            MessageReceived onMessage,
            Func <Exception, Task> onSubscriptionError,
            HasCaughtUp hasCaughtUp)
        {
            _readAllPage         = readAllPage;
            FromPosition         = fromPosition;
            _nextPosition        = new AllStreamPosition(fromPosition.ToNullableInt64() + 1 ?? 0);
            _waitForEvent        = waitForEvent;
            _onMessage           = onMessage;
            _hasCaughtUp         = hasCaughtUp ?? (() => Task.CompletedTask);
            _onSubscriptionError = onSubscriptionError ?? (_ => Task.CompletedTask);
            LastPosition         = fromPosition;

            Task.Run(PullAndPush);
        }
        private async Task Push(ReadAllPage page)
        {
            foreach (var message in page.Messages)
            {
                if (_disposed.IsCancellationRequested)
                {
                    _disposed.Token.ThrowIfCancellationRequested();
                }
                _nextPosition = new AllStreamPosition(message.Checkpoint.ToInt64() + 1);
                LastPosition  = message.Checkpoint;
                try
                {
                    await _onMessage(this, message, _disposed.Token).ConfigureAwait(false);
                }
                catch (Exception ex) when(!(ex is OperationCanceledException))
                {
                    await _onSubscriptionError(ex).ConfigureAwait(false);

                    throw;
                }
            }
        }
Example #7
0
 public ProjectionGroupState MoveTo(AllStreamPosition checkpoint) =>
 new ProjectionGroupState(Name, false, Exception, checkpoint);
Example #8
0
 public AllStreamPosition ReadCheckpoint(string name) =>
 _checkpointStores.TryGetValue(name, out CheckpointStore store)
         ? AllStreamPosition.FromNullableInt64(store.Read())
         : AllStreamPosition.None;
Example #9
0
 public void MoveTo(string name, AllStreamPosition checkpoint) =>
 this[name] = this[name].MoveTo(checkpoint);