Example #1
0
        public void AddEvents(object[] events)
        {
            if (events == null)
            {
                throw new ArgumentNullException(nameof(events));
            }

            for (int i = 0; i < events.Length; i++)
            {
                NewEventsCollection.Add(new ItemWithType(events[i]));
            }

            currentState =
                (TState)EventApplier.Apply(stateType, currentState, events.Select(x => new ItemWithType(x)));
        }
Example #2
0
        public void AddEvents(IEnumerable <object> events)
        {
            if (events == null)
            {
                throw new ArgumentNullException(nameof(events));
            }

            foreach (var @event in events.Select(x => new ItemWithType(x)))
            {
                NewEventsCollection.Add(@event);
            }

            currentState =
                (TState)EventApplier.Apply(stateType, currentState, events.Select(x => new ItemWithType(x)));
        }
Example #3
0
        public async Task <int> SaveChanges(DeliveryTargetGuarntee targetGuarantee =
                                            DeliveryTargetGuarntee.AtLeastOnce,
                                            CancellationToken cancellationToken = default(CancellationToken))
        {
            ValidateStateOrThrow(stateValidator, currentState);

            var newEvents = NewEventsCollection.ToArray();
            var sendEventsBeforeSaving = targetGuarantee == DeliveryTargetGuarntee.AtLeastOnce;

            if (sendEventsBeforeSaving)
            {
                await PublishEvents(configuration, newEvents, cancellationToken);
            }

            bool hasInterceptors = configuration.HasInterceptors;

            for (int i = 0; i < newEvents.Length; i++)
            {
                TryCallInterceptor(hasInterceptors, configuration.Interceptors, newEvents[i],
                                   (interc, e, et, s, st) => interc.BeforeSave(e, et, s, st));
            }

            var retVal = await SaveChanges(newEvents, currentState, cancellationToken);

            for (int i = 0; i < newEvents.Length; i++)
            {
                TryCallInterceptor(hasInterceptors, configuration.Interceptors, newEvents[i],
                                   (interc, e, et, s, st) => interc.AfterSave(e, et, s, st));
            }


            if (!sendEventsBeforeSaving)
            {
                await PublishEvents(configuration, newEvents, cancellationToken);
            }

            return(retVal);
        }
Example #4
0
 private void AddEventInternal(ItemWithType @event)
 {
     NewEventsCollection.Add(@event);
     currentState = (TState)EventApplier.ApplyEvent(stateType, currentState, @event);
 }