Exemple #1
0
 public static void ThrowOnInconsistentEventIds(IAttributeEvent oe, IAttributeAliasEvent e)
 {
     if (!oe.AttributeEventId.AttributeId.Equals(e.AttributeAliasEventId.AttributeId))
     {
         throw DomainError.Named("inconsistentEventIds", "Outer Id AttributeId {0} but inner id AttributeId {1}",
                                 oe.AttributeEventId.AttributeId, e.AttributeAliasEventId.AttributeId);
     }
 }
        public void Save(IAttributeAliasEvent stateEvent)
        {
            CurrentSession.Save(stateEvent);
            var saveable = stateEvent as ISaveable;

            if (saveable != null)
            {
                saveable.Save();
            }
        }
Exemple #3
0
        protected virtual IAttributeStateMergePatched Map(IMergePatchAttribute c)
        {
            var stateEventId = new AttributeEventId(c.AttributeId, c.Version);
            IAttributeStateMergePatched e = NewAttributeStateMergePatched(stateEventId);

            e.AttributeName        = c.AttributeName;
            e.OrganizationId       = c.OrganizationId;
            e.Description          = c.Description;
            e.IsMandatory          = c.IsMandatory;
            e.AttributeValueType   = c.AttributeValueType;
            e.AttributeValueLength = c.AttributeValueLength;
            e.IsList      = c.IsList;
            e.FieldName   = c.FieldName;
            e.ReferenceId = c.ReferenceId;
            e.Active      = c.Active;
            e.IsPropertyAttributeNameRemoved        = c.IsPropertyAttributeNameRemoved;
            e.IsPropertyOrganizationIdRemoved       = c.IsPropertyOrganizationIdRemoved;
            e.IsPropertyDescriptionRemoved          = c.IsPropertyDescriptionRemoved;
            e.IsPropertyIsMandatoryRemoved          = c.IsPropertyIsMandatoryRemoved;
            e.IsPropertyAttributeValueTypeRemoved   = c.IsPropertyAttributeValueTypeRemoved;
            e.IsPropertyAttributeValueLengthRemoved = c.IsPropertyAttributeValueLengthRemoved;
            e.IsPropertyIsListRemoved      = c.IsPropertyIsListRemoved;
            e.IsPropertyFieldNameRemoved   = c.IsPropertyFieldNameRemoved;
            e.IsPropertyReferenceIdRemoved = c.IsPropertyReferenceIdRemoved;
            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 (IAttributeValueCommand innerCommand in c.AttributeValueCommands)
            {
                ThrowOnInconsistentCommands(c, innerCommand);

                IAttributeValueEvent innerEvent = Map(innerCommand, c, version, _state);
                e.AddAttributeValueEvent(innerEvent);
            }

            foreach (IAttributeAliasCommand innerCommand in c.AttributeAliasCommands)
            {
                ThrowOnInconsistentCommands(c, innerCommand);

                IAttributeAliasEvent innerEvent = Map(innerCommand, c, version, _state);
                e.AddAttributeAliasEvent(innerEvent);
            }


            return(e);
        }
Exemple #4
0
        protected void ThrowOnWrongEvent(IAttributeAliasEvent e)
        {
            var id = new System.Text.StringBuilder();

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

            var stateEntityIdAttributeId = (this as IGlobalIdentity <AttributeAliasId>).GlobalId.AttributeId;
            var eventEntityIdAttributeId = e.AttributeAliasEventId.AttributeId;

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

            var stateEntityIdCode = (this as IGlobalIdentity <AttributeAliasId>).GlobalId.Code;
            var eventEntityIdCode = e.AttributeAliasEventId.Code;

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

            id.Append("]");

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

            if (e == null)
            {
                return;
            }
            stateEvent.Version = stateVersion;
            //var stateEventStateVersion = stateEvent.Version;
            //if (AttributeAliasState.VersionZero == stateEventStateVersion)
            //{
            //    stateEventStateVersion = stateEvent.Version = stateVersion;
            //}
            //if (stateVersion != stateEventStateVersion)
            //{
            //    throw OptimisticConcurrencyException.Create(stateVersion, stateEventStateVersion, id.ToString());
            //}
        }
Exemple #5
0
 public virtual AttributeAliasStateCreatedOrMergePatchedOrRemovedDto ToAttributeAliasStateEventDto(IAttributeAliasEvent stateEvent)
 {
     if (stateEvent.EventType == StateEventType.Created)
     {
         var e = (IAttributeAliasStateCreated)stateEvent;
         return(ToAttributeAliasStateCreatedDto(e));
     }
     else if (stateEvent.EventType == StateEventType.MergePatched)
     {
         var e = (IAttributeAliasStateMergePatched)stateEvent;
         return(ToAttributeAliasStateMergePatchedDto(e));
     }
     else if (stateEvent.EventType == StateEventType.Removed)
     {
         var e = (IAttributeAliasStateRemoved)stateEvent;
         return(ToAttributeAliasStateRemovedDto(e));
     }
     throw DomainError.Named("invalidEventType", String.Format("Invalid state event type: {0}", stateEvent.EventType));
 }
Exemple #6
0
 public virtual void AddAttributeAliasEvent(IAttributeAliasEvent e)
 {
     ThrowOnInconsistentEventIds(e);
     this._attributeAliasEvents[e.AttributeAliasEventId] = e;
 }
Exemple #7
0
 protected void ThrowOnInconsistentEventIds(IAttributeAliasEvent e)
 {
     ThrowOnInconsistentEventIds(this, e);
 }
Exemple #8
0
 void IAttributeStateMergePatched.AddAttributeAliasEvent(IAttributeAliasEvent e)
 {
     this._attributeAliasEvents.AddAttributeAliasEvent(e);
 }
Exemple #9
0
 public void AddAttributeAliasEvent(IAttributeAliasEvent e)
 {
     _innerStateEvents.Add((AttributeAliasStateCreatedOrMergePatchedOrRemovedDto)e);
 }