private async Task <int> ProcessEvent(OrderedEventPayload @event) { var eventPayload = @event.EventPayload; var eventType = eventPayload.GetType(); // Do we have an event listener for this event type? // TODO: This can be removed once we only get typed events if (!_eventHandlers.ContainsKey(eventType)) { return(await Task.FromResult(0)); } var queryModelStore = GetQueryModelStoreFromEvent(@event); // Invoke event handler for event try { var eventHandler = _eventHandlers[eventType]; await eventHandler(@event.EventPayload, queryModelStore); return(await Task.FromResult(1)); } catch (Exception e) { //TODO: Handle exception Trace.TraceError($"Error while processing event {eventType.FullName} in Projection {this.GetType().FullName}\nException: {e.ToString()}"); throw; } //return await Task.FromResult(0); }
private QueryModelStore GetQueryModelStoreFromEvent(OrderedEventPayload @event) { return(new QueryModelStore( QueryModelRepository, _projectionMetadataRepository, @event.Ordering, _projectionId)); }