예제 #1
0
        protected void ThrowOnWrongEvent(IContactMechEvent e)
        {
            var id = new System.Text.StringBuilder();

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

            var stateEntityId = this.ContactMechId; // Aggregate Id
            var eventEntityId = e.ContactMechEventId.ContactMechId;

            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 = e.ContactMechEventId.Version;

            if (stateVersion != eventVersion)
            {
                throw OptimisticConcurrencyException.Create(stateVersion, eventVersion, id.ToString());
            }
        }
예제 #2
0
 public void AddContactMechEvent(IContactMechEvent e)
 {
     _innerStateEvents.Add((ContactMechStateCreatedOrMergePatchedOrDeletedDto)e);
 }
예제 #3
0
 public virtual ContactMechStateCreatedOrMergePatchedOrDeletedDto ToContactMechStateEventDto(IContactMechEvent stateEvent)
 {
     if (stateEvent.EventType == StateEventType.Created)
     {
         var e = (IContactMechStateCreated)stateEvent;
         return(ToContactMechStateCreatedDto(e));
     }
     else if (stateEvent.EventType == StateEventType.MergePatched)
     {
         var e = (IContactMechStateMergePatched)stateEvent;
         return(ToContactMechStateMergePatchedDto(e));
     }
     else if (stateEvent.EventType == StateEventType.Deleted)
     {
         var e = (IContactMechStateDeleted)stateEvent;
         return(ToContactMechStateDeletedDto(e));
     }
     throw DomainError.Named("invalidEventType", String.Format("Invalid state event type: {0}", stateEvent.EventType));
 }