Esempio n. 1
0
        /// <summary>
        /// Vrací command na základě příkazové řádky.
        /// </summary>
        /// <param name="cmdLine"></param>
        /// <returns></returns>
        private static MessageFromClient GetMessage(MyCommandLine cmdLine)
        {
            var result = GetCmdByLineMessage(cmdLine); //musí být před GetDoFileMessage(...)

            if (result != null)
            {
                return(result);
            }

            result = GetDoFileMessage(cmdLine);
            if (result != null)
            {
                return(result);
            }

            result = GetUploadMessage(cmdLine);
            if (result != null)
            {
                return(result);
            }

            result = GetCmdMessage(cmdLine);
            if (result != null)
            {
                return(result);
            }

            return(null);
        }
Esempio n. 2
0
            public void AddCommandToStack(MyCommandLine _commandLine)
            {
                if (Platforms.Count > 0 && null != _commandLine.Argument(0))
                {
                    switch (_commandLine.Argument(0))
                    {
                    case Constants.C_ASSIGN:
                        if (null == _commandLine.Argument(1) || _commandLine.Argument(1).Equals(Constants.C_AUTO))
                        {
                            AssignLandingPad(null);
                        }
                        else
                        {
                            foreach (KeyValuePair <string, Platform> value in Platforms)
                            {
                                if (value.Value.Name.Equals(_commandLine.Argument(1)))
                                {
                                    AssignLandingPad(_commandLine.Argument(1));
                                }
                            }
                        }
                        break;

                    default:
                        myProgram.Echo("No valid parameters specified\n");
                        break;
                    }
                }
                else
                {
                    myProgram.Echo("There are no landing platforms on the ship / station\n");
                }
            }
Esempio n. 3
0
 public override void onCommand(MyCommandLine args)
 {
     if (args.Argument(0) == "reset")
     {
         Counter = 0;
     }
 }
Esempio n. 4
0
            /// <summary>
            /// Handler for processing any of the 'trigger' upatetypes
            /// </summary>
            /// <param name="argument"></param>
            /// <param name="updateSource"></param>
            public void ProcessTrigger(MyCommandLine myCommandLine, UpdateType updateSource)
            {
                //                string[] args = argument.Trim().Split(' ');
                if (myCommandLine != null)
                {
                    if (myCommandLine.Argument(0) == "setmode")
                    {
                        int theNewState = 0;
                        if (myCommandLine.Argument(1) != null)
                        {
                            int theNewMode = Convert.ToInt32(myCommandLine.Argument(1));
                            if (myCommandLine.Argument(2) != null)
                            {
                                theNewState = Convert.ToInt32(myCommandLine.Argument(2));
                            }
                            SetMode(theNewMode, theNewState);
                        }
                        else
                        {
                            thisProgram.Echo("Invalid Syntax");
                        }
                    }
                }
                // else no arguments

                /*
                 *              // Debugging/play information
                 *              if (bIAmMain)
                 *              {
                 *                  SendToAllSubscribers(UnicastTagTrigger, argument);
                 *              }
                 *              else thisProgram.Echo("Trigger found, not not master");
                 */
            }
Esempio n. 5
0
        void Command(MyCommandLine cmd)
        {
            switch (cmd.Argument(1))
            {
            case "help": Owner.Log(Help); break;

            case "amount":
            {
                string name  = cmd.Argument(2);
                bool   found = false;
                foreach (var item in _Stock)
                {
                    if (item.Value.Name.IndexOf(name, StringComparison.CurrentCultureIgnoreCase) >= 0)
                    {
                        found = true;
                        Owner.Log($"{item.Value.Name}: {item.Value.FormatAmount()}");
                    }
                }
                if (!found)
                {
                    Owner.Log("No items found.");
                }
            }; break;

            case "reset":
            {
                Updating = true;
                _Stock.Clear();
                Owner.ScanGrid();
                Owner.Log("Stock reset. Scanning grid...");
            }; break;
            }
        }
Esempio n. 6
0
        //private Client()
        //{
        //    NamedPipeClientStream pipeClient =
        //        new NamedPipeClientStream(".", "testpipe",
        //            PipeDirection.InOut, PipeOptions.None,
        //            TokenImpersonationLevel.Impersonation);
        //}

        public async Task <string> Request(string transmitMessage)
        {
            using (var stream = new NamedPipeClientStream(".", _expectedIdentity, PipeDirection.InOut, PipeOptions.Asynchronous, TokenImpersonationLevel.Anonymous))
            {
                var message = new MyCommandLine();
                stream.ReadTimeout  = 500;
                stream.WriteTimeout = 500;
                await stream.ConnectAsync(500);

                var writer   = new StreamWriter(stream);
                var reader   = new StreamReader(stream);
                var response = await reader.ReadLineAsync();

                if (string.IsNullOrWhiteSpace(response) || response != $"ID {_expectedIdentity}")
                {
                    throw new ClientException("Bad response");
                }
                writer.WriteLine($"REQUEST {transmitMessage}");
                response = await reader.ReadLineAsync();

                if (string.IsNullOrWhiteSpace(response))
                {
                    throw new ClientException("Bad response");
                }
                var code = response.Substring(0, Math.Max(response.Length, response.IndexOf(' ')));
            }
            throw new NotImplementedException();
        }
Esempio n. 7
0
        private static void Main(string[] args)
        {
            ConsoleEx.WriteAppCaption();
            ConsoleEx.WriteLine($"Valid port(s): {Helpers.GetValidPorts()}");

            var cmdLine = new MyCommandLine(args);

            if (cmdLine.ExistsAny(new[] { PAR_HELP_1, PAR_HELP_2, PAR_HELP_3 }))
            {
                ShowHelp();
                return;
            }

            try
            {
                var comCom = new ComComunication(cmdLine.Value(PAR_PORT_LIST));

                Console.WriteLine($"Selected port: {comCom.PortName}");

                var comComThread = comCom.StartCommunication();
                var pipeName     = cmdLine.Exists(PAR_PIPE_NAME) ? cmdLine.Value(PAR_PIPE_NAME) : Helpers.GetPipeName(comCom.PortName);

                var pipeServer       = new PipeServer(pipeName, comCom.SerialPort);
                var pipeServerThread = pipeServer.Start();

                comComThread?.Join();
            }
            catch (Exception ex)
            {
                ConsoleEx.WriteError(ex);
            }
        }
        void Command(MyCommandLine cmd)
        {
            switch (cmd.Items[1])
            {
            case "status":
                foreach (var kv in _Airlocks)
                {
                    Owner.Log($"{kv.Key.Name}: {kv.Value.CurrentState}");
                }
                break;

            case "inner":
            case "outer":
            {
                foreach (var kv in _Airlocks)
                {
                    if (string.Equals(kv.Key.Name, cmd.Items[2], StringComparison.CurrentCultureIgnoreCase))
                    {
                        if (kv.Value.CurrentState == "Idle")
                        {
                            kv.Value.CurrentState = (cmd.Items[1] == "inner") ? "Inner Doors Opening" : "Outer Doors Opening";
                        }
                        else
                        {
                            Owner.Log($"Can't trigger '{cmd.Items[2]}' - airlock is not idle.");
                        }
                        return;
                    }
                }
                Owner.Log($"No such airlock: '{cmd.Items[2]}'");
            }; break;
            }
        }
Esempio n. 9
0
 /// <summary>
 /// Schedule a grid scan. It will happen over the course of several next ticks, depending on how large the grid is. <para/>
 /// This version can be registered as a command, and will cause a message "Grid scan complete" to be logged.
 /// </summary>
 public void ScanGrid(MyCommandLine args)
 {
     if (GroupFeed == null || BlockFeed == null)
     {
         Log("Initiating grid scan...");
         BlockFound += GridScanComplete;
         ScanGrid();
     }
 }
Esempio n. 10
0
 public Program()
 {
     Airlocks                = new Dictionary <string, Airlock>();
     CommandLine             = new MyCommandLine();
     InitSettings            = new MyIni();
     Runtime.UpdateFrequency = UpdateFrequency.Update10;
     Output = new StringBuilder();
     Initialize();
 }
Esempio n. 11
0
 void SetName(MyCommandLine args)
 {
     if (args.ArgumentCount != 2)
     {
         Echo("Usage: setname <name>"); return;
     }
     Name = args.Argument(1);
     updateMessage();
 }
Esempio n. 12
0
        public override void Execute(MyCommandLine parser)
        {
            bool rgb = (parser.Argument(1) == "rgb");

            float[] values = new float[3];

            if (rgb && parser.Argument(2).StartsWith("#", COMPARE_TYPE))
            {
                string hexText = parser.Argument(2);

                if (hexText.Length < 7)
                {
                    Utils.ShowColoredChatMessage(PaintGunMod.MOD_NAME, "Invalid HEX color, needs 6 characters after #.", MyFontEnum.Red);
                    return;
                }

                int c = 0;

                for (int i = 1; i < 7; i += 2)
                {
                    values[c++] = Convert.ToInt32(hexText[i].ToString() + hexText[i + 1].ToString(), 16);
                }
            }
            else
            {
                if (parser.ArgumentCount != 5)
                {
                    Utils.ShowColoredChatMessage(PaintGunMod.MOD_NAME, "Need to specify 3 numbers separated by spaces.", MyFontEnum.Red);
                    return;
                }

                for (int i = 0; i < 3; i++)
                {
                    string arg = parser.Argument(i + 2);
                    if (!float.TryParse(arg, out values[i]))
                    {
                        Utils.ShowColoredChatMessage(PaintGunMod.MOD_NAME, $"'{arg}' is not a valid number!", MyFontEnum.Red);
                        return;
                    }
                }
            }

            Vector3 colorMask;

            if (rgb)
            {
                colorMask = Utils.RGBToColorMask(new Color(MathHelper.Clamp((int)values[0], 0, 255), MathHelper.Clamp((int)values[1], 0, 255), MathHelper.Clamp((int)values[2], 0, 255)));
            }
            else
            {
                colorMask = Utils.HSVToColorMask(new Vector3(MathHelper.Clamp(values[0], 0f, 360f) / 360.0f, MathHelper.Clamp(values[1], 0f, 100f) / 100.0f, MathHelper.Clamp(values[2], 0f, 100f) / 100.0f));
            }

            PaintMaterial material = new PaintMaterial(colorMask, Main.Palette.GetLocalPaintMaterial().Skin);

            Main.Palette.GrabPaletteFromPaint(material);
        }
Esempio n. 13
0
 /// <summary>
 /// Handler for processing any of the 'trigger' upatetypes
 /// </summary>
 /// <param name="argument"></param>
 /// <param name="updateSource"></param>
 public void ProcessTrigger(MyCommandLine myCommandLine, UpdateType updateSource)
 {
     if (myCommandLine != null)
     {
         if (myCommandLine.Argument(0) == "orbitallaunch")
         {
             thisProgram.wicoControl.SetMode(WicoControl.MODE_ORBITALLAUNCH);
         }
     }
 }
 /// <summary>
 /// the function that will be run when we give the command
 /// </summary>
 /// <param name="commandline">A <c>MyCommandLine</c> object, that contains the parsed arguments that Main/Tick got.
 /// <para>See https://github.com/malware-dev/MDK-SE/wiki/VRage.Game.ModAPI.Ingame.Utilities.MyCommandLine </para>
 /// </param>
 /// <returns>whether the script should still execute jobs in this tick</returns>
 public bool MyCommandFunction(MyCommandLine commandline)
 {
     //this is your command functions body. Note that because its decladed in the body of the Program class, it has access to the RuntimeEnvironemnt and can use its members
     Env.Echo("there were", commandline.ArgumentCount, "arguments:");                //This version of echo is capable of expanding argument lists
     foreach (var x in commandline.Items)
     {
         Env.Echo(x);
     }
     return(true);            //If you return true, the Command will still process any active jobs in the Tick
 }
Esempio n. 15
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");
                    }
                }
            }
        }
 private bool CMD_run(MyCommandLine commandLine)
 {
     if (commandLine.ArgumentCount == 1)
     {
         return(true);
     }
     else
     {
         TryQueueJob(commandLine.Argument(1)); return(true);
     }
 }
Esempio n. 17
0
        void Command(MyCommandLine args)
        {
            switch (args.Argument(1))
            {
            case "write": AddLine(args.Argument(2)); break;

            case "clear": Buffer.Clear(); break;

            case "help": Owner.Log(HELP); break;

            default: Owner.Log($"Unknown command: {args.ToString()}"); break;
            }
        }
Esempio n. 18
0
        public override void Execute(MyCommandLine parser)
        {
            if (Main.Settings.Load())
            {
                Utils.ShowColoredChatMessage(PaintGunMod.MOD_NAME, "Reloaded and re-saved config.", MyFontEnum.Green);
            }
            else
            {
                Utils.ShowColoredChatMessage(PaintGunMod.MOD_NAME, "Config created with the current settings.", MyFontEnum.Green);
            }

            Main.Settings.Save();
            return;
        }
Esempio n. 19
0
            public virtual void onCommand(MyCommandLine args)
            {
                var key = args.Argument(0).ToLower();
                Action <MyCommandLine> handler;

                if (!m_commands.TryGetValue(key, out handler))
                {
                    var text = new StringBuilder();
                    text.Append("Commands: ");
                    text.Append(String.Join(", ", m_commands.Keys));
                    Echo(text.ToString());
                    return;
                }
                handler(args);
            }
 /// <summary>
 /// Handler for processing any of the 'trigger' upatetypes
 /// </summary>
 /// <param name="argument"></param>
 /// <param name="updateSource"></param>
 internal void ProcessTrigger(string sArgument, MyCommandLine myCommandLine, UpdateType updateSource)
 {
     if (myCommandLine.ArgumentCount > 1)
     {
         if (myCommandLine.Argument(0) == "setmode")
         {
             int  toMode = 0;
             bool bOK    = int.TryParse(myCommandLine.Argument(1), out toMode);
             if (bOK)
             {
                 SetMode(toMode);
             }
         }
     }
 }
            private bool CMD_evaluate(MyCommandLine commandLine)
            {
                if (commandLine.Argument(1) == "all")
                {
                    foreach (var x in JobNames)
                    {
                        TryRegisterEvaluation(x);
                    }
                }
                else
                {
                    TryRegisterEvaluation(commandLine.Argument(1));
                }

                return(true);
            }
            private bool CMD_toggle(MyCommandLine commandLine)
            {
                if (commandLine.ArgumentCount == 1)
                {
                    TrySetActive();
                }
                else if (commandLine.ArgumentCount == 2)
                {
                    if (commandLine.Argument(1) == "all")
                    {
                        foreach (var name in JobNames)
                        {
                            TrySetActive(name);
                        }
                    }
                    else
                    {
                        if (JobNames.Contains(commandLine.Argument(1)))
                        {
                            TrySetActive(commandLine.Argument(1));
                        }
                    }
                }
                else if (commandLine.ArgumentCount == 3)
                {
                    int state = commandLine.Argument(2) == "" ? -1 :
                                commandLine.Argument(2) == "off" ? 0 :
                                commandLine.Argument(2) == "on" ? 1 :
                                -2;

                    if (state != -2)
                    {
                        if (commandLine.Argument(1) == "all")
                        {
                            foreach (var name in JobNames)
                            {
                                TrySetActive(name, state);
                            }
                        }
                        else
                        {
                            TrySetActive(commandLine.Argument(1), state);
                        }
                    }
                }
                return(true);
            }
Esempio n. 23
0
        public override void Execute(MyCommandLine parser)
        {
            if (Main.LocalToolHandler.LocalTool == null)
            {
                Utils.ShowColoredChatMessage(PaintGunMod.MOD_NAME, "You need to hold the paint gun for this to work.", MyFontEnum.Red);
            }
            else
            {
                if (Main.Palette.ReplaceMode)
                {
                    Main.Palette.ReplaceMode = false;
                    Main.Notifications.Show(3, "Replace color mode turned off.", MyFontEnum.Debug, 2000);
                }

                Main.Palette.ColorPickMode = true;
            }
        }
Esempio n. 24
0
 public void AddCommandToStack(MyCommandLine _commandLine)
 {
     if (null != _commandLine.Argument(1))
     {
         if (_commandLine.Argument(1).Equals(Constants.P_ON))
         {
             myProgram.isLeakManagementOn = true;
         }
         else if (_commandLine.Argument(1).Equals(Constants.P_OFF))
         {
             myProgram.isLeakManagementOn = false;
         }
         else
         {
             myProgram.Echo("No valid command\n");
         }
     }
 }
        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. 26
0
        /* * * * *
        * SETUP *
        * * * * */

        public Program()
        {
            //adding the commands to the dictionary
            commands         = new Dictionary <string, Action>(StringComparer.OrdinalIgnoreCase);
            commands["open"] = open;
            cline            = new MyCommandLine();

            //broadcasting stuff
            broadcasts = new Queue <string>();
            antenna    = getAntenna();
            sendable   = true;

            //filling the lists
            getTextpanels();
            getStations();
            getGarages();
            log      = "";
            logQueue = new Queue <string>();

            useElevator             = true;
            useGarages              = true;
            Runtime.UpdateFrequency = UpdateFrequency.Update1;

            if (antenna != null)
            {
                writeLog("Antenna found: " + antenna.CustomName);
            }
            if (stations != null)
            {
                for (int i = 0; i < stations.Count; i++)
                {
                    writeLog("Station found: " + stations[i].name);
                }
            }
            if (garages != null)
            {
                for (int i = 0; i < garages.Count; i++)
                {
                    writeLog("garage found: " + garages[i].name);
                }
            }
            syncStations();
        }
Esempio n. 27
0
        private static MessageFromClient GetCmdByLineMessage(MyCommandLine cmdLine)
        {
            if (!cmdLine.ExistsAll(new [] { PAR_CMD_DOFILE, PAR_CMD_LINE }))
            {
                return(null);
            }

            var fileName = cmdLine.Value(PAR_CMD_DOFILE);

            if (string.IsNullOrEmpty(fileName))
            {
                throw new Exception("File not specified.");
            }

            var lineIndex = cmdLine.Value(PAR_CMD_LINE, 0) - 1; //řádky jsou v VS Code číslovány od jedničky, převádím je tedy na index

            if (lineIndex < 0)
            {
                throw new Exception("Line not specified.");
            }

            //--- vytáhneme příslušný řádek (očekáváme, že řádky jsou číslovány od jedničky)
            var lines = System.IO.File.ReadAllLines(fileName);

            if (lines.Length < lineIndex)
            {
                throw new Exception($"Line {lineIndex+1} in file {fileName} not exists.");
            }

            var command = lines[lineIndex];

            //---

            return(new MessageFromClient
            {
                Command = "CMD",
                Parameters = new List <string> {
                    command
                }
            });
        }
            private bool CMD_reset(MyCommandLine commandLine)
            {
                string name = commandLine.Argument(1);

                if (name == "all")
                {
                    foreach (var x in JobNames)
                    {
                        AverageJobRuntimes[x] = new JobRuntimeInfo();
                    }
                }
                else if (Jobs.ContainsKey(name))
                {
                    AverageJobRuntimes[name] = new JobRuntimeInfo();
                }

                StatsStrings[3].Invalidate();
                StatsStrings[-3].Invalidate();

                return(true);
            }
            private bool CMD_freq(MyCommandLine commandLine)
            {
                int i;

                if (commandLine.ArgumentCount > 1 && int.TryParse(commandLine.Argument(1), out i))
                {
                    TrySetInterval(i);
                }
                else if (commandLine.ArgumentCount > 2 && int.TryParse(commandLine.Argument(2), out i))
                {
                    if (commandLine.Argument(1) == "all")
                    {
                        TrySetInterval(i);
                    }
                    else
                    {
                        TrySetInterval(i, commandLine.Argument(1));
                    }
                }
                return(true);
            }
Esempio n. 30
0
        private static MessageFromClient GetCmdMessage(MyCommandLine cmdLine)
        {
            if (!cmdLine.Exists(PAR_CMD_COMMAND))
            {
                return(null);
            }

            var command = cmdLine.Value(PAR_CMD_COMMAND);

            if (string.IsNullOrEmpty(command))
            {
                throw new Exception("Command not specified.");
            }

            return(new MessageFromClient
            {
                Command = "CMD",
                Parameters = new List <string> {
                    command
                }
            });
        }