private EventData CreateEventData(ItemWithType @event)
        {
            var eventData = new EventData(
                Guid.NewGuid(),
                @event.type.AssemblyQualifiedName,
                true,
                System.Text.Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(@event.instance)),
                null);

            return(eventData);
        }
Beispiel #2
0
        private EventData CreateEventData(ItemWithType @event)
        {
            var metadata = EventMetadata_V1.From(@event);

            var eventData = new EventData(
                Guid.NewGuid(),
                @event.type.Name,
                true,
                System.Text.Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(@event.instance)),
                MetadataSerializer.Serialize(metadata));

            return(eventData);
        }
Beispiel #3
0
 private void TryCallInterceptor(bool hasInterceptors, IInterceptEvents[] interceptors,
                                 ItemWithType @event, Action <IInterceptEvents, object, Type, object, Type> interceptorMethod)
 {
     if (hasInterceptors)
     {
         var interceptorCount = interceptors?.Length ?? 0;
         IInterceptEvents interceptor;
         for (int j = 0; j < interceptorCount; j++)
         {
             interceptor = interceptors[j];
             interceptorMethod(interceptor, @event.instance, @event.type, currentState, stateType);
         }
     }
 }
            public object ApplyEvent(Type stateType, object state, ItemWithType @event)
            {
                if (@event.instance is CountChangedClassEvent countClassEvent)
                {
                    return(Apply(state as TestState, countClassEvent));
                }

                if (@event.instance is ICountChangedInterfaceEvent countInterfaceEvent)
                {
                    return(Apply(state as TestState, countInterfaceEvent));
                }

                throw new NotSupportedException();
            }
        public static EsClientV20.EventData CreateV20EventData(this ItemWithType @event, IDateTimeProvider dateTimeProvider)
        {
            var metadata = EventMetadata_V2.From(@event,
                                                 (MetadataProperties.Timestamp, dateTimeProvider.UtcNow.ToString("yyyy-MM-dd HH:mm:ss")));

            var eventAsJson = JObject.FromObject(@event.instance);

            eventAsJson.Remove(CanEditJsonFieldName);

            return(new EsClientV20.EventData(
                       EsClientV20.Uuid.NewUuid(),
                       @event.type.Name,
                       System.Text.Encoding.UTF8.GetBytes(eventAsJson.ToString()),
                       MetadataSerializer.Serialize(metadata)));
        }
        public static EventData CreateEventData(this ItemWithType @event)
        {
            var metadata = EventMetadata_V1.From(@event);

            var eventAsJson = JObject.FromObject(@event.instance);

            eventAsJson.Remove(CanEditJsonFieldName);

            var eventData = new EventData(
                Guid.NewGuid(),
                @event.type.Name,
                true,
                System.Text.Encoding.UTF8.GetBytes(eventAsJson.ToString()),
                MetadataSerializer.Serialize(metadata));

            return(eventData);
        }
Beispiel #7
0
        public object ApplyEvent(Type stateType, object state, ItemWithType @event)
        {
            var switchable = state as ICanSwitchBackAndToReadOnly;

            if (switchable != null)
            {
                switchable.CanEdit = true;
            }

            state = ApplyAssumeWritable(stateType, state, @event.type, @event.instance);

            if (switchable != null)
            {
                switchable.CanEdit = false;
            }

            return(state);
        }
        public void GetFromTypes_WithwithTwoUpconverterInChainFromEventAToEventBToEventE_ShouldReturnDictionaryWithUpconvertFromEventBToEventE()
        {
            // Arrange
            var           types           = new[] { typeof(UpconverterAToB), typeof(UpconverterBToE) };
            UpconvertFunc upconverter     = null;
            var           originalEvent   = new EventB("Mr. Silly Name", 5);
            var           wrappedOriginal = new ItemWithType(originalEvent);
            var           expectedEvent   = new EventE("Mr. Silly Name-5");

            // Act
            upconverter = UpconverterCompiler.GetFrom(types)[typeof(EventB)];

            // Assert
            upconverter.Should().NotBeNull();
            upconverter(wrappedOriginal).isSingleItem.Should().BeTrue();
            upconverter(wrappedOriginal).single.type.Should().Be <EventE>();
            upconverter(wrappedOriginal).single.instance.As <EventE>().Formatted.Should().Be(expectedEvent.Formatted);
        }
Beispiel #9
0
 public bool TakeWhile(ItemWithType item) => true;
Beispiel #10
0
 private void AddEventInternal(ItemWithType @event)
 {
     NewEventsCollection.Add(@event);
     currentState = (TState)EventApplier.ApplyEvent(stateType, currentState, @event);
 }
Beispiel #11
0
 internal static EventMetadata_V1 From(ItemWithType @event)
 => new EventMetadata_V1(@event.type.FullName);
 Task IPublishEvents.Publish(ItemWithType @event, CancellationToken cancellationToken)
 {
     return(publishEndpoint.Publish(@event.instance, @event.type, cancellationToken));
 }
 public void PublishSync(ItemWithType @event)
 {
 }
 public Task Publish(ItemWithType @event, CancellationToken cancellationToken = default(CancellationToken)) => Done;
 public ReadResult(string eventStreamId, ItemWithType @event)
 {
     EventStreamId = eventStreamId;
     Event         = @event;
 }
        public bool TakeWhile(ItemWithType item)
        {
            foundSoftDelete = item.IsSoftDeleteEvent();

            return(!foundSoftDelete);
        }
 public static bool IsSoftDeleteEvent(this ItemWithType @event)
 => @event.type == DefaultSoftDeleteEvent.Type || @event.type.IsSubclassOf(DefaultSoftDeleteEvent.Type);
 internal static EventMetadata_V2 From(ItemWithType @event, params (string key, string value)[] properties)
 void IPublishEvents.PublishSync(ItemWithType @event)
 {
     publishEndpoint.Publish(@event.instance, @event.type).Wait();
 }