Esempio n. 1
0
        protected void ThrowOnWrongEvent(IAttributeSetStateEvent stateEvent)
        {
            var id = new System.Text.StringBuilder();

            id.Append("[").Append("AttributeSet|");

            var stateEntityId = this.AttributeSetId;                    // Aggregate Id
            var eventEntityId = stateEvent.StateEventId.AttributeSetId; // EntityBase.Aggregate.GetStateEventIdPropertyIdName();

            if (stateEntityId != eventEntityId)
            {
                throw DomainError.Named("mutateWrongEntity", "Entity Id {0} in state but entity id {1} in event", stateEntityId, eventEntityId);
            }
            id.Append(stateEntityId).Append(",");

            id.Append("]");

            var stateVersion = this.Version;
            var eventVersion = stateEvent.StateEventId.Version;

            if (stateVersion != eventVersion)
            {
                throw OptimisticConcurrencyException.Create(stateVersion, eventVersion, id.ToString());
            }
        }
Esempio n. 2
0
 public static void ThrowOnInconsistentEventIds(IAttributeSetStateEvent oe, IAttributeUseStateEvent e)
 {
     if (!oe.StateEventId.AttributeSetId.Equals(e.StateEventId.AttributeSetId))
     {
         throw DomainError.Named("inconsistentEventIds", "Outer Id AttributeSetId {0} but inner id AttributeSetId {1}",
                                 oe.StateEventId.AttributeSetId, e.StateEventId.AttributeSetId);
     }
 }
Esempio n. 3
0
        protected void ThrowOnWrongEvent(IAttributeSetStateEvent stateEvent)
        {
            var stateEntityId = this.AttributeSetId;                    // Aggregate Id
            var eventEntityId = stateEvent.StateEventId.AttributeSetId; // EntityBase.Aggregate.GetStateEventIdPropertyIdName();

            if (stateEntityId != eventEntityId)
            {
                throw DomainError.Named("mutateWrongEntity", "Entity Id {0} in state but entity id {1} in event", stateEntityId, eventEntityId);
            }

            var stateVersion = this.Version;
            var eventVersion = stateEvent.StateEventId.Version;

            if (stateVersion != eventVersion)
            {
                throw DomainError.Named("concurrencyConflict", "Conflict between state version {0} and event version {1}", stateVersion, eventVersion);
            }
        }
Esempio n. 4
0
 public void AddAttributeSetEvent(IAttributeSetStateEvent e)
 {
     _innerStateEvents.Add((AttributeSetStateCreatedOrMergePatchedOrDeletedDto)e);
 }
        public virtual AttributeSetStateCreatedOrMergePatchedOrDeletedDto ToAttributeSetStateEventDto(IAttributeSetStateEvent stateEvent)
        {
            if (stateEvent.StateEventType == StateEventType.Created)
            {
                var e = (IAttributeSetStateCreated)stateEvent;
                return(ToAttributeSetStateCreatedDto(e));
            }
            else if (stateEvent.StateEventType == StateEventType.MergePatched)
            {
                var e = (IAttributeSetStateMergePatched)stateEvent;
                return(ToAttributeSetStateMergePatchedDto(e));
            }
            else if (stateEvent.StateEventType == StateEventType.Deleted)
            {
                var e = (IAttributeSetStateDeleted)stateEvent;
                return(ToAttributeSetStateDeletedDto(e));
            }

            throw DomainError.Named("invalidStateEventType", String.Format("Invalid state event type: {0}", stateEvent.StateEventType));
        }