コード例 #1
0
        public string Execute(ICommandHandler command)
        {
            if (command.Name != "SetupPark" && VehiclePark == null)
            {
                return "The vehicle park has not been set up";
            }

            switch(command.Name.ToString())
            {
                case "SetupPark":
                    VehiclePark = new VehiclePark(int.Parse(command.Parameters["sectors"]), int.Parse(command.Parameters["placesPerSector"]));
                    return "Vehicle park created";

                case "Park":
                    switch (command.Parameters["type"])
                        {
                            case "car":
                                return VehiclePark.InsertCar(new Car(command.Parameters["licensePlate"],
                                       command.Parameters["owner"], int.Parse(command.Parameters["hours"])), int.Parse(command.Parameters["sector"]),
                                       int.Parse(command.Parameters["place"]), DateTime.Parse(command.Parameters["time"], null,
                                       System.Globalization.DateTimeStyles.RoundtripKind));

                            case "motorbike":
                                return VehiclePark.InsertMotorbike(new Motorbike(command.Parameters["licensePlate"],
                                      command.Parameters["owner"], int.Parse(command.Parameters["hours"])), int.Parse(command.Parameters["sector"]),
                                      int.Parse(command.Parameters["place"]), DateTime.Parse(command.Parameters["time"], null,
                                      System.Globalization.DateTimeStyles.RoundtripKind));

                            case "truck":
                                return VehiclePark.InsertTruck(new Truck(command.Parameters["licensePlate"],
                                      command.Parameters["owner"], int.Parse(command.Parameters["hours"])), int.Parse(command.Parameters["sector"]),
                                      int.Parse(command.Parameters["place"]), DateTime.Parse(command.Parameters["time"], null,
                                      System.Globalization.DateTimeStyles.RoundtripKind));
                        }
                    break;

                case "Exit":
                    return VehiclePark.ExitVehicle(command.Parameters["licensePlate"],
                           DateTime.Parse(command.Parameters["time"], null, System.Globalization.DateTimeStyles.RoundtripKind),
                           decimal.Parse(command.Parameters["money"]));

                case "Status": return VehiclePark.GetStatus();
                case "FindVehicle": return VehiclePark.FindVehicle(command.Parameters["licensePlate"]);
                case "VehiclesByOwner": return VehiclePark.FindVehiclesByOwner(command.Parameters["owner"]);
                default:
                    throw new IndexOutOfRangeException("Invalid command.");
            }

            return string.Empty;
        }
コード例 #2
0
        public string Execution(ICommand command)
        {
            if (command.Name != "SetupPark" && VehiclePark == null)
            {
                return("The vehicle park has not been set up");
            }
            switch (command.Name)
            {
            //SetupPark {"sectors": 3, "placesPerSector": 5}
            case "SetupPark":
            {
                int iniciatedSectors         = int.Parse(command.Parameters["sectors"]);
                int initiatedPlacesPerSector = int.Parse(command.Parameters["placesPerSector"]);
                if (iniciatedSectors <= 0)
                {
                    return("The number of sectors must be positive");
                }

                if (initiatedPlacesPerSector <= 0)
                {
                    return("The number of places per sector must be positive");
                }

                this.VehiclePark = new VehiclePark(iniciatedSectors, initiatedPlacesPerSector);
                return("Vehicle park created"); break;
            }

            case "Park":
            {
                switch (command.Parameters["type"])
                {
                case "car":
                {
                    return(this.ExecuteParkCar(command)); break;
                }

                case "motorbike":
                {
                    return(ExecuteParkMotorbike(command)); break;
                }

                case "truck":
                {
                    return(ExecuteParkTruck(command)); break;
                }

                default:
                    throw new IndexOutOfRangeException("Invalid command inside.");
                }

                break;
            }

            case "Exit":
            {
                return(VehiclePark.ExitVehicle(
                           command.Parameters["licensePlate"],
                           DateTime.Parse(command.Parameters["time"], null, System.Globalization.DateTimeStyles.RoundtripKind),
                           decimal.Parse(command.Parameters["paid"]))); break;
            }

            case "Status":
            {
                return(VehiclePark.GetStatus()); break;
            }

            case "FindVehicle":
            {
                return(VehiclePark.FindVehicle(command.Parameters["licensePlate"])); break;
            }

            case "VehiclesByOwner":
            {
                return(VehiclePark.FindVehiclesByOwner(command.Parameters["owner"])); break;
            }

            default:
                throw new IndexOutOfRangeException("Invalid command.");
            }
        }
コード例 #3
0
        public string ExecuteCommand(ICommand command)
        {
            if (command.CommandName != "SetupPark" && this.vehiclePark == null)
            {
                return("The vehicle park has not been set up");
            }

            switch (command.CommandName)
            {
            case "SetupPark":
            {
                this.vehiclePark = new VehiclePark(int.Parse(command.CommandParameters["sectors"]), int.Parse(command.CommandParameters["placesPerSector"]));
                return("Vehicle park created");
            }

            case "Park":
            {
                DateTime time = DateTime.Parse(command.CommandParameters["time"], null, System.Globalization.DateTimeStyles.RoundtripKind);
                switch (command.CommandParameters["type"])
                {
                case "car":
                {
                    return(this.vehiclePark.InsertCar(
                               new Car(command.CommandParameters["licensePlate"],
                                       command.CommandParameters["owner"],
                                       int.Parse(command.CommandParameters["hours"])),
                               int.Parse(command.CommandParameters["sector"]),
                               int.Parse(command.CommandParameters["place"]),
                               time));
                }

                case "motorbike":
                {
                    return(this.vehiclePark.InsertMotorbike(
                               new Motorbike(command.CommandParameters["licensePlate"],
                                             command.CommandParameters["owner"],
                                             int.Parse(command.CommandParameters["hours"])),
                               int.Parse(command.CommandParameters["sector"]),
                               int.Parse(command.CommandParameters["place"]),
                               time));
                }

                case "truck":
                {
                    return(this.vehiclePark.InsertTruck(
                               new Truck(command.CommandParameters["licensePlate"],
                                         command.CommandParameters["owner"],
                                         int.Parse(command.CommandParameters["hours"])),
                               int.Parse(command.CommandParameters["sector"]),
                               int.Parse(command.CommandParameters["place"]),
                               time));
                }
                }

                break;
            }

            case "Exit":
            {
                DateTime time   = DateTime.Parse(command.CommandParameters["time"], null, System.Globalization.DateTimeStyles.RoundtripKind);
                string   output = this.vehiclePark.ExitVehicle(command.CommandParameters["licensePlate"], time, decimal.Parse(command.CommandParameters["paid"]));

                return(output);
            }

            case "Status":
            {
                return(this.vehiclePark.GetStatus());
            }

            case "FindVehicle":
            {
                string result = this.vehiclePark.FindVehicle(command.CommandParameters["licensePlate"]);

                return(result);
            }

            case "VehiclesByOwner":
            {
                return(this.vehiclePark.FindVehiclesByOwner(command.CommandParameters["owner"]));
            }

            default:
            {
                throw new IndexOutOfRangeException("Invalid command.");
            }
            }

            return(string.Empty);
        }
コード例 #4
0
ファイル: Command.cs プロジェクト: nedjoooo/High-Qulaity-Code
        public string ExecuteCommand(ICommand command)
        {
            if (command.CommandName != "SetupPark" && this.vehiclePark == null)
            {
                return "The vehicle park has not been set up";
            }

            switch (command.CommandName)
            {
                case "SetupPark":
                    {
                        this.vehiclePark = new VehiclePark(int.Parse(command.CommandParameters["sectors"]), int.Parse(command.CommandParameters["placesPerSector"]));
                        return "Vehicle park created";
                    }

                case "Park":
                    {
                        DateTime time = DateTime.Parse(command.CommandParameters["time"], null, System.Globalization.DateTimeStyles.RoundtripKind);
                        switch (command.CommandParameters["type"])
                        {
                            case "car":
                                {
                                    return this.vehiclePark.InsertCar(
                                        new Car(command.CommandParameters["licensePlate"],
                                            command.CommandParameters["owner"],
                                            int.Parse(command.CommandParameters["hours"])),
                                            int.Parse(command.CommandParameters["sector"]),
                                            int.Parse(command.CommandParameters["place"]),
                                            time);
                                }

                            case "motorbike":
                                {
                                    return this.vehiclePark.InsertMotorbike(
                                        new Motorbike(command.CommandParameters["licensePlate"],
                                            command.CommandParameters["owner"],
                                            int.Parse(command.CommandParameters["hours"])),
                                            int.Parse(command.CommandParameters["sector"]),
                                            int.Parse(command.CommandParameters["place"]),
                                            time);
                                }

                            case "truck":
                                {
                                    return this.vehiclePark.InsertTruck(
                                        new Truck(command.CommandParameters["licensePlate"],
                                            command.CommandParameters["owner"],
                                            int.Parse(command.CommandParameters["hours"])),
                                            int.Parse(command.CommandParameters["sector"]),
                                            int.Parse(command.CommandParameters["place"]),
                                            time);
                                }
                        }

                        break;
                    }

                case "Exit":
                    {
                        DateTime time = DateTime.Parse(command.CommandParameters["time"], null, System.Globalization.DateTimeStyles.RoundtripKind);
                        string output = this.vehiclePark.ExitVehicle(command.CommandParameters["licensePlate"], time, decimal.Parse(command.CommandParameters["paid"]));

                        return output;
                    }

                case "Status":
                    {
                        return this.vehiclePark.GetStatus();
                    }

                case "FindVehicle":
                    {
                        string result = this.vehiclePark.FindVehicle(command.CommandParameters["licensePlate"]);

                        return result;
                    }

                case "VehiclesByOwner":
                    {
                        return this.vehiclePark.FindVehiclesByOwner(command.CommandParameters["owner"]);
                    }

                default:
                    {
                        throw new IndexOutOfRangeException("Invalid command.");
                    }
            }

            return string.Empty;
        }