示例#1
0
 public static bool Applies <T>(this IPersistedEvent @event, EventSourced <T> aggregateRoot)
     where T : new()
 {
     return
         (aggregateRoot.Id == @event.AggregateRootId
          &&
          aggregateRoot.Version == @event.Version - 1);
 }
示例#2
0
        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);
        }
示例#3
0
        public bool Match(IPersistedEvent @event)
        {
            if (@event.GetType() == typeof(TPersistedEvent))
            {
                return(eventFilterFunction == null ? true : eventFilterFunction((TPersistedEvent)@event));
            }

            return(false);
        }
示例#4
0
        public bool EventMatches(IPersistedEvent e)
        {
            foreach (var p in _predicates)
            {
                if (p.EventMatches(e))
                {
                    return(true);
                }
            }

            return(false);
        }
示例#5
0
        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);
        }
示例#6
0
        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);
        }
示例#7
0
        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);
                    }
                }
            }
        }
示例#8
0
 public ReadResponse(Guid requestId, IPersistedEvent @event)
 {
     this.RequestID = requestId;
     this.Event = @event;
 }
示例#9
0
 public ReadResponse(Guid requestId, IPersistedEvent @event)
 {
     this.RequestID = requestId;
     this.Event     = @event;
 }
示例#10
0
 private void Rename(IPersistedEvent pe, ProductRenamed e)
 {
 }
示例#11
0
 private void Delete(IPersistedEvent pe, ProductDeleted e)
 {
 }
 public bool EventMatches(IPersistedEvent persistedEvent)
 {
     return _type.IsAssignableFrom(persistedEvent.DomainEvent.GetType());
 }
示例#13
0
        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);
                }
            }
        }
示例#14
0
 private void Add(IPersistedEvent pe, ProductCreated e)
 {
 }
示例#15
0
 public bool EventMatches(IPersistedEvent persistedEvent)
 {
     return(_type.IsAssignableFrom(persistedEvent.DomainEvent.GetType()));
 }
示例#16
0
        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));
        }
示例#17
0
 public ProjectionEvent(Stream stream, int streamSequence, IPersistedEvent <T> persistedEvent)
 {
     Stream         = stream;
     StreamSequence = streamSequence;
     _e             = persistedEvent;
 }
示例#18
0
 private void Delete(IPersistedEvent pe, ProductDeleted e)
 {
    
 }
示例#19
0
        private void Rename(IPersistedEvent pe, ProductRenamed e)
        {

        }
示例#20
0
 private void Add(IPersistedEvent pe, ProductCreated e)
 {
     
 }