示例#1
0
        Action <EventStoreCatchUpSubscription, ResolvedEvent> EventAppeared(Projection projection)
        => (_, e) =>
        {
            // always double check if it is a system event ;)
            if (e.OriginalEvent.EventType.StartsWith("$"))
            {
                return;
            }

            // get the configured clr type name for deserializing the event
            if (!_typeMapper.TryGetType(e.Event.EventType, out var eventType))
            {
                Log.Debug("Failed to find clr type for {eventType}. Skipping...", e.Event.EventType);
            }
            else
            {
                // deserialize event
                var domainEvent = _serializer.Deserialize(e.Event.Data, eventType);

                // try to execute the projection
                if (projection.CanHandle(domainEvent))
                {
                    projection.Handle(domainEvent).GetAwaiter().GetResult();
                    Log.Debug("{projection} handled {event}", projection, domainEvent);
                }
            }

            // store the current checkpoint
            _checkpointStore.SetCheckpoint(e.OriginalPosition, projection).GetAwaiter().GetResult();
        };
示例#2
0
    public async Task Project(object @event)
    {
        if (!_projection.CanHandle(@event.GetType()))
        {
            return;
        }

        await _projection.Handle(@event.GetType(), @event);
    }