Пример #1
0
        private static string ExecuteCommand(string[] args, string commandString, int auto)
        {
            object command;
            object commandResult = null;
            string message       = null;

            switch (commandString)
            {
            case "park":
            case "p":
                new ParkCommand(_commandSender).Execute();
                break;

            case "parkw":
                command       = new ParkAndWaitCommand(_commandSender);
                commandResult = ((ParkAndWaitCommand)command).Execute();
                message       = ((ParkAndWaitCommand)command).Message;
                break;

            case "unpark":
            case "up":
                new UnparkCommand(_commandSender).Execute();
                break;

            case "command":
            case "c":
                new CustomCommand(_commandSender).Execute(new[] { args[2 - auto] });
                break;

            case "waitstationary":
                Status.WaitForStatus(_commandSender, MountState.Stationary, 30);
                break;

            case "stat":
                command       = new StatusCommand(_commandSender);
                commandResult = ((StatusCommand)command).Execute();
                break;

            case "stop":
                new StopTrackingCommand(_commandSender).Execute();
                break;

            case "start":
                new StartTrackingCommand(_commandSender).Execute();
                break;

            case "maxslew":
                command       = new SetMaxSlewCommand(_commandSender);
                commandResult = ((SetMaxSlewCommand)command).Execute(new[] { args[2 - auto] });
                message       = ((SetMaxSlewCommand)command).Message;
                break;

            case "gpsupdate":
                command       = new GpsUpdateCommand(_commandSender);
                commandResult = ((GpsUpdateCommand)command).Execute();
                message       = ((GpsUpdateCommand)command).Message;
                break;

            case "move":
            case "movew":
                MountState tracking      = new StatusCommand(_commandSender).Execute();
                string     az            = args[2 - auto];
                string     alt           = args[3 - auto];
                string     enableTraking = tracking == MountState.Tracking && commandString == "movew" ? "1" : "0";
                command       = new SlewAltAzCommand(_commandSender);
                commandResult = ((SlewAltAzCommand)command).Execute(new[] { az, alt, enableTraking });
                message       = ((SlewAltAzCommand)command).Message;
                break;

            case "refr":
            case "refraction":
            case "r":
                string pressure    = args[2 - auto];
                string temperature = args[3 - auto];
                command       = new SetRefractionCommand(_commandSender);
                commandResult = ((SetRefractionCommand)command).Execute(new[] { pressure, temperature });
                message       = ((SetRefractionCommand)command).Message;
                break;

            case "autorefr":
            case "ar":
                if (File.Exists(args[2 - auto]))
                {
                    StreamReader streamReader    = new StreamReader(args[2 - auto]);
                    string[]     data            = streamReader.ReadLine()?.Split(' ');
                    string       autoPressure    = ParseDecimal(data?[10]);
                    string       autoTemperature = ParseDecimal(data?[2]);
                    command       = new SetRefractionCommand(_commandSender);
                    commandResult = ((SetRefractionCommand)command).Execute(new[] { autoPressure, autoTemperature });
                    message       = ((SetRefractionCommand)command).Message;
                }
                else
                {
                    message = "?Refraction file not found.";
                }
                break;

            case "time":
                command       = new SetTimeCommand(_commandSender);
                commandResult = ((SetTimeCommand)command).Execute();
                message       = ((SetTimeCommand)command).Message;
                break;

            case "getwol":
                command       = new GetWakeOnLanCommand(_commandSender);
                commandResult = ((GetWakeOnLanCommand)command).Execute();
                message       = ((GetWakeOnLanCommand)command).Message;
                break;

            case "setwol":
                command       = new SetWakeOnLanCommand(_commandSender);
                commandResult = ((SetWakeOnLanCommand)command).Execute(new [] { args[2 - auto] });
                message       = ((SetWakeOnLanCommand)command).Message;
                break;

            case "shutdown":
                new ShutdownCommand(_commandSender).Execute();
                break;

            case "save":
                SaveIpAddress(args);
                break;

            case "fw":
                command       = new FirmwareCommand(_commandSender);
                commandResult = ((FirmwareCommand)command).Execute();
                break;

            default:
                Help();
                Environment.Exit(0);
                break;
            }

            var result = "";

            if (commandResult != null)
            {
                result += $"Result : {commandResult}\n";
            }

            if (!string.IsNullOrWhiteSpace(message))
            {
                result += $"{message}\n";
            }

            _commandSender.CloseConnection();
            return(result);
        }