Exemplo n.º 1
0
        /// <summary>
        /// This method startpoint in execute side.Check input data and execute rover command.
        /// </summary>
        /// <param name="marsRoccerModel"></param>
        public void RunSimulate(MarsRoverModel marsRoccerModel)
        {
            _inputDataRef = marsRoccerModel;

            ValidationService.CheckInputData(marsRoccerModel);

            PlateauSize.PlateauX = (int)marsRoccerModel.PlateauModel.PlateauMaxX;
            PlateauSize.PlateauY = (int)marsRoccerModel.PlateauModel.PlateauMaxY;

            foreach (var rover in marsRoccerModel.RoverModels)
            {
                try
                {
                    ProcessRoverCommand.Execute(rover);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        ///    This method check null wxception for input data
        /// </summary>
        /// <param name="marsRoverModel"></param>
        /// <returns></returns>
        public static bool CheckInputData(MarsRoverModel marsRoverModel)
        {
            if (marsRoverModel != null)
            {
                if (marsRoverModel.PlateauModel.PlateauMaxX != null || marsRoverModel.PlateauModel.PlateauMaxY != null)
                {
                    if (marsRoverModel.RoverModels.Count > 0)
                    {
                        foreach (var rover in marsRoverModel.RoverModels)
                        {
                            if (string.IsNullOrEmpty(rover.RoverCommands) || rover.RoverX == null || rover.RoverY == null || string.IsNullOrEmpty(rover.RoverD))
                            {
                                throw new ArgumentException("Rover data is invalid.");
                            }
                        }
                        return(true);
                    }
                }

                throw new ArgumentException("Plateau data is invalid.");
            }
            throw new ArgumentNullException(nameof(marsRoverModel));
        }