Exemple #1
0
        private void Process(string msg)
        {
            if (s != null)
            {
                response = msg;
                s.Set();
                return; //Intercepterd by running process
                //TODO: introduce read queue later?
            }

            var args = msg.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
            var key  = args[0];

            if (CliCommands.ContainsKey(key))
            {
                var handler = CliCommands[key];
                handler.Action(args);
            }
            else if (CliAliases.ContainsKey(key))
            {
                var handler = CliCommands[CliAliases[key]];
                handler.Action(args);
            }
            else
            {
                LogProblem("No Such Command");
            }
        }
Exemple #2
0
        /// <summary>
        /// Defines the entry point of this application.
        /// </summary>
        /// <param name="Arguments">The CLI arguments.</param>
        private static async Task Main(string[] Arguments)
        {
            var EngineConfig = new BekoConfig
            {
                Process         = Process.GetCurrentProcess(),
                MemoryHandler   = new NativeMemoryHandler(),
                RequestsHandler = new NativeRequestsHandler()
            };

            // ..

            try
            {
                Engine = BekoEngine.FromConfiguration(EngineConfig);
            }
            catch (Exception Exception)
            {
                Console.WriteLine("[*] " + Exception.Message.Split('\n')[0]);
            }

            // ..

            if (Engine != null)
            {
                if (Arguments.Length == 0)
                {
                    HelpCommand.Execute(null);
                }

                Console.Write("[*] > ");

                using (Engine)
                {
                    while (true)
                    {
                        var Command = Console.ReadLine();

                        if (!string.IsNullOrEmpty(Command))
                        {
                            if (Command == "dispose" || Command == "exit" || Command == "quit")
                            {
                                break;
                            }

                            CliCommands.TryExecute(Command.Split(' '));
                        }

                        Console.Write("[*] > ");
                    }
                }
            }
            else
            {
                Console.WriteLine("[*] The engine failed to initialize.");
            }

            await Task.Delay(500);
        }
Exemple #3
0
        public UnityTerminalFrontend()
        {
            var modules = typeof(CliModule).FindImplementations();

            foreach (var module in modules)
            {
                var pluginInstance = Activator.CreateInstance(module, this) as CliModule;

                Plugins.Add(pluginInstance);

                var methods = module.GetMethods().Where(m => m.IsDefined(typeof(CliCommand), true));

                foreach (var methodInfo in methods)
                {
                    var c    = methodInfo.GetCustomAttributes(typeof(CliCommand), true).FirstOrDefault() as CliCommand;
                    var info = methodInfo;

                    Action <string[]> handler = str =>
                    {
                        info.Invoke(pluginInstance, new object[] { str });
                    };

                    CliCommands.Add(c.Code, new TerminalServerCommand()
                    {
                        Action      = handler,
                        CommandCode = c.Code,
                        Help        = c.Help
                    });

                    var aliases = methodInfo.GetCustomAttributes(typeof(CliAlias), true).Cast <CliAlias>();

                    foreach (var alias in aliases)
                    {
                        CliAliases.Add(alias.Code, c.Code);
                    }
                }
            }



            Log("Hello, I am Koinonia!");
            Log("Type \"help\" or \"h\" for a list of available commands.");
            Log("");
            Log("");
        }