public bool TryParse(string line)
        {
            bool success = myCommandLine.TryParse(line);

            if (success)
            {
                Subsystem = myCommandLine.Argument(0);
                int index = line.IndexOf(Subsystem);
                line = line.Remove(index, Subsystem.Length);

                success = myCommandLine.TryParse(line);
            }
            return(success);
        }
Esempio n. 2
0
        private void RunCommand(string argument)
        {
            if (argument != null)
            {
                commandLine.TryParse(argument);
                var command = commandLine.Argument(0);
                if (command != null)
                {
                }
                else
                {
                    Init();
                    Search();
                }

                string current_group = "";
                if (commandLine.ArgumentCount > 1)
                {
                    current_group = commandLine.Argument(1);
                }
                if (Airlocks != null)
                {
                    Airlocks.ForEach(delegate(Airlock airlock)
                    {
                        if (current_group.Equals("") || airlock.GroupFilter.Contains(current_group))
                        {
                            airlock.RunCommand(argument);
                        }
                    });
                }
            }
        }
            private bool ParseArgs(string args)
            {
                CommandLine.TryParse(args);

                if (CommandLine.Argument(0) == null)
                {
                    return(true);
                }

                bool valid  = false;
                bool result = true;

                if (Commands.Keys.Any(x => x == CommandLine.Argument(0)))
                {
                    if (Commands[CommandLine.Argument(0)].MinumumArguments < CommandLine.ArgumentCount)
                    {
                        result = Commands[CommandLine.Argument(0)].Action(CommandLine);
                        valid  = true;
                    }
                }

                SaveEvent("Command:" + (valid?"":"invalid:") + "\"" + args + "\"");

                return(result);
            }
Esempio n. 4
0
        public void Main(string argument, UpdateType source)
        {
            if (m_instance == null && !Init())
            {
                return;
            }

            if ((source & (UpdateType.Mod | UpdateType.Script | UpdateType.Terminal | UpdateType.Trigger)) != 0)
            {
                if (m_command.TryParse(argument))
                {
                    m_instance.onCommand(m_command);
                }
                else
                {
                    Echo("Rescanning");
                    m_instance.ScanBlocks(GridTerminalSystem);    // with on args, rescan blocks
                }
            }
            if ((source & (UpdateType.IGC)) != 0)
            {
                m_instance.onIGCMessage();
            }
            if ((source & (UpdateType.Update1 | UpdateType.Update10 | UpdateType.Update100)) != 0)
            {
                m_instance.onTick(source);
            }
        }
Esempio n. 5
0
        public void Main(string argument, UpdateType updateSource)
        {
            if (commandLine.TryParse(argument))
            {
                Action commandAction;

                string command = commandLine.Argument(0);
                if (command == null)
                {
                    Echo("No command specified");
                }
                else if (commands.TryGetValue(command, out commandAction))
                {
                    // We have found a command. Invoke it.
                    commandAction();
                }
                else
                {
                    echoBuilder.AppendLine($"Unknown command {command}");
                }
            }
            else
            {
                echoBuilder.Clear();
                echoBuilder.Append(setupBuilder.ToString());

                Action updateAction;
                if (updates.TryGetValue(currentState, out updateAction))
                {
                    updateAction();
                }

                doDisplay();
            }
        }
Esempio n. 6
0
        private void ProcessCommand(string command)
        {
            if (Cmd.TryParse(command) && Cmd.ArgumentCount > 0)
            {
                switch (Cmd.Argument(0))
                {
                case "id": Message($"Drone computer IGC ID: 0x{IGC.Me:X}"); break;

                case "start": Start(Cmd.Argument(1)); break;

                case "capture": CaptureScanned(); break;

                case "grind": Grind(); break;

                case "halt": Halt("Warning: drone halted."); break;

                case "reload": Reload(); break;

                case "recall": Recall(); break;

                case "process_message": ProcessUnicast(); break;

                default:
                    Start(command);  break;
                }
            }
        }
Esempio n. 7
0
        public void Main(string argument, UpdateType updateSource)
        {
            if (_commandLine.TryParse(argument))
            {
                string command = _commandLine.Argument(0);
                if (command == null)
                {
                    Echo("No command specified");
                }
                else if (!command.Equals("land") && !command.Equals("scan"))
                {
                    Echo("Wrong command issued, should be 'scan' or 'land'");
                }
                else if (command.Equals("scan"))
                {
                    ExecuteScan();
                }
                else if (command.Equals("land"))
                {
                    ExecuteLanding();
                }
            }

            Echo("Status: " + Status);
            Scan();
            Land();
        }
Esempio n. 8
0
        public void Main(string argument, UpdateType updateSource)
        {
            if ((updateSource & ~(UpdateType.Update1 | UpdateType.Update10 | UpdateType.Update100)) != 0)
            {
                if (Cmd.TryParse(argument))
                {
                    switch (Cmd.Argument(0))
                    {
                    case "fly": FlyForward(); break;

                    case "dock": PerformDocking(); break;

                    case "scan": QuickScan(); break;

                    case "halt": QuickHalt(); break;

                    default:
                        Log($"Unknown command: {Cmd.Argument(0)}"); break;
                    }
                }
            }
            if ((updateSource & (UpdateType.Update1 | UpdateType.Update10 | UpdateType.Update100)) != 0)
            {
                if (Pilot.Tasks.Count > 0)
                {
                    Pilot.Update(Runtime.TimeSinceLastRun.TotalSeconds);
                }
                if (Cockpit.IsUnderControl)
                {
                    UpdateShipInfo();
                    UpdateStorageInfo();
                }
            }
        }
Esempio n. 9
0
        public void Main(string argument, UpdateType updateSource)
        {
            // MDK command parsing
            if (_commandLine.TryParse(argument))
            {
                Action commandAction;

                // Retrieve the first argument. Switches are ignored.
                string command = _commandLine.Argument(0);

                // Now we must validate that the first argument is actually specified,
                // then attempt to find the matching command delegate.
                if (command == null)
                {
                    Echo("No command specified");
                }
                else if (_commands.TryGetValue(_commandLine.Argument(0), out commandAction))
                {
                    // We have found a command. Invoke it.
                    commandAction();
                }
                else
                {
                    Echo($"Unknown command {command}");
                }
            }
        }
Esempio n. 10
0
        public void Main(string arg, UpdateType updateSource)
        {
            if (_commandLine.TryParse(arg))
            {
                Action commandAction;

                string command = _commandLine.Argument(0);

                if (_commands.TryGetValue(_commandLine.Argument(0), out commandAction))
                {
                    commandAction();
                    message = command + "\n" + message;
                }
                else
                {
                    message = $"Unknown command {command}";
                }
            }

            message = "Drill Deployed:\n" + status["deployed"];

            CheckDeploy();

            Echo(message);
            Echo("\nExecution Time: " + Runtime.LastRunTimeMs.ToString() + "ms");

            Me.GetSurface(0).WriteText(message);
        }
Esempio n. 11
0
        void MessageEntered(string msg, ref bool send)
        {
            try
            {
                if (!msg.StartsWith(MAIN_COMMAND))
                {
                    return;
                }

                if (!argParser.TryParse(msg))
                {
                    Utils.ShowColoredChatMessage(PaintGunMod.MOD_NAME, $"Couldn't parse command \"{msg}\" for some reason, please report!", MyFontEnum.Red);
                    Log.Error($"Couldn't parse command for some reason. Text entered: \"{msg}\"");
                    return;
                }

                send = false;

                string             alias = argParser.Argument(1) ?? string.Empty;
                CommandHandlerBase handler;

                if (AliasToCommandHandler.TryGetValue(alias, out handler))
                {
                    handler.Execute(argParser);
                }
                else
                {
                    Utils.ShowColoredChatMessage(PaintGunMod.MOD_NAME, $"Unknown command: {MAIN_COMMAND} {alias}", MyFontEnum.Red);
                }
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }
Esempio n. 12
0
        /* * * * * * * * * *
        * Main & Commands *
        * * * * * * * * * */

        public void Main(string argument, UpdateType updateSource)
        {
            //shit run every tick
            if ((updateSource & UpdateType.Update1) != 0)
            {
                //if we use the elevator
                if (useElevator && stations != null && stations.Count != 0)
                {
                    for (int i = 0; i < stations.Count; i++)
                    {
                        if (stations[i].Update())
                        {
                            broadcasts.Enqueue("request " + stations[i].name);
                        }
                    }
                }
            }

            //shit with arguments
            if ((updateSource & (UpdateType.Antenna | UpdateType.Trigger | UpdateType.Terminal)) != 0)
            {
                //if arguments are actually given
                if (cline.TryParse(argument))
                {
                    Action cAction;

                    String command = cline.Argument(0);

                    if (command == null)
                    {
                        writeLog("No Command was given!");
                    }
                    else if (commands.TryGetValue(command, out cAction))
                    {
                        cAction();
                    }
                    else
                    {
                        writeLog("Unknown Command: " + command);
                    }
                }
            }

            //at the end of every run we transmit one of the queued messages
            if (antenna != null && broadcasts.Count > 0)
            {
                if (sendable)
                {
                    antenna.TransmitMessage(broadcasts.Dequeue());
                    sendable = false;
                }
                else
                {
                    sendable = true;
                }
            }
        }
Esempio n. 13
0
        async void ServerFunction()
        {
            while (true)
            {
                using (var stream = new NamedPipeServerStream(_pipeName, PipeDirection.InOut, 4, PipeTransmissionMode.Byte, PipeOptions.Asynchronous))
                {
                    stream.ReadTimeout  = 500;
                    stream.WriteTimeout = 500;
                    var message = new MyCommandLine();
                    await stream.WaitForConnectionAsync(_cancellation.Token);

                    if (_cancellation.IsCancellationRequested)
                    {
                        return;
                    }

                    var writer = new StreamWriter(stream);
                    var reader = new StreamReader(stream);

                    writer.WriteLine($"ID \"{_identity}\"");
                    var messageSrc = reader.ReadLine();
                    if (string.IsNullOrWhiteSpace(messageSrc) || !message.TryParse(messageSrc))
                    {
                        writer.WriteLine("400");
                        continue;
                    }

                    var completion = new TaskCompletionSource <string>();
                    _synchronizationContext.Post(OnRequest, new Request(message, completion));
                    try
                    {
                        var response = completion.Task.Result;
                        if (response == null)
                        {
                            writer.WriteLine("400");
                        }
                        else
                        {
                            writer.WriteLine($"200 {response}");
                        }
                    }
                    catch (Exception exception)
                    {
                        void logError(object state)
                        {
                            MyLog.Default.WriteLine("MDKListenerPlugin Error");
                            MyLog.Default.WriteLine((Exception)state);
                        }

                        _synchronizationContext.Post(logError, exception);
                        writer.WriteLine("500");
                    }
                }
            }
        }
Esempio n. 14
0
        public void Main(string argument, UpdateType updateSource)
        {
            Echo(updateSource.Equals(UpdateFrequency.Update10) ? "Stopped" : "Running");

            if (_commandLine.TryParse(argument).Equals("stop"))
            {
                Runtime.UpdateFrequency = UpdateFrequency.None;
            }

            if (_commandLine.TryParse(argument).Equals("fix"))
            {
                Me.CustomData = "Battery.Empty";
            }

            LoadData();

            if ((updateSource & UpdateType.Update10) != 0 && !_commandLine.TryParse(argument).Equals("stop"))
            {
                StartStopHydrogenEngine();
            }
        }
Esempio n. 15
0
 public void Main(string argument, UpdateType updateSource)
 {
     subsystemManager.UpdateTime();
     if (commandLine.TryParse(argument))
     {
         subsystemManager.Command(commandLine.Argument(0), commandLine.Argument(1), commandLine.ArgumentCount > 2 ? commandLine.Argument(2) : null);
     }
     else
     {
         subsystemManager.Update(updateSource);
         Echo(subsystemManager.GetStatus());
     }
 }
Esempio n. 16
0
        public void Main(string argument, UpdateType updateSource)
        {
            if (commandLine.TryParse(argument))
            {
                Action action;
                string command = commandLine.Argument(0);

                if (command == null)
                {
                    Echo("No command specified");
                }
                else if (commands.TryGetValue(command, out action))
                {
                    action();
                }
            }

            string[] entries = Storage.Split(';');
            if (entries.Length == 5)
            {
                bool.TryParse(entries[0], out enableAltitude);
                bool.TryParse(entries[1], out enableProximity);
                bool.TryParse(entries[2], out firstRun);

                Enum.TryParse(entries[3], out gearState);

                double.TryParse(entries[4], out previousAltitude);
            }

            Echo("Altitude: " + enableAltitude.ToString());
            Echo("Proximity: " + enableProximity.ToString());

            if (enableProximity)
            {
                SetUpProximity();
            }
            if (enableAltitude)
            {
                SetUpAltitude();
            }

            if (firstRun)
            {
                //Calibrate gearState in case gear has never been deployed before
                List <IMyLandingGear> landingGear = new List <IMyLandingGear>();
                GridTerminalSystem.GetBlocksOfType(landingGear);

                CalibrateGearState(landingGear);
                firstRun = false;
            }
        }
Esempio n. 17
0
        /// <summary>Executes a command as if it was entered by user.</summary>
        public void ExecuteCommand(string command)
        {
            Log($">{command}");
            Action <MyCommandLine> handler;

            if (CmdLine.TryParse(command) && Commands.TryGetValue(CmdLine.Items[0], out handler))
            {
                handler?.Invoke(CmdLine);
            }
            else
            {
                Log($"Invalid command");
            }
        }
Esempio n. 18
0
        public void Main(string argument, UpdateType updateSource)
        {
            echoBuilder.Clear();

            if (!isSetup)
            {
                SetUp();
            }

            echoBuilder.Append(setupBuilder.ToString());

            echoBuilder.AppendLine($"Current state >> {currentState.ToString()}");

            GetBlocks();

            if (commandLine.TryParse(argument))
            {
                Action commandAction;

                // Retrieve the first argument. Switches are ignored.
                string command = commandLine.Argument(0);

                // Now we must validate that the first argument is actually specified,
                // then attempt to find the matching command delegate.
                if (command == null)
                {
                    Echo("No command specified");
                }
                else if (commands.TryGetValue(command, out commandAction))
                {
                    // We have found a command. Invoke it.
                    commandAction();
                }
                else
                {
                    echoBuilder.AppendLine($"Unknown command {command}");
                }
            }
            else
            {
                Action updateAction;
                if (updates.TryGetValue(currentState, out updateAction))
                {
                    updateAction();
                }
            }

            doDisplay();
        }
Esempio n. 19
0
        private void RunCommand(string argument)
        {
            if (argument != null)
            {
                commandLine.TryParse(argument);
                var command = commandLine.Argument(0);

                switch (command)
                {
                case "reset":
                    Prepare();
                    break;
                }
            }
        }
Esempio n. 20
0
            public void ParseCommand(string argument)
            {
                if (_commandLine.TryParse(argument))
                {
                    switch (_commandLine.Argument(0))
                    {
                    case Constants.C_ASSIGN:
                        myProgram.platformController.AddCommandToStack(_commandLine);
                        break;

                    default:
                        myProgram.Echo($"No valid command specified: {_commandLine.Argument(0)}");
                        break;
                    }
                }
            }
Esempio n. 21
0
        private void RunCommand(string argument)
        {
            MyProperty.Load();
            if (argument != null)
            {
                commandLine.TryParse(argument);
                var command = commandLine.Argument(0);

                switch (command)
                {
                default:
                    machine_state = StateMachine.TrakingLat;
                    last_power    = 0f;
                    break;
                }
            }
        }
        public static T Deserialise <T>(this IConfigurationReader <T> reader, T defaultConfiguration, string serialised) where T : new()
        {
            var commandLine = new MyCommandLine();

            if (String.IsNullOrWhiteSpace(serialised) || !commandLine.TryParse(serialised))
            {
                Debug.Write(Debug.Level.Info, "No stored configuration.");
                return(defaultConfiguration);
            }
            var configuration = new T();

            if (!reader.Read(configuration, commandLine.Items))
            {
                Debug.Write(Debug.Level.Error, "Unable to read the stored configuration. Resetting to defaults.");
                return(defaultConfiguration);
            }
            return(configuration);
        }
Esempio n. 23
0
        private void ProcessCommand(string argument)
        {
            if (CommandLine.TryParse(argument))
            {
                switch (CommandLine.Argument(0).ToLower())
                {
                case "initialize":
                case "init":
                    Output.AppendLine("Reinitializing");
                    Initialize();
                    break;

                default:
                    ProcessAirlockCommand();
                    break;
                }
            }
        }
Esempio n. 24
0
        public void Main(string argument, UpdateType updateSource)
        {
            Echo($"Time since last execute: {Runtime.TimeSinceLastRun}");
            previousState = currentState;

            if (_commandLine.TryParse(argument))
            {
                var newTargetState = _commandLine.Argument(0);
                if (String.Equals(newTargetState, "park", StringComparison.OrdinalIgnoreCase))
                {
                    targetState = MiningArmTargetState.PARK;
                }
                else if (String.Equals(newTargetState, "deploy", StringComparison.OrdinalIgnoreCase))
                {
                    targetState = MiningArmTargetState.DEPLOYED;
                    foreach (var hinge in miningArmBlocks.hinges)
                    {
                        hinge.TargetVelocityRPM = -1 * hinge.TargetVelocityRPM;
                    }
                }
                else if (String.Equals(newTargetState, "drill", StringComparison.OrdinalIgnoreCase))
                {
                    targetState = MiningArmTargetState.DRILLING;
                }
                else
                {
                    Echo("Unknown Command: " + newTargetState);
                }
            }

            currentState = DetectCurrentState();


            Echo("TagetState:   " + targetState);
            Echo("CurrentState: " + currentState);
            Echo("drillRotorOrientation: " + miningArmBlocks.drillRotor.Orientation);
            Echo("ArmGridPosition: " + miningArmBlocks.referenceHinge.TopGrid.GetPosition().ToString());
            Echo("Hinge Angle: " + miningArmBlocks.referenceHinge.Angle);



            Echo("");
            Echo("Executed instructions: " + Runtime.CurrentInstructionCount + "/" + Runtime.MaxInstructionCount);
        }
Esempio n. 25
0
        void CommandParser(string argument)
        {
            if (argument != null)
            {
                commandLine.TryParse(argument);
                var command = commandLine.Argument(0);

                switch (command)
                {
                case "reset":
                    lcd_ore.Search("ORE");
                    controller_refinery.Search();
                    controller_cargo_ore.Search();
                    controller_cargo_ingot.Search();
                    controller_refinery.RefineryInit();
                    RefineryOreCleanup();
                    RefineryIngotCleanup();
                    DisplayOre();
                    break;

                case "test":
                    Echo("Test");
                    Lcd lcd_test = new Lcd(this);
                    lcd_test.Search("Test");
                    if (lcd_test.IsEmpty)
                    {
                        Echo("Not found lcd Test");
                    }
                    else
                    {
                        Echo("Found lcd Test");
                        lcd_test.GetDrawing().Test();
                        lcd_test.GetDrawing().Dispose();
                    }
                    break;

                default:
                    //Echo("Command:");
                    //Echo(" reset");
                    break;
                }
            }
        }
Esempio n. 26
0
        private void RunCommand(string argument)
        {
            if (argument != null)
            {
                commandLine.TryParse(argument);
                var command = commandLine.Argument(0);

                switch (command)
                {
                case "reset":
                    Init();
                    break;

                default:
                    Search();
                    break;
                }
            }
        }
Esempio n. 27
0
        public void Main(string argument, UpdateType updateSource)
        {
            debug = SleepMode() ? "sleeping\n" : "working\n";
            if (solarMoving)
            {
                debug += solarRaising ? "solar raising\n" : "solar lowering\n";
            }
            if (drillMoving)
            {
                debug += drillRaising ? "drill raising\n" : "drill lowering\n";
            }

            LCD.GetSurface(0).WriteText(debug);

            if (_commandLine.TryParse(argument))
            {
                Action commandAction;

                string command = _commandLine.Argument(0);

                if (_commands.TryGetValue(_commandLine.Argument(0), out commandAction))
                {
                    commandAction();
                }
                else
                {
                    Echo($"Unknown command {command}");
                }
            }

            if (SleepMode())
            {
                return;
            }
            if (solarMoving)
            {
                SolarToggle();
            }
            else if (drillMoving)
            {
                DrillArmToggle();
            }
        }
Esempio n. 28
0
 private void RunCommand(string argument)
 {
     Init();
     if (argument != null)
     {
         commandLine.TryParse(argument);
         var command = commandLine.Argument(0);
         if (command != null)
         {
             command = command.Trim().ToLower();
         }
         switch (command)
         {
         default:
             search = true;
             Search();
             break;
         }
     }
 }
Esempio n. 29
0
        private void RunCommand(string argument)
        {
            Init();
            if (argument != null)
            {
                commandLine.TryParse(argument);
                var    command = commandLine.Argument(0);
                string tag     = commandLine.Argument(1);
                switch (command)
                {
                case "prefix":
                    RenamePrefix(tag);
                    break;

                case "unprefix":
                    UnRenamePrefix(tag);
                    break;
                }
            }
        }
Esempio n. 30
0
        public void Main(string argument, UpdateType updateSource)
        {
            Clock.AddTime(Runtime.TimeSinceLastRun);

            if (current == null)
            {
                Debug.ClearBuffer();
            }
            else
            {
                Debug.RestoreBuffer();
            }

            if (commandLine.TryParse(argument))
            {
                var command = commandLine.Argument(0);
                switch (command?.ToLower())
                {
                case "configure":
                    configuration = new ConfigurationReader().UpdateFromCommandLine(configuration, commandLine.Items.Skip(1));
                    instance      = null;
                    break;

                case "reset":
                    configuration = new RequestedConfiguration();
                    instance      = null;
                    break;

                case "rescan":
                    Rescan();
                    break;
                }
            }

            EnsureInitialised();

            if ((updateSource & (UpdateType.Update1 | UpdateType.Update10 | UpdateType.Update100)) != 0)
            {
                HandlePeriodicUpdate();
            }
        }