Action <EventStoreCatchUpSubscription, ResolvedEvent> EventAppeared(IProjection projection)
        {
            return((s, e) =>
            {
                if (!projection.CanHandle(e.Event.EventType))
                {
                    return;
                }

                var deserializedEvent = e.Deserialize();
                projection.Handle(e.Event.EventType, deserializedEvent);

                UpdatePosition(projection.GetType(), e.OriginalPosition.Value);
            });
        }
Beispiel #2
0
    Func <StreamSubscription, ResolvedEvent, CancellationToken, Task> EventAppeared(IProjection projection)
    {
        return(async(s, e, ct) =>
        {
            Console.WriteLine(
                $"Handling Projection {projection.GetType().Name} event {e.Event.EventType} id: {e.Event.EventId}");

            if (!projection.CanHandle(e.Event.EventType))
            {
                return;
            }

            var deserializedEvent = e.Deserialize();
            await projection.HandleAsync(e.Event.EventType, deserializedEvent, ct);

            await UpdatePositionAsync(projection.GetType(), e.OriginalPosition !.Value, ct);
        });
    }
Beispiel #3
0
        Action <EventStoreCatchUpSubscription, ResolvedEvent> EventAppeared(IProjection projection)
        {
            return((s, e) =>
            {
                if (!projection.CanHandle(e.Event.EventType))
                {
                    UpdatePosition(projection.GetType(), e.OriginalPosition.Value);
                    return;
                }

                Console.WriteLine("Processing");
                Console.WriteLine(e.Event.EventStreamId);
                Console.WriteLine(e.Event.EventNumber);
                Console.WriteLine(e.Event.EventType);

                var deserializedEvent = e.Deserialize();
                projection.Handle(e.Event.EventType, deserializedEvent);

                UpdatePosition(projection.GetType(), e.OriginalPosition.Value);
            });
        }
Beispiel #4
0
        private Action <EventStoreCatchUpSubscription, ResolvedEvent> EventAppeared(IProjection projection)
        {
            return((subscription, resolvedEvent) =>
            {
                var currentPosition = resolvedEvent.OriginalPosition;
                var projectionId = projection.Id;
                try
                {
                    var @event = resolvedEvent.Event;
                    if (!projection.CanHandle(@event.EventType))
                    {
                        return;
                    }

                    var deserializedEvent = JsonConvert.DeserializeObject(Encoding.UTF8.GetString(resolvedEvent.Event.Data), new JsonSerializerSettings {
                        TypeNameHandling = TypeNameHandling.Objects
                    });
                    projection.Handle(@event.EventType, deserializedEvent);
                    positionStore.Update(projectionId, currentPosition);
                    log.Debug($"EVENT HANDLED: EventType: {@event.EventType} AggregateId: {resolvedEvent.OriginalStreamId} Projection: {projectionId}");
                }
                catch (Exception exception)
                {
                    var aggregateId = resolvedEvent.OriginalStreamId;
                    var position = currentPosition.HasValue ? currentPosition.ToString() : "unknown";
                    log.Error(
                        $"EXCEPTION DURING PROJECTION UPDATE - AggregateId: {aggregateId} Projection: {projectionId} Position: {position}",
                        exception);
                    try
                    {
                        positionStore.OnError(projectionId, resolvedEvent.Event.EventType, aggregateId, currentPosition, exception);
                    }
                    catch (Exception ex)
                    {
                        log.Error($"EXCEPTION DURING ERROR POSITION UPDATE - AggregateId: {aggregateId} Projection: {projectionId} Position: {position}", ex);
                    }
                }
            });
        }