Exemplo n.º 1
0
        protected void ThrowOnWrongEvent(IAttributeEvent e)
        {
            var id = new System.Text.StringBuilder();

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

            var stateEntityId = this.AttributeId; // Aggregate Id
            var eventEntityId = e.AttributeEventId.AttributeId;

            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.AttributeEventId.Version;

            if (stateVersion != eventVersion)
            {
                throw OptimisticConcurrencyException.Create(stateVersion, eventVersion, id.ToString());
            }
        }
Exemplo n.º 2
0
 public static void ThrowOnInconsistentEventIds(IAttributeEvent oe, IAttributeAliasEvent e)
 {
     if (!oe.AttributeEventId.AttributeId.Equals(e.AttributeAliasEventId.AttributeId))
     {
         throw DomainError.Named("inconsistentEventIds", "Outer Id AttributeId {0} but inner id AttributeId {1}",
                                 oe.AttributeEventId.AttributeId, e.AttributeAliasEventId.AttributeId);
     }
 }
Exemplo n.º 3
0
 public void AddAttributeEvent(IAttributeEvent e)
 {
     _innerStateEvents.Add((AttributeStateCreatedOrMergePatchedOrDeletedDto)e);
 }
Exemplo n.º 4
0
 public virtual AttributeStateCreatedOrMergePatchedOrDeletedDto ToAttributeStateEventDto(IAttributeEvent stateEvent)
 {
     if (stateEvent.EventType == StateEventType.Created)
     {
         var e = (IAttributeStateCreated)stateEvent;
         return(ToAttributeStateCreatedDto(e));
     }
     else if (stateEvent.EventType == StateEventType.MergePatched)
     {
         var e = (IAttributeStateMergePatched)stateEvent;
         return(ToAttributeStateMergePatchedDto(e));
     }
     else if (stateEvent.EventType == StateEventType.Deleted)
     {
         var e = (IAttributeStateDeleted)stateEvent;
         return(ToAttributeStateDeletedDto(e));
     }
     throw DomainError.Named("invalidEventType", String.Format("Invalid state event type: {0}", stateEvent.EventType));
 }