Ejemplo n.º 1
0
        public static IKernelEventEnvelope Create(IKernelEvent @event)
        {
            var factory = _envelopeFactories.GetOrAdd(
                @event.GetType(),
                eventType =>
            {
                var genericType = _envelopeTypesByEventTypeName[@event.GetType().Name];

                var constructor = genericType.GetConstructors().Single();

                var eventParameter = Expression.Parameter(
                    typeof(IKernelEvent),
                    "e");

                var newExpression = Expression.New(
                    constructor,
                    Expression.Convert(eventParameter, eventType));

                var expression = Expression.Lambda <Func <IKernelEvent, IKernelEventEnvelope> >(
                    newExpression,
                    eventParameter);

                return(expression.Compile());
            });

            return(factory(@event));
        }
Ejemplo n.º 2
0
 public static StreamKernelEvent ToStreamKernelEvent(IKernelEvent kernelEvent, int correlationId)
 {
     return(new StreamKernelEvent
     {
         Id = correlationId,
         EventType = kernelEvent.GetType().Name,
         Event = kernelEvent
     });
 }
Ejemplo n.º 3
0
        private void Write(IKernelEvent e, int id)
        {
            var wrapper = new StreamKernelEvent
            {
                Id        = id,
                Event     = e,
                EventType = e.GetType().Name
            };
            var serialized = wrapper.Serialize();

            _output.Write(serialized);
        }
        private void Write(IKernelEvent e, int id)
        {
            var wrapper = new StreamKernelEvent
            {
                Id        = id,
                Event     = e,
                EventType = e.GetType().Name
            };
            var serialized = JsonConvert.SerializeObject(wrapper, _jsonSerializerSettings);

            _output.WriteLine(serialized);
            _output.Flush();
        }
Ejemplo n.º 5
0
        public void All_event_types_are_round_trip_serializable(IKernelEvent @event)
        {
            var originalEnvelope = KernelEventEnvelope.Create(@event);

            var json = KernelEventEnvelope.Serialize(originalEnvelope);

            _output.WriteLine($"{Environment.NewLine}{@event.GetType().Name}: {Environment.NewLine}{json}");

            var deserializedEnvelope = KernelEventEnvelope.Deserialize(json);

            deserializedEnvelope
            .Should()
            .BeEquivalentTo(originalEnvelope);
        }
Ejemplo n.º 6
0
        private void Write(IKernelEvent kernelEvent, int correlationId)
        {
            if (kernelEvent is ReturnValueProduced rvp && rvp.Value is DisplayedValue)
            {
                return;
            }
            var wrapper = new StreamKernelEvent
            {
                Id        = correlationId,
                Event     = kernelEvent,
                EventType = kernelEvent.GetType().Name
            };
            var serialized = wrapper.Serialize();

            _output.Write(serialized);
        }