private Task HandleNewEvent(StreamSubscription subscription, ResolvedEvent evnt, CancellationToken token) { if (evnt.Event.EventStreamId.StartsWith('$')) { // skip system events return(Task.CompletedTask); } IDomainEvent <IDomainEventData> @event; try { @event = ParseEvent(evnt); } catch { // TODO: Properly handle this case _logger.LogWarning("Unknown event name: {eventName}", evnt.Event.EventType); return(Task.CompletedTask); } _logger.LogDebug("Processed event {position}|{type}.", evnt.OriginalPosition, evnt.Event.EventType); _sender.SendEvent(@event); return(Task.CompletedTask); }
public Task <IDomainEvent <IDomainEventData> > Store(ICreateEvent <IDomainEventData> newEvent) { var eventData = newEvent.Data; var eventVersion = _events.Where(x => x.AggregateKey == eventData.GetAggregateKey()).Select(x => (ulong?)x.Version).Max(x => x) ?? 0; Instant created = _clock.GetCurrentInstant(); var @event = _eventFactory.CreateEvent(eventVersion, created, eventData); _events.Add(@event); _sender.SendEvent(@event); var result = _eventFactory.CreateEvent(eventVersion, created, eventData); return(Task.FromResult(result)); }