コード例 #1
0
ファイル: PathElement.cs プロジェクト: dowdeswells/Challenges
 public static PathElement Known(IMovementCommand cmd)
 {
     return(new PathElement
     {
         IsToBeSolved = false,
         MovementCommand = cmd
     });
 }
コード例 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        public override bool ExecuteMovementCommand(IMovementCommand command)
        {
            if (!base.ExecuteMovementCommand(command))
            {
                return(false);
            }

            return(command.Invoke(this));
        }
コード例 #3
0
ファイル: PathFinder.cs プロジェクト: dowdeswells/Challenges
        private List <Trail> AdvanceTrails(List <Trail> trails, IMovementCommand cmd)
        {
            foreach (var trail in trails)
            {
                trail.Move(cmd);
            }

            return(FilterValidTrails(trails));
        }
コード例 #4
0
 public LocalMovementController(IUnityInputProxy unityInputProxy, INetworkController networkController,
                                IRotationCommand rotationCommand, IMovementCommand movementCommand, IUnityPhysicsProxy unityPhysicsProxy,
                                IUnityDebugProxy unityDebugProxy)
 {
     this.unityInputProxy   = unityInputProxy;
     this.unityPhysicsProxy = unityPhysicsProxy;
     this.unityDebugProxy   = unityDebugProxy;
     this.networkController = networkController;
     this.rotationCommand   = rotationCommand;
     this.movementCommand   = movementCommand;
 }
コード例 #5
0
ファイル: MovementAggregate.cs プロジェクト: uwitec/wms-8
        }// END Map(IMergePatch... ////////////////////////////

        protected virtual IMovementLineStateRemoved MapRemove(IRemoveMovementLine c, IMovementCommand outerCommand, long version)
        {
            c.RequesterId = outerCommand.RequesterId;
            var stateEventId            = new MovementLineEventId(c.MovementDocumentNumber, c.LineNumber, version);
            IMovementLineStateRemoved e = NewMovementLineStateRemoved(stateEventId);


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

            return(e);
        }// END Map(IRemove... ////////////////////////////
コード例 #6
0
        protected bool IsRepeatedCommand(IMovementCommand command, IEventStoreAggregateId eventStoreAggregateId, IMovementState state)
        {
            bool repeated = false;

            if (((IMovementStateProperties)state).Version > command.AggregateVersion)
            {
                var lastEvent = EventStore.GetEvent(typeof(IMovementEvent), eventStoreAggregateId, command.AggregateVersion);
                if (lastEvent != null && lastEvent.CommandId == command.CommandId)
                {
                    repeated = true;
                }
            }
            return(repeated);
        }
コード例 #7
0
ファイル: PathFinder.cs プロジェクト: dowdeswells/Challenges
        private List <Trail> ForkTrailsInAllDirections(List <Trail> trails)
        {
            List <Trail> forkedTrails = new List <Trail>();

            foreach (var trail in trails)
            {
                var forks = new IMovementCommand[] { new MoveDown(), new MoveLeft(), new MoveRight(), };
                foreach (var forkCmd in forks)
                {
                    var forked = trail.Fork();
                    forked.Move(forkCmd);
                    forkedTrails.Add(forked);
                }
                trail.Move(new MoveUp());
                forkedTrails.Add(trail);
            }
            return(FilterValidTrails(forkedTrails));
        }
コード例 #8
0
        public void Move(IMovementCommand cmd)
        {
            var nextPosition = cmd.Move(CurrentPosition);

            if (!_board.IsValidCoordinate(nextPosition))
            {
                Abort();
                return;
            }

            if (HasBeenHereBefore(nextPosition))
            {
                Abort();
                return;
            }

            _coordinates.Add(nextPosition);
            _commands.Add(cmd);
        }
コード例 #9
0
        protected virtual void Update(IMovementCommand c, Action <IMovementAggregate> action)
        {
            var aggregateId = c.AggregateId;
            var state       = StateRepository.Get(aggregateId, false);
            var aggregate   = GetMovementAggregate(state);

            var eventStoreAggregateId = ToEventStoreAggregateId(aggregateId);

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

            if (repeated)
            {
                return;
            }

            aggregate.ThrowOnInvalidStateTransition(c);
            action(aggregate);
            Persist(eventStoreAggregateId, aggregate, state);
        }
コード例 #10
0
ファイル: MovementAggregate.cs プロジェクト: uwitec/wms-8
        protected virtual IMovementLineStateCreated MapCreate(ICreateMovementLine c, IMovementCommand outerCommand, long version, IMovementState outerState)
        {
            c.RequesterId = outerCommand.RequesterId;
            var stateEventId            = new MovementLineEventId(c.MovementDocumentNumber, c.LineNumber, version);
            IMovementLineStateCreated e = NewMovementLineStateCreated(stateEventId);
            var s = outerState.MovementLines.Get(c.LineNumber, true);

            e.MovementQuantity       = c.MovementQuantity;
            e.ProductId              = c.ProductId;
            e.LocatorIdFrom          = c.LocatorIdFrom;
            e.LocatorIdTo            = c.LocatorIdTo;
            e.AttributeSetInstanceId = c.AttributeSetInstanceId;
            e.Processed              = c.Processed;
            e.ReversalLineNumber     = c.ReversalLineNumber;
            e.Active = c.Active;

            e.CreatedBy = (string)c.RequesterId;
            e.CreatedAt = ApplicationContext.Current.TimestampService.Now <DateTime>();
            return(e);
        }// END Map(ICreate... ////////////////////////////
コード例 #11
0
ファイル: MovementAggregate.cs プロジェクト: uwitec/wms-8
        protected void ThrowOnInconsistentCommands(IMovementCommand command, IMovementLineCommand innerCommand)
        {
            var properties      = command as ICreateOrMergePatchOrDeleteMovement;
            var innerProperties = innerCommand as ICreateOrMergePatchOrRemoveMovementLine;

            if (properties == null || innerProperties == null)
            {
                return;
            }
            if (innerProperties.MovementDocumentNumber == default(string))
            {
                innerProperties.MovementDocumentNumber = properties.DocumentNumber;
            }
            else
            {
                var outerDocumentNumberName          = "DocumentNumber";
                var outerDocumentNumberValue         = properties.DocumentNumber;
                var innerMovementDocumentNumberName  = "MovementDocumentNumber";
                var innerMovementDocumentNumberValue = innerProperties.MovementDocumentNumber;
                ThrowOnInconsistentIds(innerProperties, innerMovementDocumentNumberName, innerMovementDocumentNumberValue, outerDocumentNumberName, outerDocumentNumberValue);
            }
        }// END ThrowOnInconsistentCommands /////////////////////
コード例 #12
0
ファイル: MovementAggregate.cs プロジェクト: uwitec/wms-8
        }// END ThrowOnInconsistentCommands /////////////////////

        protected virtual IMovementLineEvent Map(IMovementLineCommand c, IMovementCommand outerCommand, long version, IMovementState outerState)
        {
            var create = (c.CommandType == CommandType.Create) ? (c as ICreateMovementLine) : null;

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

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

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

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

            if (remove != null)
            {
                return(MapRemove(remove, outerCommand, version));
            }
            throw new NotSupportedException();
        }
コード例 #13
0
ファイル: RobotBase.cs プロジェクト: PoojaDashora/ToyRobot
 /// <summary>
 /// Execute external command classes. It should inherited from IMovementCommand (Base Validation)
 /// </summary>
 /// <param name="command"></param>
 /// <returns></returns>
 public virtual bool ExecuteMovementCommand(IMovementCommand command)
 {
     return(HasPosition());
 }
コード例 #14
0
 internal MovementService(IMovementCommand leftCommand, IMovementCommand rightCommand, IMovementCommand moveCommand)
 {
     _leftCommand  = leftCommand;
     _rightCommand = rightCommand;
     _moveCommand  = moveCommand;
 }
コード例 #15
0
ファイル: MovementAggregate.cs プロジェクト: uwitec/wms-8
 private static bool IsCommandCreate(IMovementCommand c)
 {
     return(c.Version == MovementState.VersionZero);
 }