public static bool Applies <T>(this IPersistedEvent @event, EventSourced <T> aggregateRoot) where T : new() { return (aggregateRoot.Id == @event.AggregateRootId && aggregateRoot.Version == @event.Version - 1); }
public override bool ApplyEvent <TEvent>(IPersistedEvent @event) { if (this.EventSubscriptions.ContainsKey(typeof(TEvent))) { return(this.EventSubscriptions[typeof(TEvent)].Match(@event) ? base.ApplyEvent <TEvent>(@event) : false); } return(false); }
public bool Match(IPersistedEvent @event) { if (@event.GetType() == typeof(TPersistedEvent)) { return(eventFilterFunction == null ? true : eventFilterFunction((TPersistedEvent)@event)); } return(false); }
public bool EventMatches(IPersistedEvent e) { foreach (var p in _predicates) { if (p.EventMatches(e)) { return(true); } } return(false); }
public virtual bool ApplyEvent <TEvent>(IPersistedEvent @event) where TEvent : IEvent { if (this is IEventHandler <TEvent> eventHandler) { eventHandler.Handle((TEvent)@event.Instance); this.Version++; return(true); } return(false); }
public override bool ApplyEvent <TEvent>(IPersistedEvent @event) { if (this.Id != @event.AggregateRootId) { throw new Exception( $"Invalid event configuration. Cannot apply event with Aggregate Root id: {@event.AggregateRootId} on Aggregate Root id: {this.Id}"); } if (this.Version != @event.Version - 1) { throw new Exception( $"Invalid event configuration. Cannot apply event version: {@event.Version} on Aggregate Root version {this.Version}"); } if (!base.ApplyEvent <TEvent>(@event)) { throw new Exception( $"Aggregate {this.GetType().Name} does not provide a handler for event {@event.GetType().Name}"); } return(true); }
private void ReceiveEventInternal(IPersistedEvent e, bool tellSubscribers) { // and the event matches the query, emit it if (_query.EventMatches(e)) { // increment the sequence _currentSequence++; // index the event _writer.Tell(new ProjectionIndexPersistenceRequest(_query.ProjectionStream, _currentSequence, e.GlobalSequence)); // tell the subscribers if (tellSubscribers) { var projectionEvent = ProjectionEventFactory.Create(_query.ProjectionStream, _currentSequence, e); foreach (var s in _subscribers) { s.Tell(projectionEvent); } } } }
public ReadResponse(Guid requestId, IPersistedEvent @event) { this.RequestID = requestId; this.Event = @event; }
private void Rename(IPersistedEvent pe, ProductRenamed e) { }
private void Delete(IPersistedEvent pe, ProductDeleted e) { }
public bool EventMatches(IPersistedEvent persistedEvent) { return _type.IsAssignableFrom(persistedEvent.DomainEvent.GetType()); }
private void ReceiveEventInternal(IPersistedEvent e, bool tellSubscribers) { // and the event matches the query, emit it if (_query.EventMatches(e)) { // increment the sequence _currentSequence++; // index the event _writer.Tell(new ProjectionIndexPersistenceRequest(_query.ProjectionStream, _currentSequence, e.GlobalSequence)); // tell the subscribers if (tellSubscribers) { var stream = new Stream(_query.ProjectionStream, e.Stream.OriginalStreamName); var projectionEvent = ProjectionEventFactory.Create(stream, _currentSequence, e); foreach (var s in _subscribers) s.Tell(projectionEvent); } } }
private void Add(IPersistedEvent pe, ProductCreated e) { }
public bool EventMatches(IPersistedEvent persistedEvent) { return(_type.IsAssignableFrom(persistedEvent.DomainEvent.GetType())); }
public static IPersistedStreamEvent Create(Stream stream, int streamSequence, IPersistedEvent persistedEvent) { Argument.RequiresNotNull(stream, nameof(stream)); Argument.Requires(streamSequence >= 1, nameof(streamSequence)); Argument.RequiresNotNull(persistedEvent, nameof(persistedEvent)); var eventType = persistedEvent.DomainEvent.GetType(); var t = typeof(ProjectionEvent <>).MakeGenericType(eventType); return((IPersistedStreamEvent)Activator.CreateInstance(t, stream, streamSequence, persistedEvent)); }
public ProjectionEvent(Stream stream, int streamSequence, IPersistedEvent <T> persistedEvent) { Stream = stream; StreamSequence = streamSequence; _e = persistedEvent; }