public string ExecuteCommand(string commandArguments)
        {
            var commandName = commandArguments.Substring(0, commandArguments.IndexOf(' '));

            var commandParameters = new JavaScriptSerializer()
                .Deserialize<Dictionary<string, string>>(
                    commandArguments.Substring(commandArguments.IndexOf(' ') + 1));

            if (commandName != "SetupPark" && this.VehiclePark == null)
            {
                return "The vehicle park has not been set up";
            }

            ICommand command = null;
            switch (commandName)
            {
                case "SetupPark":
                    command = new SetupParkCommand(commandName, commandParameters, this.VehiclePark);
                    break;
                case "Park":
                    command = new ParkCommand(commandName, commandParameters, this.VehiclePark);
                    break;
                case "Exit":
                    command = new ExitCommand(commandName, commandParameters, this.VehiclePark);
                    break;
                case "Status":
                    command = new StatusCommand(commandName, commandParameters, this.VehiclePark);
                    break;
                case "FindVehicle":
                    command = new FindVehicleCommand(commandName, commandParameters, this.VehiclePark);
                    break;
                case "VehiclesByOwner":
                    command = new VehiclesByOwner(commandName, commandParameters, this.VehiclePark);
                    break;
                default:
                    throw new InvalidOperationException("Invalid command.");
            }

            var commandOutput = string.Empty;
            if (commandName == "SetupPark")
            {
                this.VehiclePark = command.Execute() as IVehiclePark;
                commandOutput = "Vehicle park created";
            }
            else
            {
                commandOutput = command.Execute() as string;
            }

            return commandOutput;
        }
Example #2
0
        public void TestInsertCarNoParkingLot()
        {
            // Arrage
            IEngine engine = new Engine();
            IDictionary <string, string> parameters = new Dictionary <string, string>();

            parameters.Add("type", "car");
            parameters.Add("time", "2015-05-04T10:30:00.0000000");
            parameters.Add("sector", "1");
            parameters.Add("place", "5");
            parameters.Add("licensePlate", "CA1001HH");
            parameters.Add("owner", "Endi");
            parameters.Add("hours", "1");

            ICommand parkCommand = new ParkCommand("park", parameters);

            // Act
            string message = engine.ExecuteCommand(parkCommand);

            // Assert
            Assert.AreEqual("The vehicle park has not been set up", message);
        }
        private void HandleButtonCommand(GameControllerButtonCommand command, GameControllerUpdateNotification notification)
        {
            int index;

            switch (command)
            {
            case GameControllerButtonCommand.UnPark:
                if (notification == GameControllerUpdateNotification.CommandUp)
                {
                    if (ParkCommand.CanExecute(null))
                    {
                        if (IsParked)
                        {
                            ParkCommand.Execute(null);
                        }
                    }
                }
                break;

            case GameControllerButtonCommand.ParkToHome:
                if (notification == GameControllerUpdateNotification.CommandUp)
                {
                    if (ParkCommand.CanExecute(null))
                    {
                        if (!IsParked)
                        {
                            ParkCommand.Execute(null);
                        }
                    }
                }
                break;

            case GameControllerButtonCommand.Sync:
                if (notification == GameControllerUpdateNotification.CommandUp)
                {
                    if (SyncCommand.CanExecute(null))
                    {
                        SyncCommand.Execute(null);
                    }
                }
                break;

            case GameControllerButtonCommand.IncrementPreset:
                index = Settings.SlewRatePresets.IndexOf(Settings.SlewRatePreset);
                if (index < Settings.SlewRatePresets.Count - 1)
                {
                    Settings.SlewRatePreset = Settings.SlewRatePresets[index + 1];
                }
                break;

            case GameControllerButtonCommand.DecrementPreset:
                index = Settings.SlewRatePresets.IndexOf(Settings.SlewRatePreset);
                if (index > 0)
                {
                    Settings.SlewRatePreset = Settings.SlewRatePresets[index - 1];
                }
                break;

            case GameControllerButtonCommand.EmergencyStop:
                if (notification == GameControllerUpdateNotification.CommandUp)
                {
                    if (StopSlewCommand.CanExecute(SlewButton.Stop))
                    {
                        StopSlewCommand.Execute(SlewButton.Stop);
                    }
                }
                break;

            case GameControllerButtonCommand.North:
                HandleSlewButton(SlewButton.North, notification);
                break;

            case GameControllerButtonCommand.South:
                HandleSlewButton(SlewButton.South, notification);
                break;

            case GameControllerButtonCommand.East:
                HandleSlewButton(SlewButton.East, notification);
                break;

            case GameControllerButtonCommand.West:
                HandleSlewButton(SlewButton.West, notification);
                break;

            case GameControllerButtonCommand.ReverseRA:
                if (notification == GameControllerUpdateNotification.CommandUp)
                {
                    Settings.ReverseRA = !Settings.ReverseRA;
                }
                break;

            case GameControllerButtonCommand.ReverseDec:
                if (notification == GameControllerUpdateNotification.CommandUp)
                {
                    Settings.ReverseDec = !Settings.ReverseDec;
                }
                break;

            case GameControllerButtonCommand.SiderealRate:
                HandleStartStopTrackingButton(TrackingMode.Sidereal, notification);
                break;

            case GameControllerButtonCommand.LunarRate:
                HandleStartStopTrackingButton(TrackingMode.Lunar, notification);
                break;

            case GameControllerButtonCommand.SolarRate:
                HandleStartStopTrackingButton(TrackingMode.Solar, notification);
                break;

            case GameControllerButtonCommand.CustomRate:
                HandleStartStopTrackingButton(TrackingMode.Custom, notification);
                break;

            case GameControllerButtonCommand.StopTracking:
                HandleStartStopTrackingButton(TrackingMode.Stop, notification);
                break;
            }
        }