Ejemplo n.º 1
0
        protected bool IsRepeatedCommand(IMovementConfirmationCommand command, IEventStoreAggregateId eventStoreAggregateId, IMovementConfirmationState state)
        {
            bool repeated = false;

            if (((IMovementConfirmationStateProperties)state).Version > command.AggregateVersion)
            {
                var lastEvent = EventStore.GetEvent(typeof(IMovementConfirmationEvent), eventStoreAggregateId, command.AggregateVersion);
                if (lastEvent != null && lastEvent.CommandId == command.CommandId)
                {
                    repeated = true;
                }
            }
            return(repeated);
        }
Ejemplo n.º 2
0
        protected virtual void Update(IMovementConfirmationCommand c, Action <IMovementConfirmationAggregate> action)
        {
            var aggregateId = c.AggregateId;
            var state       = StateRepository.Get(aggregateId, false);
            var aggregate   = GetMovementConfirmationAggregate(state);

            var eventStoreAggregateId = ToEventStoreAggregateId(aggregateId);

            var repeated = IsRepeatedCommand(c, eventStoreAggregateId, state);

            if (repeated)
            {
                return;
            }

            aggregate.ThrowOnInvalidStateTransition(c);
            action(aggregate);
            Persist(eventStoreAggregateId, aggregate, state);
        }
Ejemplo n.º 3
0
        protected void ThrowOnInconsistentCommands(IMovementConfirmationCommand command, IMovementConfirmationLineCommand innerCommand)
        {
            var properties      = command as ICreateOrMergePatchOrDeleteMovementConfirmation;
            var innerProperties = innerCommand as ICreateOrMergePatchOrRemoveMovementConfirmationLine;

            if (properties == null || innerProperties == null)
            {
                return;
            }
            if (innerProperties.MovementConfirmationDocumentNumber == default(string))
            {
                innerProperties.MovementConfirmationDocumentNumber = properties.DocumentNumber;
            }
            else
            {
                var outerDocumentNumberName  = "DocumentNumber";
                var outerDocumentNumberValue = properties.DocumentNumber;
                var innerMovementConfirmationDocumentNumberName  = "MovementConfirmationDocumentNumber";
                var innerMovementConfirmationDocumentNumberValue = innerProperties.MovementConfirmationDocumentNumber;
                ThrowOnInconsistentIds(innerProperties, innerMovementConfirmationDocumentNumberName, innerMovementConfirmationDocumentNumberValue, outerDocumentNumberName, outerDocumentNumberValue);
            }
        }// END ThrowOnInconsistentCommands /////////////////////
Ejemplo n.º 4
0
 private static bool IsCommandCreate(IMovementConfirmationCommand c)
 {
     return(c.Version == MovementConfirmationState.VersionZero);
 }
Ejemplo n.º 5
0
        }// END Map(IMergePatch... ////////////////////////////

        protected virtual IMovementConfirmationLineStateRemoved MapRemove(IRemoveMovementConfirmationLine c, IMovementConfirmationCommand outerCommand, long version)
        {
            c.RequesterId = outerCommand.RequesterId;
            var stateEventId = new MovementConfirmationLineEventId(c.MovementConfirmationDocumentNumber, c.LineNumber, version);
            IMovementConfirmationLineStateRemoved e = NewMovementConfirmationLineStateRemoved(stateEventId);


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

            return(e);
        }// END Map(IRemove... ////////////////////////////
Ejemplo n.º 6
0
        }// END Map(ICreate... ////////////////////////////

        protected virtual IMovementConfirmationLineStateMergePatched MapMergePatch(IMergePatchMovementConfirmationLine c, IMovementConfirmationCommand outerCommand, long version, IMovementConfirmationState outerState)
        {
            c.RequesterId = outerCommand.RequesterId;
            var stateEventId = new MovementConfirmationLineEventId(c.MovementConfirmationDocumentNumber, c.LineNumber, version);
            IMovementConfirmationLineStateMergePatched e = NewMovementConfirmationLineStateMergePatched(stateEventId);
            var s = outerState.MovementConfirmationLines.Get(c.LineNumber);

            e.MovementLineNumber = c.MovementLineNumber;
            e.TargetQuantity     = c.TargetQuantity;
            e.ConfirmedQuantity  = c.ConfirmedQuantity;
            e.DifferenceQuantity = c.DifferenceQuantity;
            e.ScrappedQuantity   = c.ScrappedQuantity;
            e.Description        = c.Description;
            e.Processed          = c.Processed;
            e.Active             = c.Active;
            e.IsPropertyMovementLineNumberRemoved = c.IsPropertyMovementLineNumberRemoved;
            e.IsPropertyTargetQuantityRemoved     = c.IsPropertyTargetQuantityRemoved;
            e.IsPropertyConfirmedQuantityRemoved  = c.IsPropertyConfirmedQuantityRemoved;
            e.IsPropertyDifferenceQuantityRemoved = c.IsPropertyDifferenceQuantityRemoved;
            e.IsPropertyScrappedQuantityRemoved   = c.IsPropertyScrappedQuantityRemoved;
            e.IsPropertyDescriptionRemoved        = c.IsPropertyDescriptionRemoved;
            e.IsPropertyProcessedRemoved          = c.IsPropertyProcessedRemoved;
            e.IsPropertyActiveRemoved             = c.IsPropertyActiveRemoved;

            e.CreatedBy = (string)c.RequesterId;
            e.CreatedAt = ApplicationContext.Current.TimestampService.Now <DateTime>();
            return(e);
        }// END Map(IMergePatch... ////////////////////////////
Ejemplo n.º 7
0
        }// END ThrowOnInconsistentCommands /////////////////////

        protected virtual IMovementConfirmationLineEvent Map(IMovementConfirmationLineCommand c, IMovementConfirmationCommand outerCommand, long version, IMovementConfirmationState outerState)
        {
            var create = (c.CommandType == CommandType.Create) ? (c as ICreateMovementConfirmationLine) : null;

            if (create != null)
            {
                return(MapCreate(create, outerCommand, version, outerState));
            }

            var merge = (c.CommandType == CommandType.MergePatch || c.CommandType == null) ? (c as IMergePatchMovementConfirmationLine) : null;

            if (merge != null)
            {
                return(MapMergePatch(merge, outerCommand, version, outerState));
            }

            var remove = (c.CommandType == CommandType.Remove) ? (c as IRemoveMovementConfirmationLine) : null;

            if (remove != null)
            {
                return(MapRemove(remove, outerCommand, version));
            }
            throw new NotSupportedException();
        }