Beispiel #1
0
        public static void Main(string[] args)         //ip, port
        {
            data = new CommonData(String.Format("ws://{0}:{1}", args[0], args[1]));
            //data = new CommonData(String.Format("ws://{0}:{1}", "127.0.0.1", "20146"));
            mainThread = Thread.CurrentThread;

            ConfigMainCommands();

            data.server.onClose += (IRRClient mainclient) => {            //при падении сервера програма завершает работу
                if (data.execute)
                {
                    Console.WriteLine("server is droped");
                    cmdArray.Execute("exit", null);
                    mainThread.Abort();
                }
            };

            //cmd [ARGS] [OPTIONS]
            try
            {
                while (data.execute)
                {
                    Console.WriteLine("Enter command use cmd [ARGS] [OPTIONS]");
                    string      cmd = Console.ReadLine();
                    CommandData splited;
                    try {
                        splited = new CommandData(cmd);
                    }
                    catch (BadInputException) {
                        Console.WriteLine("Bad input");
                        continue;
                    }

                    try {
                        cmdArray.Execute(splited.Cmd, splited);
                    }
                    catch (Exception err) {
                        Console.WriteLine(err);
                    }
                }
            }
            catch (ThreadAbortException err) {
            }
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            config       = readConfig(CONFIG_PATH);
            commandBank  = configureCommands();
            webSearchers = createSearchers();

            Console.OutputEncoding = Encoding.UTF8;

            while (execute)
            {
                Console.WriteLine("Enter command");
                string      cmd     = Console.ReadLine();
                CommandData cmdData = new CommandData(cmd);
                try
                {
                    commandBank.Execute(cmdData.Cmd, cmdData);
                }
                catch (Exception err)
                {
                    Console.WriteLine(err);
                }
            }
        }
Beispiel #3
0
        /*
         * создание сервера принимающего команды с управляющего сервера
         */
        static RRServer ConfigureServer()
        {
            //requ	{cmd, data: {}}
            //resp	{ok: {message}}
            //error	{error: {message}}

            RRServer server = new RRServer(String.Format("ws://0.0.0.0:{0}", config["serverPort"].GetValue <UInt16>()));

            server.onMessage += (string arg1, IRRClient arg2) => {
                JSONParser inputData = null;
                try {
                    inputData = new JSONParser(arg1);
                }
                catch (Exception err) {
                    arg2.SendMessageAsync("{\"error\": {\"message\": \"bad JSON data\"}}");
                    return;
                }
                Console.WriteLine(inputData.ToJSON());

                commands.Execute(inputData["cmd"].GetValue <string>(), new ClientData(arg2, new JSONParser(inputData["data"])));
            };

            return(server);
        }
Beispiel #4
0
        /*
         * создание websocket сервера
         * решающего какая команда будет выполнена
         */
        private static void ConfigureRRServer()
        {
            //requ	{cmd, data: {}}
            //resp	{ok: {message}}
            //error	{error: {message}}
            server = new RRServer(String.Format("ws://0.0.0.0:{0}", config["server_port"].GetValue <UInt16>()));
            server.onServerError += (Exception err) => {
                Console.WriteLine("Server error: {0}", err);
            };
            server.onMessage += (string arg1, IRRClient arg2) =>
            {
                Console.WriteLine("server: input data {0}", arg1);
                JSONParser inputData = null;
                try {
                    inputData = new JSONParser(arg1);
                }
                catch (Exception err) {
                    arg2.SendMessageAsync("{\"error\": {\"message\": \"bad JSON data\"}}");
                    return;
                }


                try {
                    commands.Execute(inputData["cmd"].GetValue <string>(), new ClientData(arg2, new JSONParser(inputData["data"])));
                }
                catch (Exception err) {
                    arg2.SendMessageAsync(new PartStruct()
                                          .Add("error", new PartStruct()
                                               .Add("message", err.Message)
                                               ).ToJSON());
                }
            };
            server.onOpen += (IRRClient obj) => {
                Console.WriteLine("connected ip: {0}, port {1}", obj.address, obj.port);
            };
        }