Exemple #1
0
 public static void ThrowOnInconsistentEventIds(IInventoryItemEvent oe, IInventoryItemEntryEvent e)
 {
     if (!oe.InventoryItemEventId.InventoryItemId.Equals(e.InventoryItemEntryEventId.InventoryItemId))
     {
         throw DomainError.Named("inconsistentEventIds", "Outer Id InventoryItemId {0} but inner id InventoryItemId {1}",
                                 oe.InventoryItemEventId.InventoryItemId, e.InventoryItemEntryEventId.InventoryItemId);
     }
 }
Exemple #2
0
        public void Save(IInventoryItemEntryEvent stateEvent)
        {
            InventoryItemEntryState state = ((InventoryItemEntryStateCreated)stateEvent).InventoryItemEntryState;

            CurrentSession.Save(state);
            var saveable = stateEvent as ISaveable;

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

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

            var stateEntityIdInventoryItemId = (this as IGlobalIdentity <InventoryItemEntryId>).GlobalId.InventoryItemId;
            var eventEntityIdInventoryItemId = e.InventoryItemEntryEventId.InventoryItemId;

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

            var stateEntityIdEntrySeqId = (this as IGlobalIdentity <InventoryItemEntryId>).GlobalId.EntrySeqId;
            var eventEntityIdEntrySeqId = e.InventoryItemEntryEventId.EntrySeqId;

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

            id.Append("]");

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

            if (e == null)
            {
                return;
            }
            stateEvent.Version = stateVersion;
            //var stateEventStateVersion = stateEvent.Version;
            //if (InventoryItemEntryState.VersionZero == stateEventStateVersion)
            //{
            //    stateEventStateVersion = stateEvent.Version = stateVersion;
            //}
            //if (stateVersion != stateEventStateVersion)
            //{
            //    throw OptimisticConcurrencyException.Create(stateVersion, stateEventStateVersion, id.ToString());
            //}
        }
        protected virtual IInventoryItemStateMergePatched Map(IMergePatchInventoryItem c)
        {
            var stateEventId = new InventoryItemEventId(c.InventoryItemId, c.Version);
            IInventoryItemStateMergePatched e = NewInventoryItemStateMergePatched(stateEventId);


            e.CommandId = c.CommandId;


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

            var version = c.Version;

            decimal onHandQuantity    = _state.OnHandQuantity;
            decimal inTransitQuantity = _state.InTransitQuantity;
            decimal reservedQuantity  = _state.ReservedQuantity;
            decimal occupiedQuantity  = _state.OccupiedQuantity;
            decimal virtualQuantity   = _state.VirtualQuantity;

            foreach (IInventoryItemEntryCommand innerCommand in c.InventoryItemEntryCommands)
            {
                ThrowOnInconsistentCommands(c, innerCommand);

                IInventoryItemEntryEvent innerEvent = Map(innerCommand, c, version, _state);
                e.AddInventoryItemEntryEvent(innerEvent);
                // ////////////////
                if (!(innerEvent is IInventoryItemEntryStateCreated))
                {
                    continue;
                }
                var entryCreated = (IInventoryItemEntryStateCreated)innerEvent;
                onHandQuantity    = onHandQuantity + (entryCreated.OnHandQuantity != null ? entryCreated.OnHandQuantity.GetValueOrDefault() : default(decimal));
                inTransitQuantity = inTransitQuantity + (entryCreated.InTransitQuantity != null ? entryCreated.InTransitQuantity.GetValueOrDefault() : default(decimal));
                reservedQuantity  = reservedQuantity + (entryCreated.ReservedQuantity != null ? entryCreated.ReservedQuantity.GetValueOrDefault() : default(decimal));
                occupiedQuantity  = occupiedQuantity + (entryCreated.OccupiedQuantity != null ? entryCreated.OccupiedQuantity.GetValueOrDefault() : default(decimal));
                virtualQuantity   = virtualQuantity + (entryCreated.VirtualQuantity != null ? entryCreated.VirtualQuantity.GetValueOrDefault() : default(decimal));
                // ////////////////
            }

            e.OnHandQuantity    = onHandQuantity;
            e.InTransitQuantity = inTransitQuantity;
            e.ReservedQuantity  = reservedQuantity;
            e.OccupiedQuantity  = occupiedQuantity;
            e.VirtualQuantity   = virtualQuantity;

            return(e);
        }
 public void AddInventoryItemEntryEvent(IInventoryItemEntryEvent e)
 {
     _innerStateEvents.Add((InventoryItemEntryStateCreatedOrMergePatchedOrRemovedDto)e);
 }
Exemple #6
0
 public virtual InventoryItemEntryStateCreatedOrMergePatchedOrRemovedDto ToInventoryItemEntryStateEventDto(IInventoryItemEntryEvent stateEvent)
 {
     if (stateEvent.EventType == StateEventType.Created)
     {
         var e = (IInventoryItemEntryStateCreated)stateEvent;
         return(ToInventoryItemEntryStateCreatedDto(e));
     }
     throw DomainError.Named("invalidEventType", String.Format("Invalid state event type: {0}", stateEvent.EventType));
 }
Exemple #7
0
 public virtual void AddInventoryItemEntryEvent(IInventoryItemEntryEvent e)
 {
     ThrowOnInconsistentEventIds(e);
     this._inventoryItemEntryEvents[e.InventoryItemEntryEventId] = e;
 }
Exemple #8
0
 protected void ThrowOnInconsistentEventIds(IInventoryItemEntryEvent e)
 {
     ThrowOnInconsistentEventIds(this, e);
 }
 void IInventoryItemStateMergePatched.AddInventoryItemEntryEvent(IInventoryItemEntryEvent e)
 {
     this._inventoryItemEntryEvents.AddInventoryItemEntryEvent(e);
 }