Exemplo n.º 1
0
        private async Task EventAppeared(StreamSubscription subscription, ResolvedEvent resolvedEvent, CancellationToken cancellationToken)
        {
            _logger.LogInformation("{eventType}@{preparePosition}", resolvedEvent.Event.EventType, resolvedEvent.Event.Position.PreparePosition);

            var e = EventSerializer.Deserialize(resolvedEvent);

            await ExecuteProjectionHandlers(e);
        }
        private async Task EventAppeared(StreamSubscription subscription, ResolvedEvent resolvedEvent, CancellationToken cancellationToken)
        {
            _logger.LogInformation("{eventType}@{preparePosition}", resolvedEvent.Event.EventType, resolvedEvent.Event.Position.PreparePosition);

            var e = EventSerializer.Deserialize(resolvedEvent);

            foreach (var projection in _projections)
            {
                if (projection.CanHandle(e.GetType()))
                {
                    await projection.Handle(e);
                }
            }
        }
Exemplo n.º 3
0
        public async Task AppendToStream(string streamName, long expectedVersion, IEnumerable <Event> events, string correlationId)
        {
            var eventData = events.Select(e =>
            {
                var metadata = new Dictionary <string, string>
                {
                    { "$correlationId", correlationId }
                };

                var eventBytes    = Encoding.UTF8.GetBytes(EventSerializer.Serialize(e));
                var metadataBytes = Encoding.UTF8.GetBytes(EventSerializer.SerializeMetadata(metadata));

                return(new EventData(Uuid.NewUuid(), e.GetType().Name, eventBytes, metadataBytes));
            });

            var expectedRevision = StreamRevision.FromInt64(expectedVersion);
            await _client.AppendToStreamAsync(streamName, expectedRevision, eventData);
        }