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

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

            var stateEntityId = this.ClientId; // Aggregate Id
            var eventEntityId = e.AudienceEventId.ClientId;

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

            if (stateVersion != eventVersion)
            {
                throw OptimisticConcurrencyException.Create(stateVersion, eventVersion, id.ToString());
            }
        }
Ejemplo n.º 2
0
 public void AddAudienceEvent(IAudienceEvent e)
 {
     _innerStateEvents.Add((AudienceStateCreatedOrMergePatchedOrDeletedDto)e);
 }
Ejemplo n.º 3
0
 public virtual AudienceStateCreatedOrMergePatchedOrDeletedDto ToAudienceStateEventDto(IAudienceEvent stateEvent)
 {
     if (stateEvent.EventType == StateEventType.Created)
     {
         var e = (IAudienceStateCreated)stateEvent;
         return(ToAudienceStateCreatedDto(e));
     }
     else if (stateEvent.EventType == StateEventType.MergePatched)
     {
         var e = (IAudienceStateMergePatched)stateEvent;
         return(ToAudienceStateMergePatchedDto(e));
     }
     else if (stateEvent.EventType == StateEventType.Deleted)
     {
         var e = (IAudienceStateDeleted)stateEvent;
         return(ToAudienceStateDeletedDto(e));
     }
     throw DomainError.Named("invalidEventType", String.Format("Invalid state event type: {0}", stateEvent.EventType));
 }