Beispiel #1
0
        protected void ThrowOnWrongEvent(IShipmentPackageEvent e)
        {
            var id = new System.Text.StringBuilder();

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

            var stateEntityId = this.ShipmentPackageId; // Aggregate Id
            var eventEntityId = e.ShipmentPackageEventId.ShipmentPackageId;

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

            if (stateVersion != eventVersion)
            {
                throw OptimisticConcurrencyException.Create(stateVersion, eventVersion, id.ToString());
            }
        }
Beispiel #2
0
 public static void ThrowOnInconsistentEventIds(IShipmentPackageEvent oe, IShipmentPackageContentEvent e)
 {
     if (!oe.ShipmentPackageEventId.ShipmentPackageId.Equals(e.ShipmentPackageContentEventId.ShipmentPackageId))
     {
         throw DomainError.Named("inconsistentEventIds", "Outer Id ShipmentPackageId {0} but inner id ShipmentPackageId {1}",
                                 oe.ShipmentPackageEventId.ShipmentPackageId, e.ShipmentPackageContentEventId.ShipmentPackageId);
     }
 }
 public virtual ShipmentPackageStateCreatedOrMergePatchedOrDeletedDto ToShipmentPackageStateEventDto(IShipmentPackageEvent stateEvent)
 {
     if (stateEvent.EventType == StateEventType.Created)
     {
         var e = (IShipmentPackageStateCreated)stateEvent;
         return(ToShipmentPackageStateCreatedDto(e));
     }
     else if (stateEvent.EventType == StateEventType.MergePatched)
     {
         var e = (IShipmentPackageStateMergePatched)stateEvent;
         return(ToShipmentPackageStateMergePatchedDto(e));
     }
     else if (stateEvent.EventType == StateEventType.Deleted)
     {
         var e = (IShipmentPackageStateDeleted)stateEvent;
         return(ToShipmentPackageStateDeletedDto(e));
     }
     throw DomainError.Named("invalidEventType", String.Format("Invalid state event type: {0}", stateEvent.EventType));
 }
Beispiel #4
0
 public void AddShipmentPackageEvent(IShipmentPackageEvent e)
 {
     _innerStateEvents.Add((ShipmentPackageStateCreatedOrMergePatchedOrDeletedDto)e);
 }