示例#1
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 void Save(IShipmentPackageContentEvent stateEvent)
        {
            CurrentSession.Save(stateEvent);
            var saveable = stateEvent as ISaveable;

            if (saveable != null)
            {
                saveable.Save();
            }
        }
        protected void ThrowOnWrongEvent(IShipmentPackageContentEvent e)
        {
            var id = new System.Text.StringBuilder();

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

            var stateEntityIdShipmentPackageId = (this as IGlobalIdentity <ShipmentPackageContentId>).GlobalId.ShipmentPackageId;
            var eventEntityIdShipmentPackageId = e.ShipmentPackageContentEventId.ShipmentPackageId;

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

            var stateEntityIdShipmentItemSeqId = (this as IGlobalIdentity <ShipmentPackageContentId>).GlobalId.ShipmentItemSeqId;
            var eventEntityIdShipmentItemSeqId = e.ShipmentPackageContentEventId.ShipmentItemSeqId;

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

            id.Append("]");

            if (ForReapplying)
            {
                return;
            }
            var stateVersion = this.Version;
            var stateEvent   = e is IShipmentPackageContentStateEvent ? (IShipmentPackageContentStateEvent)e : null;

            if (e == null)
            {
                return;
            }
            stateEvent.Version = stateVersion;
            //var stateEventStateVersion = stateEvent.Version;
            //if (ShipmentPackageContentState.VersionZero == stateEventStateVersion)
            //{
            //    stateEventStateVersion = stateEvent.Version = stateVersion;
            //}
            //if (stateVersion != stateEventStateVersion)
            //{
            //    throw OptimisticConcurrencyException.Create(stateVersion, stateEventStateVersion, id.ToString());
            //}
        }
示例#4
0
        protected virtual IShipmentPackageStateMergePatched Map(IMergePatchShipmentPackage c)
        {
            var stateEventId = new ShipmentPackageEventId(c.ShipmentPackageId, c.Version);
            IShipmentPackageStateMergePatched e = NewShipmentPackageStateMergePatched(stateEventId);

            e.ShipmentBoxTypeId = c.ShipmentBoxTypeId;
            e.DateCreated       = c.DateCreated;
            e.BoxLength         = c.BoxLength;
            e.BoxHeight         = c.BoxHeight;
            e.BoxWidth          = c.BoxWidth;
            e.DimensionUomId    = c.DimensionUomId;
            e.Weight            = c.Weight;
            e.WeightUomId       = c.WeightUomId;
            e.InsuredValue      = c.InsuredValue;
            e.Active            = c.Active;
            e.IsPropertyShipmentBoxTypeIdRemoved = c.IsPropertyShipmentBoxTypeIdRemoved;
            e.IsPropertyDateCreatedRemoved       = c.IsPropertyDateCreatedRemoved;
            e.IsPropertyBoxLengthRemoved         = c.IsPropertyBoxLengthRemoved;
            e.IsPropertyBoxHeightRemoved         = c.IsPropertyBoxHeightRemoved;
            e.IsPropertyBoxWidthRemoved          = c.IsPropertyBoxWidthRemoved;
            e.IsPropertyDimensionUomIdRemoved    = c.IsPropertyDimensionUomIdRemoved;
            e.IsPropertyWeightRemoved            = c.IsPropertyWeightRemoved;
            e.IsPropertyWeightUomIdRemoved       = c.IsPropertyWeightUomIdRemoved;
            e.IsPropertyInsuredValueRemoved      = c.IsPropertyInsuredValueRemoved;
            e.IsPropertyActiveRemoved            = c.IsPropertyActiveRemoved;

            e.CommandId = c.CommandId;


            e.CreatedBy = (string)c.RequesterId;
            e.CreatedAt = ApplicationContext.Current.TimestampService.Now <DateTime>();

            var version = c.Version;

            foreach (IShipmentPackageContentCommand innerCommand in c.ShipmentPackageContentCommands)
            {
                ThrowOnInconsistentCommands(c, innerCommand);

                IShipmentPackageContentEvent innerEvent = Map(innerCommand, c, version, _state);
                e.AddShipmentPackageContentEvent(innerEvent);
            }


            return(e);
        }
示例#5
0
 public virtual void AddShipmentPackageContentEvent(IShipmentPackageContentEvent e)
 {
     ThrowOnInconsistentEventIds(e);
     this._shipmentPackageContentEvents[e.ShipmentPackageContentEventId] = e;
 }
示例#6
0
 protected void ThrowOnInconsistentEventIds(IShipmentPackageContentEvent e)
 {
     ThrowOnInconsistentEventIds(this, e);
 }
示例#7
0
 public void AddShipmentPackageContentEvent(IShipmentPackageContentEvent e)
 {
     _innerStateEvents.Add((ShipmentPackageContentStateCreatedOrMergePatchedOrRemovedDto)e);
 }
示例#8
0
 public virtual ShipmentPackageContentStateCreatedOrMergePatchedOrRemovedDto ToShipmentPackageContentStateEventDto(IShipmentPackageContentEvent stateEvent)
 {
     if (stateEvent.EventType == StateEventType.Created)
     {
         var e = (IShipmentPackageContentStateCreated)stateEvent;
         return(ToShipmentPackageContentStateCreatedDto(e));
     }
     else if (stateEvent.EventType == StateEventType.MergePatched)
     {
         var e = (IShipmentPackageContentStateMergePatched)stateEvent;
         return(ToShipmentPackageContentStateMergePatchedDto(e));
     }
     else if (stateEvent.EventType == StateEventType.Removed)
     {
         var e = (IShipmentPackageContentStateRemoved)stateEvent;
         return(ToShipmentPackageContentStateRemovedDto(e));
     }
     throw DomainError.Named("invalidEventType", String.Format("Invalid state event type: {0}", stateEvent.EventType));
 }
示例#9
0
 void IShipmentPackageStateMergePatched.AddShipmentPackageContentEvent(IShipmentPackageContentEvent e)
 {
     this._shipmentPackageContentEvents.AddShipmentPackageContentEvent(e);
 }