Example #1
0
        protected void ThrowOnWrongEvent(ILocatorStateEvent stateEvent)
        {
            var id = new System.Text.StringBuilder();

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

            var stateEntityId = this.LocatorId;                    // Aggregate Id
            var eventEntityId = stateEvent.StateEventId.LocatorId; // EntityBase.Aggregate.GetStateEventIdPropertyIdName();

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

            id.Append("]");

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

            if (stateVersion != eventVersion)
            {
                throw OptimisticConcurrencyException.Create(stateVersion, eventVersion, id.ToString());
            }
        }
Example #2
0
        protected void ThrowOnWrongEvent(ILocatorStateEvent stateEvent)
        {
            var stateEntityId = this.LocatorId;                    // Aggregate Id
            var eventEntityId = stateEvent.StateEventId.LocatorId; // EntityBase.Aggregate.GetStateEventIdPropertyIdName();

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

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

            if (stateVersion != eventVersion)
            {
                throw DomainError.Named("concurrencyConflict", "Conflict between state version {0} and event version {1}", stateVersion, eventVersion);
            }
        }
Example #3
0
 public void AddLocatorEvent(ILocatorStateEvent e)
 {
     _innerStateEvents.Add((LocatorStateCreatedOrMergePatchedOrDeletedDto)e);
 }
        public virtual LocatorStateCreatedOrMergePatchedOrDeletedDto ToLocatorStateEventDto(ILocatorStateEvent stateEvent)
        {
            if (stateEvent.StateEventType == StateEventType.Created)
            {
                var e = (ILocatorStateCreated)stateEvent;
                return(ToLocatorStateCreatedDto(e));
            }
            else if (stateEvent.StateEventType == StateEventType.MergePatched)
            {
                var e = (ILocatorStateMergePatched)stateEvent;
                return(ToLocatorStateMergePatchedDto(e));
            }
            else if (stateEvent.StateEventType == StateEventType.Deleted)
            {
                var e = (ILocatorStateDeleted)stateEvent;
                return(ToLocatorStateDeletedDto(e));
            }

            throw DomainError.Named("invalidStateEventType", String.Format("Invalid state event type: {0}", stateEvent.StateEventType));
        }