Esempio n. 1
0
        protected void ThrowOnWrongEvent(IInOutLineStateEvent stateEvent)
        {
            var stateEntityIdInOutDocumentNumber = (this as IGlobalIdentity <InOutLineId>).GlobalId.InOutDocumentNumber;
            var eventEntityIdInOutDocumentNumber = stateEvent.StateEventId.InOutDocumentNumber;

            if (stateEntityIdInOutDocumentNumber != eventEntityIdInOutDocumentNumber)
            {
                throw DomainError.Named("mutateWrongEntity", "Entity Id InOutDocumentNumber {0} in state but entity id InOutDocumentNumber {1} in event", stateEntityIdInOutDocumentNumber, eventEntityIdInOutDocumentNumber);
            }

            var stateEntityIdSkuId = (this as IGlobalIdentity <InOutLineId>).GlobalId.SkuId;
            var eventEntityIdSkuId = stateEvent.StateEventId.SkuId;

            if (stateEntityIdSkuId != eventEntityIdSkuId)
            {
                throw DomainError.Named("mutateWrongEntity", "Entity Id SkuId {0} in state but entity id SkuId {1} in event", stateEntityIdSkuId, eventEntityIdSkuId);
            }

            var stateVersion = this.Version;
            var eventVersion = stateEvent.Version;

            if (InOutLineState.VersionZero == eventVersion)
            {
                eventVersion = stateEvent.Version = stateVersion;
            }
            if (stateVersion != eventVersion)
            {
                throw DomainError.Named("concurrencyConflict", "Conflict between state version {0} and event version {1}", stateVersion, eventVersion);
            }
        }
Esempio n. 2
0
 public static void ThrowOnInconsistentEventIds(IInOutStateEvent oe, IInOutLineStateEvent e)
 {
     if (!oe.StateEventId.DocumentNumber.Equals(e.StateEventId.InOutDocumentNumber))
     {
         throw DomainError.Named("inconsistentEventIds", "Outer Id DocumentNumber {0} but inner id InOutDocumentNumber {1}",
                                 oe.StateEventId.DocumentNumber, e.StateEventId.InOutDocumentNumber);
     }
 }
Esempio n. 3
0
        public void Save(IInOutLineStateEvent stateEvent)
        {
            CurrentSession.Save(stateEvent);
            var saveable = stateEvent as ISaveable;

            if (saveable != null)
            {
                saveable.Save();
            }
        }
Esempio n. 4
0
        protected void ThrowOnWrongEvent(IInOutLineStateEvent stateEvent)
        {
            var id = new System.Text.StringBuilder();

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

            var stateEntityIdInOutDocumentNumber = (this as IGlobalIdentity <InOutLineId>).GlobalId.InOutDocumentNumber;
            var eventEntityIdInOutDocumentNumber = stateEvent.StateEventId.InOutDocumentNumber;

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

            var stateEntityIdLineNumber = (this as IGlobalIdentity <InOutLineId>).GlobalId.LineNumber;
            var eventEntityIdLineNumber = stateEvent.StateEventId.LineNumber;

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

            id.Append("]");

            if (ForReapplying)
            {
                return;
            }
            var stateVersion = this.Version;
            var eventVersion = stateEvent.Version;

            if (InOutLineState.VersionZero == eventVersion)
            {
                eventVersion = stateEvent.Version = stateVersion;
            }
            if (stateVersion != eventVersion)
            {
                throw OptimisticConcurrencyException.Create(stateVersion, eventVersion, id.ToString());
            }
        }
Esempio n. 5
0
        public virtual InOutLineStateCreatedOrMergePatchedOrRemovedDto ToInOutLineStateEventDto(IInOutLineStateEvent stateEvent)
        {
            if (stateEvent.StateEventType == StateEventType.Created)
            {
                var e = (IInOutLineStateCreated)stateEvent;
                return(ToInOutLineStateCreatedDto(e));
            }
            else if (stateEvent.StateEventType == StateEventType.MergePatched)
            {
                var e = (IInOutLineStateMergePatched)stateEvent;
                return(ToInOutLineStateMergePatchedDto(e));
            }
            else if (stateEvent.StateEventType == StateEventType.Removed)
            {
                var e = (IInOutLineStateRemoved)stateEvent;
                return(ToInOutLineStateRemovedDto(e));
            }

            throw DomainError.Named("invalidStateEventType", String.Format("Invalid state event type: {0}", stateEvent.StateEventType));
        }
Esempio n. 6
0
 public virtual void AddInOutLineEvent(IInOutLineStateEvent e)
 {
     ThrowOnInconsistentEventIds(e);
     this._inOutLineEvents[e.StateEventId] = e;
 }
Esempio n. 7
0
 protected void ThrowOnInconsistentEventIds(IInOutLineStateEvent e)
 {
     ThrowOnInconsistentEventIds(this, e);
 }
Esempio n. 8
0
        protected virtual IInOutStateMergePatched Map(IMergePatchInOut c)
        {
            var stateEventId          = new InOutStateEventId(c.DocumentNumber, c.Version);
            IInOutStateMergePatched e = NewInOutStateMergePatched(stateEventId);

            e.IsSOTransaction = c.IsSOTransaction;
            NewInOutDocumentActionCommandAndExecute(c, _state, e);
            e.Posted                                     = c.Posted;
            e.Processing                                 = c.Processing;
            e.Processed                                  = c.Processed;
            e.DocumentType                               = c.DocumentType;
            e.Description                                = c.Description;
            e.OrderNumber                                = c.OrderNumber;
            e.DateOrdered                                = c.DateOrdered;
            e.IsPrinted                                  = c.IsPrinted;
            e.MovementType                               = c.MovementType;
            e.MovementDate                               = c.MovementDate;
            e.BusinessPartnerId                          = c.BusinessPartnerId;
            e.WarehouseId                                = c.WarehouseId;
            e.POReference                                = c.POReference;
            e.FreightAmount                              = c.FreightAmount;
            e.ShipperId                                  = c.ShipperId;
            e.ChargeAmount                               = c.ChargeAmount;
            e.DatePrinted                                = c.DatePrinted;
            e.SalesRepresentative                        = c.SalesRepresentative;
            e.NumberOfPackages                           = c.NumberOfPackages;
            e.PickDate                                   = c.PickDate;
            e.ShipDate                                   = c.ShipDate;
            e.TrackingNumber                             = c.TrackingNumber;
            e.DateReceived                               = c.DateReceived;
            e.IsInTransit                                = c.IsInTransit;
            e.IsApproved                                 = c.IsApproved;
            e.IsInDispute                                = c.IsInDispute;
            e.Volume                                     = c.Volume;
            e.Weight                                     = c.Weight;
            e.RmaNumber                                  = c.RmaNumber;
            e.ReversalNumber                             = c.ReversalNumber;
            e.IsDropShip                                 = c.IsDropShip;
            e.DropShipBusinessPartnerId                  = c.DropShipBusinessPartnerId;
            e.Active                                     = c.Active;
            e.IsPropertyIsSOTransactionRemoved           = c.IsPropertyIsSOTransactionRemoved;
            e.IsPropertyPostedRemoved                    = c.IsPropertyPostedRemoved;
            e.IsPropertyProcessingRemoved                = c.IsPropertyProcessingRemoved;
            e.IsPropertyProcessedRemoved                 = c.IsPropertyProcessedRemoved;
            e.IsPropertyDocumentTypeRemoved              = c.IsPropertyDocumentTypeRemoved;
            e.IsPropertyDescriptionRemoved               = c.IsPropertyDescriptionRemoved;
            e.IsPropertyOrderNumberRemoved               = c.IsPropertyOrderNumberRemoved;
            e.IsPropertyDateOrderedRemoved               = c.IsPropertyDateOrderedRemoved;
            e.IsPropertyIsPrintedRemoved                 = c.IsPropertyIsPrintedRemoved;
            e.IsPropertyMovementTypeRemoved              = c.IsPropertyMovementTypeRemoved;
            e.IsPropertyMovementDateRemoved              = c.IsPropertyMovementDateRemoved;
            e.IsPropertyBusinessPartnerIdRemoved         = c.IsPropertyBusinessPartnerIdRemoved;
            e.IsPropertyWarehouseIdRemoved               = c.IsPropertyWarehouseIdRemoved;
            e.IsPropertyPOReferenceRemoved               = c.IsPropertyPOReferenceRemoved;
            e.IsPropertyFreightAmountRemoved             = c.IsPropertyFreightAmountRemoved;
            e.IsPropertyShipperIdRemoved                 = c.IsPropertyShipperIdRemoved;
            e.IsPropertyChargeAmountRemoved              = c.IsPropertyChargeAmountRemoved;
            e.IsPropertyDatePrintedRemoved               = c.IsPropertyDatePrintedRemoved;
            e.IsPropertySalesRepresentativeRemoved       = c.IsPropertySalesRepresentativeRemoved;
            e.IsPropertyNumberOfPackagesRemoved          = c.IsPropertyNumberOfPackagesRemoved;
            e.IsPropertyPickDateRemoved                  = c.IsPropertyPickDateRemoved;
            e.IsPropertyShipDateRemoved                  = c.IsPropertyShipDateRemoved;
            e.IsPropertyTrackingNumberRemoved            = c.IsPropertyTrackingNumberRemoved;
            e.IsPropertyDateReceivedRemoved              = c.IsPropertyDateReceivedRemoved;
            e.IsPropertyIsInTransitRemoved               = c.IsPropertyIsInTransitRemoved;
            e.IsPropertyIsApprovedRemoved                = c.IsPropertyIsApprovedRemoved;
            e.IsPropertyIsInDisputeRemoved               = c.IsPropertyIsInDisputeRemoved;
            e.IsPropertyVolumeRemoved                    = c.IsPropertyVolumeRemoved;
            e.IsPropertyWeightRemoved                    = c.IsPropertyWeightRemoved;
            e.IsPropertyRmaNumberRemoved                 = c.IsPropertyRmaNumberRemoved;
            e.IsPropertyReversalNumberRemoved            = c.IsPropertyReversalNumberRemoved;
            e.IsPropertyIsDropShipRemoved                = c.IsPropertyIsDropShipRemoved;
            e.IsPropertyDropShipBusinessPartnerIdRemoved = c.IsPropertyDropShipBusinessPartnerIdRemoved;
            e.IsPropertyActiveRemoved                    = c.IsPropertyActiveRemoved;

            ReflectUtils.CopyPropertyValue("CommandId", c, e);


            e.CreatedBy = (string)c.RequesterId;
            e.CreatedAt = DateTime.Now;

            var version = c.Version;

            foreach (IInOutLineCommand innerCommand in c.InOutLineCommands)
            {
                ThrowOnInconsistentCommands(c, innerCommand);

                IInOutLineStateEvent innerEvent = Map(innerCommand, c, version, _state);
                e.AddInOutLineEvent(innerEvent);
            }


            return(e);
        }
Esempio n. 9
0
 public void AddInOutLineEvent(IInOutLineStateEvent e)
 {
     _innerStateEvents.Add((InOutLineStateCreatedOrMergePatchedOrRemovedDto)e);
 }
Esempio n. 10
0
 void IInOutStateMergePatched.AddInOutLineEvent(IInOutLineStateEvent e)
 {
     this._inOutLineEvents.AddInOutLineEvent(e);
 }