예제 #1
0
        private static void Main(string[] args)
        {
            // Load embedded DLLs
            AppDomain.CurrentDomain.AssemblyResolve += LoadDll;

            _connector = new JsonApiConnector(args);
            _connector.OutputReceived += TextReceived;

            Thread t;

            if (_connector.ShowConsole)
            {
                t = new Thread(ScanInput)
                {
                    Name = "thd_ScanInput", IsBackground = true
                };
                t.Start();
            }
            else
            {
                t = new Thread(ScanStdIn)
                {
                    Name = "thd_ScanStdIn", IsBackground = true
                };
                t.Start();
            }
            _connector.Connect();
            while (_connector.Api.IsListening())
            {
                Thread.Sleep(10);
            }
        }
예제 #2
0
        private static void Main(string[] args)
        {
            // Load embedded DLLs
            AppDomain.CurrentDomain.AssemblyResolve += LoadDll;

            _connector = new JsonApiConnector(args);
            _connector.OutputReceived += TextReceived;

            Thread t;
            if (_connector.ShowConsole)
            {
                t = new Thread(ScanInput) {Name = "thd_ScanInput", IsBackground = true};
                t.Start();
            }
            else
            {
                t = new Thread(ScanStdIn) {Name = "thd_ScanStdIn", IsBackground = true};
                t.Start();
            }
            _connector.Connect();
            while (_connector.Api.IsListening())
            {
                Thread.Sleep(10);
            }
        }
예제 #3
0
 public JsonApiConnector(string[] args)
 {
     //Arguments:
     // -u=username
     // -p=password
     // -s=salt (if necessary)
     // -host=[ip or hostname]
     // -port=20060
     // -api=1 (to use old api, default is v2)
     _reference = this;
     LoadArguments(args);
 }
예제 #4
0
 public JsonApiConnector(string[] args)
 {
     //Arguments:
     // -u=username
     // -p=password
     // -s=salt (if necessary)
     // -host=[ip or hostname]
     // -port=20060
     // -api=1 (to use old api, default is v2)
     _reference = this;
     LoadArguments(args);
 }
예제 #5
0
        public void ReadConsoleStream()
        {
            JsonApiConnector.HandleOutput(LogPrefix + "Connecting to the external server...");
            Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            try
            {
                sock.Connect(_host, _port + 1);
            }
            catch (Exception connectException)
            {
                JsonApiConnector.HandleOutput(ErrPrefix + "Couldn't connect to JsonApi stream:" +
                                              connectException.Message);
            }

            if (sock.Connected)
            {
                NetworkStream stream  = new NetworkStream(sock);
                StreamWriter  sw      = new StreamWriter(stream);
                string        request = "/api/2/subscribe?json=" + CreateJsonPayload("console", null, true);
                sw.WriteLine(request);
                sw.Flush();
                StreamReader sr = new StreamReader(stream);
                JsonApiConnector.HandleOutput(LogPrefix + "Connected!");

                while (_listening && sock.Connected && stream.CanRead)
                {
                    string l = "";
                    try
                    {
                        while (_listening && sock.Connected && stream.CanRead && sr.EndOfStream)
                        {
                            Thread.Sleep(100);
                        }
                        if (_listening && sock.Connected)
                        {
                            l = sr.ReadLine();
                        }
                    }
                    catch (Exception readex)
                    {
                        Debug.WriteLine("exception at run_connection_receive, while reading from networkstream " +
                                        readex.Message);
                        //don't flag as critical error
                    }

                    if (!string.IsNullOrEmpty(l) && l.Contains("{") & l.Contains(":") & l.Contains("}"))
                    {
                        l = new JsonApiStreamResult(l).Line;
                        if (!_filter ||
                            !Regex.IsMatch(l,
                                           "^[^\\]]*\\](:|\\s){0,2}\\[JSONAPI\\]\\s?\\[(api|stream) (call|request)\\]",
                                           RegexOptions.IgnoreCase))
                        {
                            JsonApiConnector.HandleOutput(l.TrimEnd(Environment.NewLine.ToCharArray()));
                        }
                    }

                    Thread.Sleep(10);
                }
            }
            JsonApiConnector.HandleOutput(LogPrefix + "Disconnected");
            if (sock.Connected)
            {
                sock.Close();
            }
            _listening = false;
        }