示例#1
0
        public bool CheckOutput(OutputCollectingReader r)
        {
            bool outputComplete = false;

            if (r.state == OutputState.Executing)
            {
                int startIndex = r.textReceived.IndexOf(Networking.StartToken + "\r");

                if (startIndex != -1)
                {
                    // skip past the start token and the "\r" that should be after it
                    r.textReceived = r.textReceived.Substring(startIndex + Networking.StartToken.Length + 2);
                    r.state        = OutputState.Busy;
                }
            }

            if (r.state == OutputState.Busy)
            {
                int endIndex = r.textReceived.IndexOf(Networking.EndToken);

                if (endIndex != -1)
                {
                    // remove the end token and everything after it
                    r.textReceived = r.textReceived.Substring(0, endIndex);
                    r.state        = OutputState.Finished;
                }
            }

            // if we're ready to finish, send the received text back to whoever
            // supplied the callback function
            if (r.state == OutputState.Finished && !r.finished)
            {
                if (r.textReceived != "")
                {
                    lock (_locker)
                    {
                        sb.Clear();

                        byte[] bytes = Encoding.UTF8.GetBytes(r.textReceived);
                        vt.Input(bytes);

                        r.finalOutput = sb.ToString();
                    }

                    if (r.callback != null)
                    {
                        FireAndForgetMethods.FireAndForget <string>(r.callback, r.finalOutput);

                        //r.callback(r.finalOutput);
                    }
                }

                r.finished = true;

                m_readers.Remove(r);
                outputComplete = true;
            }

            return(outputComplete);
        }
示例#2
0
        public void ExecuteRemoteCommand(string command, Action <string> callback)
        {
            OutputCollectingReader r = new OutputCollectingReader();

            r.callback = callback;

            m_outputParser.AddReader(r);

            SSHChannel chan = StartShell(r);

            r.chan = chan;

            // TODO This whole function probably ought to spin off a new thread or something
            while (!r._ready)
            {
                Thread.Sleep(50);
            }

            //chan.Transmit("bash");

            string formattedCommand = string.Format("echo {0}; {1}; echo {2};exit;\r", StartToken, command, EndToken);

            chan.Transmit(formattedCommand);
        }
示例#3
0
 public void AddReader(OutputCollectingReader r)
 {
     m_readers.Add(r);
 }