public void Execute(PrimitiveEvent primitiveEvent)
        {
            Guard.AgainstNull(primitiveEvent, nameof(primitiveEvent));

            State.SetPrimitiveEvent(primitiveEvent);

            Execute();
        }
Exemplo n.º 2
0
        public void AddPrimitiveEvent(PrimitiveEvent primitiveEvent)
        {
            Guard.AgainstNull(primitiveEvent, nameof(primitiveEvent));

            if (_primitiveEvents.ContainsKey(primitiveEvent.SequenceNumber))
            {
                return;
            }

            _primitiveEvents.TryAdd(primitiveEvent.SequenceNumber, primitiveEvent);
        }
Exemplo n.º 3
0
        public EventHandlerContext(EventEnvelope eventEnvelope, T @event, PrimitiveEvent primitiveEvent,
                                   CancellationToken cancellationToken)
        {
            Guard.AgainstNull(eventEnvelope, nameof(eventEnvelope));
            Guard.AgainstNull(@event, nameof(@event));
            Guard.AgainstNull(primitiveEvent, nameof(primitiveEvent));

            CancellationToken = cancellationToken;
            Event             = @event;
            PrimitiveEvent    = primitiveEvent;
            EventEnvelope     = eventEnvelope;
        }
Exemplo n.º 4
0
        public EventHandlerContext(EventEnvelope eventEnvelope, T @event, PrimitiveEvent primitiveEvent,
                                   IThreadState activeState)
        {
            Guard.AgainstNull(eventEnvelope, nameof(eventEnvelope));
            Guard.AgainstNull(@event, nameof(@event));
            Guard.AgainstNull(primitiveEvent, nameof(primitiveEvent));
            Guard.AgainstNull(activeState, nameof(activeState));

            ActiveState    = activeState;
            Event          = @event;
            PrimitiveEvent = primitiveEvent;
            EventEnvelope  = eventEnvelope;
        }
Exemplo n.º 5
0
        public void Process(EventEnvelope eventEnvelope, object domainEvent, PrimitiveEvent primitiveEvent,
                            IThreadState threadState)
        {
            Guard.AgainstNull(eventEnvelope, nameof(eventEnvelope));
            Guard.AgainstNull(domainEvent, nameof(domainEvent));
            Guard.AgainstNull(primitiveEvent, nameof(primitiveEvent));
            Guard.AgainstNull(threadState, nameof(threadState));

            if (primitiveEvent.SequenceNumber <= SequenceNumber)
            {
                return;
            }

            var domainEventType = Type.GetType(eventEnvelope.AssemblyQualifiedName, true);

            try
            {
                if (!HandlesType(domainEventType))
                {
                    if (Log.IsTraceEnabled)
                    {
                        _log.Trace(string.Format(Resources.TraceTypeNotHandled, Name,
                                                 eventEnvelope.AssemblyQualifiedName));
                    }

                    return;
                }

                var contextType = typeof(EventHandlerContext <>).MakeGenericType(domainEventType);
                var method      = _eventHandlers[domainEventType].GetType().GetMethod("ProcessEvent", new[] { contextType });

                if (method == null)
                {
                    throw new ProcessEventMethodMissingException(string.Format(
                                                                     Resources.ProcessEventMethodMissingException,
                                                                     _eventHandlers[domainEventType].GetType().FullName,
                                                                     domainEventType.FullName));
                }

                var handlerContext =
                    Activator.CreateInstance(contextType, eventEnvelope, domainEvent, primitiveEvent, threadState);

                method.Invoke(_eventHandlers[domainEventType], new[] { handlerContext });
            }
            finally
            {
                SequenceNumber = primitiveEvent.SequenceNumber;
            }
        }
 public static void SetPrimitiveEvent(this IState state, PrimitiveEvent primitiveEvent)
 {
     state.Replace(StateKeys.PrimitiveEvent, primitiveEvent);
 }