public void Execute(OnAssembleEventEnvelope pipelineEvent)
        {
            var state        = pipelineEvent.Pipeline.State;
            var domainEvent  = state.GetDomainEvent();
            var configurator = state.GetEventEnvelopeConfigurator();

            Guard.AgainstNull(domainEvent, nameof(domainEvent));

            var eventEnvelope = new EventEnvelope
            {
                Event                 = state.GetEventBytes(),
                EventType             = domainEvent.Event.GetType().FullName,
                IsSnapshot            = domainEvent.IsSnapshot,
                Version               = domainEvent.Version,
                AssemblyQualifiedName = domainEvent.Event.GetType().AssemblyQualifiedName,
                EncryptionAlgorithm   = _configuration.EncryptionAlgorithm,
                CompressionAlgorithm  = _configuration.CompressionAlgorithm
            };

            if (configurator != null)
            {
                eventEnvelope.Headers = configurator.Headers;
            }

            state.SetEventEnvelope(eventEnvelope);
        }
Example #2
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;
        }
Example #3
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;
        }
        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 EventEnvelope EventEnvelope(object @event, string encryptionAlgorithm, string compressionAlgorithm)
        {
            Guard.AgainstNull(@event, nameof(@event));

            var result = new EventEnvelope
            {
                AssemblyQualifiedName = @event.GetType().AssemblyQualifiedName,
                EncryptionAlgorithm   = encryptionAlgorithm,
                CompressionAlgorithm  = compressionAlgorithm,
                EventDate             = DateTime.Now
            };

            result.Headers.Merge(Headers);

            return(result);
        }
 public static void AcceptInvariants(this EventEnvelope eventEnvelope)
 {
     Guard.AgainstNull(eventEnvelope.EventId, nameof(eventEnvelope.EventId));
     Guard.AgainstNullOrEmptyString(eventEnvelope.AssemblyQualifiedName, nameof(eventEnvelope.AssemblyQualifiedName));
 }
 public static bool CompressionEnabled(this EventEnvelope eventEnvelope)
 {
     return(!string.IsNullOrEmpty(eventEnvelope.CompressionAlgorithm)
            &&
            !eventEnvelope.CompressionAlgorithm.Equals("none", StringComparison.InvariantCultureIgnoreCase));
 }
 public static void SetEventEnvelope(this IState state, EventEnvelope value)
 {
     state.Replace(StateKeys.EventEnvelope, value);
 }