Пример #1
0
        private void OnEventAppeared(EventStoreCatchUpSubscription subscription, ResolvedEvent resolvedEvent)
        {
            var maybeEvent = _eventSerializer.FromEventData(resolvedEvent.Event);

            maybeEvent.Match(
                @event =>
            {
                var originalPosition    = resolvedEvent.OriginalPosition;
                var eventHasBeenDeleted = originalPosition == null;
                if (eventHasBeenDeleted)
                {
                    return;
                }

                _blockingCollection.Add(@event);
            },
                () => { });
        }
        private async Task <Option <UserIndexedByEmail> > ReadUserByEmailIndexedEventAsync(string email)
        {
            var maybeResolvedEvent = await _connection.ReadLastStreamEvent(StreamBy(email));

            return(maybeResolvedEvent.Map(
                       resolvedEvent =>
            {
                var fromEventData = _eventSerializer.FromEventData(resolvedEvent.OriginalEvent);
                if (!fromEventData.HasValue)
                {
                    throw new Exception($"Could not read event of type {resolvedEvent.OriginalEvent.EventType}");
                }

                var @event = fromEventData.ValueOrFailure();
                if (!(@event is UserIndexedByEmail))
                {
                    var message = $"Expected event of type {typeof (UserIndexedByEmail).FullName} " +
                                  "but was '{@event.GetType().FullName}'";
                    throw new Exception(message);
                }

                return @event as UserIndexedByEmail;
            }));
        }