protected bool IsRepeatedCommand(IAttributeUseMvoCommand command, IEventStoreAggregateId eventStoreAggregateId, IAttributeUseMvoState state)
        {
            bool repeated = false;

            if (((IAttributeUseMvoStateProperties)state).AttributeSetVersion > command.AggregateVersion)
            {
                var lastEvent = EventStore.GetEvent(typeof(IAttributeUseMvoEvent), eventStoreAggregateId, command.AggregateVersion);
                if (lastEvent != null && lastEvent.CommandId == command.CommandId)
                {
                    repeated = true;
                }
            }
            return(repeated);
        }
        protected virtual void Update(IAttributeUseMvoCommand c, Action <IAttributeUseMvoAggregate> action)
        {
            var aggregateId = c.AggregateId;
            var state       = StateRepository.Get(aggregateId, false);
            var aggregate   = GetAttributeUseMvoAggregate(state);

            var eventStoreAggregateId = ToEventStoreAggregateId(aggregateId);

            var repeated = IsRepeatedCommand(c, eventStoreAggregateId, state);

            if (repeated)
            {
                return;
            }

            aggregate.ThrowOnInvalidStateTransition(c);
            action(aggregate);
            Persist(eventStoreAggregateId, aggregate, state);
        }
Beispiel #3
0
        protected virtual void Update(IAttributeUseMvoCommand c, Action <IAttributeUseMvoAggregate> action)
        {
            var aggregateId = c.AggregateId;
            var state       = StateRepository.Get(aggregateId, false);
            var aggregate   = GetAttributeUseMvoAggregate(state);

            var eventStoreAggregateId = ToEventStoreAggregateId(aggregateId);

            var repeated = IsRepeatedCommand(c, eventStoreAggregateId, state);

            if (repeated)
            {
                return;
            }

            aggregate.ThrowOnInvalidStateTransition(c);
            action(aggregate);
            EventStore.AppendEvents(eventStoreAggregateId, ((IAttributeUseMvoStateProperties)state).AttributeSetVersion, aggregate.Changes, () => { StateRepository.Save(state); });
        }
Beispiel #4
0
 private static bool IsCommandCreate(IAttributeUseMvoCommand c)
 {
     return(c.AttributeSetVersion == AttributeUseMvoState.VersionZero);
 }