Пример #1
0
 public static void ThrowOnInconsistentEventIds(IProductEvent oe, IGoodIdentificationEvent e)
 {
     if (!oe.ProductEventId.ProductId.Equals(e.GoodIdentificationEventId.ProductId))
     {
         throw DomainError.Named("inconsistentEventIds", "Outer Id ProductId {0} but inner id ProductId {1}",
                                 oe.ProductEventId.ProductId, e.GoodIdentificationEventId.ProductId);
     }
 }
Пример #2
0
        public void Save(IGoodIdentificationEvent stateEvent)
        {
            CurrentSession.Save(stateEvent);
            var saveable = stateEvent as ISaveable;

            if (saveable != null)
            {
                saveable.Save();
            }
        }
Пример #3
0
        protected void ThrowOnWrongEvent(IGoodIdentificationEvent e)
        {
            var id = new System.Text.StringBuilder();

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

            var stateEntityIdProductId = (this as IGlobalIdentity <ProductGoodIdentificationId>).GlobalId.ProductId;
            var eventEntityIdProductId = e.GoodIdentificationEventId.ProductId;

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

            var stateEntityIdGoodIdentificationTypeId = (this as IGlobalIdentity <ProductGoodIdentificationId>).GlobalId.GoodIdentificationTypeId;
            var eventEntityIdGoodIdentificationTypeId = e.GoodIdentificationEventId.GoodIdentificationTypeId;

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

            id.Append("]");

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

            if (e == null)
            {
                return;
            }
            stateEvent.Version = stateVersion;
            //var stateEventStateVersion = stateEvent.Version;
            //if (GoodIdentificationState.VersionZero == stateEventStateVersion)
            //{
            //    stateEventStateVersion = stateEvent.Version = stateVersion;
            //}
            //if (stateVersion != stateEventStateVersion)
            //{
            //    throw OptimisticConcurrencyException.Create(stateVersion, stateEventStateVersion, id.ToString());
            //}
        }
Пример #4
0
 public virtual void AddGoodIdentificationEvent(IGoodIdentificationEvent e)
 {
     ThrowOnInconsistentEventIds(e);
     this._goodIdentificationEvents[e.GoodIdentificationEventId] = e;
 }
Пример #5
0
 protected void ThrowOnInconsistentEventIds(IGoodIdentificationEvent e)
 {
     ThrowOnInconsistentEventIds(this, e);
 }
 public virtual GoodIdentificationStateCreatedOrMergePatchedOrRemovedDto ToGoodIdentificationStateEventDto(IGoodIdentificationEvent stateEvent)
 {
     if (stateEvent.EventType == StateEventType.Created)
     {
         var e = (IGoodIdentificationStateCreated)stateEvent;
         return(ToGoodIdentificationStateCreatedDto(e));
     }
     else if (stateEvent.EventType == StateEventType.MergePatched)
     {
         var e = (IGoodIdentificationStateMergePatched)stateEvent;
         return(ToGoodIdentificationStateMergePatchedDto(e));
     }
     else if (stateEvent.EventType == StateEventType.Removed)
     {
         var e = (IGoodIdentificationStateRemoved)stateEvent;
         return(ToGoodIdentificationStateRemovedDto(e));
     }
     throw DomainError.Named("invalidEventType", String.Format("Invalid state event type: {0}", stateEvent.EventType));
 }
Пример #7
0
        protected virtual IProductStateMergePatched Map(IMergePatchProduct c)
        {
            var stateEventId            = new ProductEventId(c.ProductId, c.Version);
            IProductStateMergePatched e = NewProductStateMergePatched(stateEventId);

            e.ProductTypeId            = c.ProductTypeId;
            e.PrimaryProductCategoryId = c.PrimaryProductCategoryId;
            e.ManufacturerPartyId      = c.ManufacturerPartyId;
            e.FacilityId                 = c.FacilityId;
            e.IntroductionDate           = c.IntroductionDate;
            e.ReleaseDate                = c.ReleaseDate;
            e.SupportDiscontinuationDate = c.SupportDiscontinuationDate;
            e.SalesDiscontinuationDate   = c.SalesDiscontinuationDate;
            e.SalesDiscWhenNotAvail      = c.SalesDiscWhenNotAvail;
            e.InternalName               = c.InternalName;
            e.BrandName                = c.BrandName;
            e.Comments                 = c.Comments;
            e.ProductName              = c.ProductName;
            e.Description              = c.Description;
            e.PriceDetailText          = c.PriceDetailText;
            e.SmallImageUrl            = c.SmallImageUrl;
            e.MediumImageUrl           = c.MediumImageUrl;
            e.LargeImageUrl            = c.LargeImageUrl;
            e.DetailImageUrl           = c.DetailImageUrl;
            e.OriginalImageUrl         = c.OriginalImageUrl;
            e.DetailScreen             = c.DetailScreen;
            e.InventoryMessage         = c.InventoryMessage;
            e.InventoryItemTypeId      = c.InventoryItemTypeId;
            e.RequireInventory         = c.RequireInventory;
            e.QuantityUomId            = c.QuantityUomId;
            e.QuantityIncluded         = c.QuantityIncluded;
            e.PiecesIncluded           = c.PiecesIncluded;
            e.RequireAmount            = c.RequireAmount;
            e.FixedAmount              = c.FixedAmount;
            e.AmountUomTypeId          = c.AmountUomTypeId;
            e.WeightUomId              = c.WeightUomId;
            e.ShippingWeight           = c.ShippingWeight;
            e.ProductWeight            = c.ProductWeight;
            e.HeightUomId              = c.HeightUomId;
            e.ProductHeight            = c.ProductHeight;
            e.ShippingHeight           = c.ShippingHeight;
            e.WidthUomId               = c.WidthUomId;
            e.ProductWidth             = c.ProductWidth;
            e.ShippingWidth            = c.ShippingWidth;
            e.DepthUomId               = c.DepthUomId;
            e.ProductDepth             = c.ProductDepth;
            e.ShippingDepth            = c.ShippingDepth;
            e.DiameterUomId            = c.DiameterUomId;
            e.ProductDiameter          = c.ProductDiameter;
            e.ProductRating            = c.ProductRating;
            e.RatingTypeEnum           = c.RatingTypeEnum;
            e.Returnable               = c.Returnable;
            e.Taxable                  = c.Taxable;
            e.ChargeShipping           = c.ChargeShipping;
            e.AutoCreateKeywords       = c.AutoCreateKeywords;
            e.IncludeInPromotions      = c.IncludeInPromotions;
            e.IsVirtual                = c.IsVirtual;
            e.IsVariant                = c.IsVariant;
            e.VirtualVariantMethodEnum = c.VirtualVariantMethodEnum;
            e.InShippingBox            = c.InShippingBox;
            e.DefaultShipmentBoxTypeId = c.DefaultShipmentBoxTypeId;
            e.IsSerialNumbered         = c.IsSerialNumbered;
            e.IsManagedByLot           = c.IsManagedByLot;
            e.AttributeSetId           = c.AttributeSetId;
            e.AttributeSetInstanceId   = c.AttributeSetInstanceId;
            e.Active = c.Active;
            e.IsPropertyProductTypeIdRemoved            = c.IsPropertyProductTypeIdRemoved;
            e.IsPropertyPrimaryProductCategoryIdRemoved = c.IsPropertyPrimaryProductCategoryIdRemoved;
            e.IsPropertyManufacturerPartyIdRemoved      = c.IsPropertyManufacturerPartyIdRemoved;
            e.IsPropertyFacilityIdRemoved                 = c.IsPropertyFacilityIdRemoved;
            e.IsPropertyIntroductionDateRemoved           = c.IsPropertyIntroductionDateRemoved;
            e.IsPropertyReleaseDateRemoved                = c.IsPropertyReleaseDateRemoved;
            e.IsPropertySupportDiscontinuationDateRemoved = c.IsPropertySupportDiscontinuationDateRemoved;
            e.IsPropertySalesDiscontinuationDateRemoved   = c.IsPropertySalesDiscontinuationDateRemoved;
            e.IsPropertySalesDiscWhenNotAvailRemoved      = c.IsPropertySalesDiscWhenNotAvailRemoved;
            e.IsPropertyInternalNameRemoved               = c.IsPropertyInternalNameRemoved;
            e.IsPropertyBrandNameRemoved                = c.IsPropertyBrandNameRemoved;
            e.IsPropertyCommentsRemoved                 = c.IsPropertyCommentsRemoved;
            e.IsPropertyProductNameRemoved              = c.IsPropertyProductNameRemoved;
            e.IsPropertyDescriptionRemoved              = c.IsPropertyDescriptionRemoved;
            e.IsPropertyPriceDetailTextRemoved          = c.IsPropertyPriceDetailTextRemoved;
            e.IsPropertySmallImageUrlRemoved            = c.IsPropertySmallImageUrlRemoved;
            e.IsPropertyMediumImageUrlRemoved           = c.IsPropertyMediumImageUrlRemoved;
            e.IsPropertyLargeImageUrlRemoved            = c.IsPropertyLargeImageUrlRemoved;
            e.IsPropertyDetailImageUrlRemoved           = c.IsPropertyDetailImageUrlRemoved;
            e.IsPropertyOriginalImageUrlRemoved         = c.IsPropertyOriginalImageUrlRemoved;
            e.IsPropertyDetailScreenRemoved             = c.IsPropertyDetailScreenRemoved;
            e.IsPropertyInventoryMessageRemoved         = c.IsPropertyInventoryMessageRemoved;
            e.IsPropertyInventoryItemTypeIdRemoved      = c.IsPropertyInventoryItemTypeIdRemoved;
            e.IsPropertyRequireInventoryRemoved         = c.IsPropertyRequireInventoryRemoved;
            e.IsPropertyQuantityUomIdRemoved            = c.IsPropertyQuantityUomIdRemoved;
            e.IsPropertyQuantityIncludedRemoved         = c.IsPropertyQuantityIncludedRemoved;
            e.IsPropertyPiecesIncludedRemoved           = c.IsPropertyPiecesIncludedRemoved;
            e.IsPropertyRequireAmountRemoved            = c.IsPropertyRequireAmountRemoved;
            e.IsPropertyFixedAmountRemoved              = c.IsPropertyFixedAmountRemoved;
            e.IsPropertyAmountUomTypeIdRemoved          = c.IsPropertyAmountUomTypeIdRemoved;
            e.IsPropertyWeightUomIdRemoved              = c.IsPropertyWeightUomIdRemoved;
            e.IsPropertyShippingWeightRemoved           = c.IsPropertyShippingWeightRemoved;
            e.IsPropertyProductWeightRemoved            = c.IsPropertyProductWeightRemoved;
            e.IsPropertyHeightUomIdRemoved              = c.IsPropertyHeightUomIdRemoved;
            e.IsPropertyProductHeightRemoved            = c.IsPropertyProductHeightRemoved;
            e.IsPropertyShippingHeightRemoved           = c.IsPropertyShippingHeightRemoved;
            e.IsPropertyWidthUomIdRemoved               = c.IsPropertyWidthUomIdRemoved;
            e.IsPropertyProductWidthRemoved             = c.IsPropertyProductWidthRemoved;
            e.IsPropertyShippingWidthRemoved            = c.IsPropertyShippingWidthRemoved;
            e.IsPropertyDepthUomIdRemoved               = c.IsPropertyDepthUomIdRemoved;
            e.IsPropertyProductDepthRemoved             = c.IsPropertyProductDepthRemoved;
            e.IsPropertyShippingDepthRemoved            = c.IsPropertyShippingDepthRemoved;
            e.IsPropertyDiameterUomIdRemoved            = c.IsPropertyDiameterUomIdRemoved;
            e.IsPropertyProductDiameterRemoved          = c.IsPropertyProductDiameterRemoved;
            e.IsPropertyProductRatingRemoved            = c.IsPropertyProductRatingRemoved;
            e.IsPropertyRatingTypeEnumRemoved           = c.IsPropertyRatingTypeEnumRemoved;
            e.IsPropertyReturnableRemoved               = c.IsPropertyReturnableRemoved;
            e.IsPropertyTaxableRemoved                  = c.IsPropertyTaxableRemoved;
            e.IsPropertyChargeShippingRemoved           = c.IsPropertyChargeShippingRemoved;
            e.IsPropertyAutoCreateKeywordsRemoved       = c.IsPropertyAutoCreateKeywordsRemoved;
            e.IsPropertyIncludeInPromotionsRemoved      = c.IsPropertyIncludeInPromotionsRemoved;
            e.IsPropertyIsVirtualRemoved                = c.IsPropertyIsVirtualRemoved;
            e.IsPropertyIsVariantRemoved                = c.IsPropertyIsVariantRemoved;
            e.IsPropertyVirtualVariantMethodEnumRemoved = c.IsPropertyVirtualVariantMethodEnumRemoved;
            e.IsPropertyInShippingBoxRemoved            = c.IsPropertyInShippingBoxRemoved;
            e.IsPropertyDefaultShipmentBoxTypeIdRemoved = c.IsPropertyDefaultShipmentBoxTypeIdRemoved;
            e.IsPropertyIsSerialNumberedRemoved         = c.IsPropertyIsSerialNumberedRemoved;
            e.IsPropertyIsManagedByLotRemoved           = c.IsPropertyIsManagedByLotRemoved;
            e.IsPropertyAttributeSetIdRemoved           = c.IsPropertyAttributeSetIdRemoved;
            e.IsPropertyAttributeSetInstanceIdRemoved   = c.IsPropertyAttributeSetInstanceIdRemoved;
            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 (IGoodIdentificationCommand innerCommand in c.GoodIdentificationCommands)
            {
                ThrowOnInconsistentCommands(c, innerCommand);

                IGoodIdentificationEvent innerEvent = Map(innerCommand, c, version, _state);
                e.AddGoodIdentificationEvent(innerEvent);
            }


            return(e);
        }
Пример #8
0
 void IProductStateMergePatched.AddGoodIdentificationEvent(IGoodIdentificationEvent e)
 {
     this._goodIdentificationEvents.AddGoodIdentificationEvent(e);
 }
 public void AddGoodIdentificationEvent(IGoodIdentificationEvent e)
 {
     _innerStateEvents.Add((GoodIdentificationStateCreatedOrMergePatchedOrRemovedDto)e);
 }