public static PathElement Known(IMovementCommand cmd) { return(new PathElement { IsToBeSolved = false, MovementCommand = cmd }); }
/// <summary> /// /// </summary> /// <param name="command"></param> /// <returns></returns> public override bool ExecuteMovementCommand(IMovementCommand command) { if (!base.ExecuteMovementCommand(command)) { return(false); } return(command.Invoke(this)); }
private List <Trail> AdvanceTrails(List <Trail> trails, IMovementCommand cmd) { foreach (var trail in trails) { trail.Move(cmd); } return(FilterValidTrails(trails)); }
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; }
}// 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... ////////////////////////////
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); }
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)); }
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); }
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); }
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... ////////////////////////////
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 /////////////////////
}// 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(); }
/// <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()); }
internal MovementService(IMovementCommand leftCommand, IMovementCommand rightCommand, IMovementCommand moveCommand) { _leftCommand = leftCommand; _rightCommand = rightCommand; _moveCommand = moveCommand; }
private static bool IsCommandCreate(IMovementCommand c) { return(c.Version == MovementState.VersionZero); }