示例#1
0
        protected bool IsRepeatedCommand(IPartyCommand command, IEventStoreAggregateId eventStoreAggregateId, IPartyState state)
        {
            bool repeated = false;

            if (((IPartyStateProperties)state).Version > command.AggregateVersion)
            {
                var lastEvent = EventStore.GetEvent(typeof(IPartyEvent), eventStoreAggregateId, command.AggregateVersion);
                if (lastEvent != null && lastEvent.CommandId == command.CommandId)
                {
                    repeated = true;
                }
            }
            return(repeated);
        }
示例#2
0
        protected virtual void Update(IPartyCommand c, Action <IPartyAggregate> action)
        {
            var aggregateId = c.AggregateId;
            var stateType   = GetStateType(c);
            var state       = StateRepository.Get(stateType, aggregateId, false);
            var aggregate   = GetPartyAggregate(state);

            var eventStoreAggregateId = ToEventStoreAggregateId(aggregateId);

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

            if (repeated)
            {
                return;
            }

            aggregate.ThrowOnInvalidStateTransition(c);
            action(aggregate);
            Persist(eventStoreAggregateId, aggregate, state);
        }
示例#3
0
        protected virtual Type GetStateType(IPartyCommand c)
        {
            Type   clazz            = null; //typeof(PartyState);
            string discriminatorVal = null;

            if (c is ICreateParty)
            {
                discriminatorVal = ((ICreateParty)c).PartyTypeId;
            }
            else if (c is IMergePatchParty)
            {
                discriminatorVal = ((IMergePatchParty)c).PartyTypeId;
            }
            else if (c is IDeleteParty)
            {
                discriminatorVal = ((IDeleteParty)c).PartyTypeId;
            }
            if (discriminatorVal != null)
            {
                switch (discriminatorVal)
                {
                case PartyTypeIds.Party:
                    clazz = typeof(PartyState);
                    break;

                case PartyTypeIds.Organization:
                    clazz = typeof(OrganizationState);
                    break;

                case PartyTypeIds.Person:
                    clazz = typeof(PersonState);
                    break;
                }
            }
            if (clazz == null)
            {
                throw new ArgumentException(String.Format("CANNOT find discriminator info from command: {0}", c));
            }
            return(clazz);
        }
示例#4
0
 private static bool IsCommandCreate(IPartyCommand c)
 {
     return(c.Version == PartyState.VersionZero);
 }