Exemple #1
0
        private void TerminalKeyDown(object sender, KeyRoutedEventArgs e)
        {
            if (!Connected)
            {
                return;
            }

            var controlPressed = (Window.Current.CoreWindow.GetKeyState(Windows.System.VirtualKey.Control).HasFlag(CoreVirtualKeyStates.Down));
            var shiftPressed   = (Window.Current.CoreWindow.GetKeyState(Windows.System.VirtualKey.Shift).HasFlag(CoreVirtualKeyStates.Down));

            switch (e.Key)
            {
            case Windows.System.VirtualKey.Shift:
            case Windows.System.VirtualKey.Control:
                return;

            default:
                break;
            }

            if (controlPressed && e.Key == Windows.System.VirtualKey.F12)
            {
                Terminal.Debugging = !Terminal.Debugging;
            }

            if (controlPressed && e.Key == Windows.System.VirtualKey.F10)
            {
                Consumer.SequenceDebugging = !Consumer.SequenceDebugging;
            }

            if (controlPressed && e.Key == Windows.System.VirtualKey.F11)
            {
                ViewDebugging = !ViewDebugging;
                canvas.Invalidate();
            }

            var code = Terminal.GetKeySequence((controlPressed ? "Ctrl+" : "") + (shiftPressed ? "Shift+" : "") + e.Key.ToString());

            if (code != null)
            {
                Task.Run(() =>
                {
                    _stream.Write(code, 0, code.Length);
                    _stream.Flush();
                });

                e.Handled = true;

                if (ViewTop != Terminal.ViewPort.TopRow)
                {
                    Terminal.ViewPort.SetTopLine(ViewTop);
                    canvas.Invalidate();
                }
            }

            //System.Diagnostics.Debug.WriteLine(e.Key.ToString() + ",S" + (shiftPressed ? "1" : "0") + ",C" + (controlPressed ? "1" : "0"));
        }
Exemple #2
0
        private void button3_Click(object sender, EventArgs e)
        {
            aTimer          = new System.Windows.Forms.Timer();
            aTimer.Interval = 5000;
            aTimer.Tick    += new EventHandler(timer_tick);
            aTimer.Start();

            Monitering_sShell.Write("cat /proc/meminfo | grep MemTotal \n");
            Monitering_sShell.Flush();
        }
Exemple #3
0
 /// <summary>
 /// Send data to ssh client
 /// </summary>
 /// <param name="byteData"></param>
 private static void SendSSHClientData(byte[] byteData)
 {
     try
     {
         shellStream.Write(byteData, 0, byteData.Length);
         shellStream.Flush();
     }
     catch (Exception e)
     {
         pipeMessaging.ClosePipes();
         DisconnectSSHClient();
     }
 }
Exemple #4
0
 /// <summary>
 /// Send data to ssh client
 /// </summary>
 /// <param name="byteData"></param>
 private static void SendSSHClientData(byte[] byteData)
 {
     try
     {
         shellStream.Write(byteData, 0, byteData.Length);
         shellStream.Flush();
     }
     catch (Exception e)
     {
         Trace.TraceError("Failed to send data to ssh client, remote session {0} ({1})", RemoteSessionID, e);
         throw;
     }
 }
Exemple #5
0
 private void textBox6_KeyPress(object sender, KeyPressEventArgs e)
 {
     try
     {
         if (e.KeyChar == 13)
         {
             Command_sShell.Write(textBox6.Text + "\n");
             Command_sShell.Flush();
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         Console.WriteLine(ex.StackTrace);
     }
 }
Exemple #6
0
        public string WriteLine(string command)
        {
            _sshStream.Flush();
            _sshStream.WriteLine(command);


            StringBuilder output = new StringBuilder();

            string line;

            while (!_sshStream.DataAvailable)
            {
                System.Threading.Thread.Sleep(200);
            }

//            System.Threading.Thread.Sleep(200);
            var num = 0;

            while (_sshStream.DataAvailable)
            {
                if (num > 1)
                {
                    output.Append('\n');
                }
                line = _sshStream.ReadLine();
                output.Append(line);
                num++;
            }


            return(output.ToString());
        }
Exemple #7
0
 /// <summary>
 /// Sends text to the server
 /// </summary>
 /// <param name="text"></param>
 public void SendText(string text)
 {
     try
     {
         if (Client != null)
         {
             TheStream.Write(text);
             TheStream.Flush();
         }
     }
     catch
     {
         Debug.Console(1, this, "Stream write failed. Disconnected, closing");
         ClientStatus = SocketStatus.SOCKET_STATUS_BROKEN_REMOTELY;
         HandleConnectionFailure();
     }
 }
Exemple #8
0
        public void FlushShouldSendBufferToServer()
        {
            _channelSessionMock.InSequence(_mockSequence)
            .Setup(p => p.SendData(_bufferData));

            _shellStream.Flush();

            _channelSessionMock.Verify(p => p.SendData(_bufferData), Times.Once);
        }
        public void ShellSend(Gdk.Key key)
        {
            if (UserInputMode)
            {
                LastKeyPress = key;
                userkeypress.Set();
            }
            else
            {
                if (LocalEcho)
                {
                    Write(key.ToString());
                }
                if (shellStream != null && shellStream.CanWrite)
                {
                    byte[] charBytes = null;

                    switch (key)
                    {
                    case Gdk.Key.Shift_L:
                    case Gdk.Key.Shift_R:
                    case Gdk.Key.ISO_Level3_Shift:     //Alt Gr
                        //Ignore
                        break;

                    case Gdk.Key.Return:
                    case Gdk.Key.KP_Enter:
                        charBytes = Encoding.UTF8.GetBytes(Environment.NewLine);
                        break;

                    case Gdk.Key.BackSpace:
                        charBytes = new byte[] { (byte)'\b' };
                        break;

                    case Gdk.Key.KP_Tab:
                    case Gdk.Key.Tab:
                        charBytes = new byte[] { (byte)'\t' };
                        break;

                    case Gdk.Key.Escape:
                        charBytes = new byte[] { 0x1B };     //ESC
                        break;

                    default:
                        charBytes = Encoding.UTF8.GetBytes(new char[] { key.GetChar() });
                        break;
                    }

                    if (charBytes != null)
                    {
                        shellStream.Write(charBytes, 0, charBytes.Length);
                        shellStream.Flush();
                    }
                }
            }
        }
Exemple #10
0
        public void FlushShouldSendRemaningBytesToServer()
        {
            var expectedBytesSent = _data.Take(_bufferSize * 2, _data.Length - _bufferSize * 2);

            _channelSessionMock.InSequence(_mockSequence)
            .Setup(p => p.SendData(expectedBytesSent));

            _shellStream.Flush();

            _channelSessionMock.Verify(p => p.SendData(expectedBytesSent), Times.Once);
        }
Exemple #11
0
        public String expect(String cmd, int t)
        {
            String retval = "";

            try
            {
                stream.Write(cmd + "\r");
                stream.Flush();
                Thread.Sleep(t);
                retval = stream.Expect(reg_prompt, waitTime);
                stream.Flush();
                while (stream.DataAvailable == true)
                {
                    retval += stream.Read();
                }
                return(retval);
            }
            catch (System.Exception e)
            {
                return(retval + "\n" + "err: " + e.ToString());
            }
        }
        /// <summary>
        /// Sends text to the server
        /// </summary>
        /// <param name="text"></param>
        public void SendText(string text)
        {
            try
            {
                if (Client != null)
                {
                    if (StreamDebugging.TxStreamDebuggingIsEnabled)
                    {
                        Debug.Console(0, this, "Sending {0} characters of text: '{1}'", text.Length, text);
                    }

                    TheStream.Write(text);
                    TheStream.Flush();
                }
            }
            catch
            {
                Debug.Console(1, this, "Stream write failed. Disconnected, closing");
                ClientStatus = SocketStatus.SOCKET_STATUS_BROKEN_REMOTELY;
                HandleConnectionFailure();
            }
        }
        /// <summary>
        /// Runs pre and post deployment commands over the SSH client.
        /// </summary>
        /// <param name="shellStream">The shell stream.</param>
        /// <param name="verbOptions">The verb options.</param>
        private static void RunShellStreamCommand(ShellStream shellStream, CliExecuteOptionsBase verbOptions)
        {
            var commandText = verbOptions.PostCommand;

            if (string.IsNullOrWhiteSpace(commandText))
            {
                return;
            }

            Terminal.WriteLine("    Executing shell command.", ConsoleColor.Green);
            shellStream.Write($"{commandText}\r\n");
            shellStream.Flush();
            Terminal.WriteLine($"    TX: {commandText}", ConsoleColor.DarkYellow);
        }
Exemple #14
0
        /// <summary>
        /// Runs pre and post deployment commands over the SSH client
        /// </summary>
        /// <param name="sshClient">The SSH client.</param>
        /// <param name="commandText">The command text.</param>
        private static void RunShellStreamCommand(ShellStream shellStream, MonitorVerbOptions verbOptions)
        {
            var commandText = verbOptions.PostCommand;

            if (string.IsNullOrWhiteSpace(commandText) == true)
            {
                return;
            }

            ConsoleManager.WriteLine("    Executing shell command.", ConsoleColor.Green);
            shellStream.WriteLine(commandText);
            shellStream.Flush();
            ConsoleManager.WriteLine("    TX: " + commandText, ConsoleColor.DarkYellow);
        }
Exemple #15
0
        protected override bool RunSSHAction(SshClient ssh)
        {
            IDictionary <TerminalModes, uint> termkvp = new Dictionary <TerminalModes, uint>();

            termkvp.Add(TerminalModes.ECHO, 53);

            using (Process pr = Process.Start(new ProcessStartInfo()
            {
                Arguments = Arguments == null ? "" : Arguments,
                CreateNoWindow = true,
                RedirectStandardInput = true,
                RedirectStandardOutput = true,
                WindowStyle = ProcessWindowStyle.Hidden,
                UseShellExecute = false,
            }))
            {
                ShellStream cmd = null;
                try
                {
                    cmd = ssh.CreateShellStream("xterm", 100, 60, 1000, 600, 4096, termkvp);

                    // Read from SSH
                    cmd.DataReceived += (object sender, ShellDataEventArgs e) =>
                    {
                        string line = Encoding.UTF8.GetString(e.Data);
                        WriteInfo("> " + line);

                        pr.StandardInput.WriteLine(line);
                        pr.StandardInput.Flush();
                    };
                }
                catch { }

                while (!pr.HasExited && !ssh.IsConnected)
                {
                    // Read from program
                    string line = pr.StandardOutput.ReadLine();
                    WriteInfo("< " + line);

                    cmd.WriteLine(line);
                    cmd.Flush();

                    Thread.Sleep(10);
                }

                pr.WaitForExit();
            }

            return(true);
        }
        public void FlushShouldSendWrittenBytesToServer()
        {
            byte[] bytesSent = null;

            _channelSessionMock.InSequence(_mockSequence)
            .Setup(p => p.SendData(It.IsAny <byte[]>()))
            .Callback <byte[]>(data => bytesSent = data);

            _shellStream.Flush();

            Assert.IsNotNull(bytesSent);
            Assert.IsTrue(_data.Take(_offset, _count).IsEqualTo(bytesSent));

            _channelSessionMock.Verify(p => p.SendData(It.IsAny <byte[]>()), Times.Once);
        }
Exemple #17
0
        private string _SendCommand(string ip, string id, string password, string command)
        {
            string ret = "";

            Console.WriteLine("\n[ start ]");
            try
            {
                // 연결 체크
                if ((CommandView.current.sshclient == null || !CommandView.current.sshclient.IsConnected) ||
                    (CommandView.current.sshclient.ConnectionInfo.Host != ip ||
                     CommandView.current.sshclient.ConnectionInfo.Port != PORT ||
                     CommandView.current.sshclient.ConnectionInfo.Username != id))
                {
                    if (CommandView.current.sshclient != null && CommandView.current.sshclient.IsConnected)
                    {
                        CommandView.current.sshclient.Disconnect();
                    }

                    CommandView.current.sshclient = new SshClient(ip, PORT, id, password);
                    CommandView.current.sshclient.Connect();
                    shell_stream = sshclient.CreateShellStream("customCommand", 80, 24, 800, 600, 1024);
                    timer_read.Start();

                    Console.Write("[ ReConnection ] ");
                    Console.WriteLine(CommandView.current.sshclient.ConnectionInfo.Host + " / " + CommandView.current.sshclient.ConnectionInfo.Port + " / " + CommandView.current.sshclient.ConnectionInfo.Username + " / " + CommandView.current.sshclient.ConnectionInfo.ProxyUsername + " / " + CommandView.current.sshclient.ConnectionInfo.ProxyPassword);
                }
                // send
                if (shell_stream != null)
                {
                    shell_stream.Write(command);
                    shell_stream.Write("\n");
                    shell_stream.Flush();
                    //textBox_result.Text += read2();
                }
            }
            catch (Exception ex)
            {
                ret = "Error = " + ex.Message;
                Console.WriteLine(ex.Message);
            }
            Console.WriteLine("[ finish ]\n");

            if (command == "exit")
            {
                CommandView.current.sshclient.Disconnect();
            }
            return(ret);
        }
Exemple #18
0
        public Stream(SshClient ssh)
        {
            _sshClient = ssh;
            _sshClient.Connect();

            _sshStream = _sshClient.CreateShellStream("xterm", 80, 50, 1024, 1024, 1024);

            while (!_sshStream.DataAvailable)
            {
                System.Threading.Thread.Sleep(200);
            }

            var line = _sshStream.Read();

            _sshStream.Flush();
        }
Exemple #19
0
        //private void btnTelnetConnect_Click(object sender, EventArgs e)
        //{
        //	try
        //	{
        //		TcpClient oClient = new TcpClient("192.168.100.254", 6000);
        //		//l_TelnetState.Text = oClient.Connected.ToString();
        //		if(oClient.Connected)
        //		{
        //			NetworkStream ns = new NetworkStream(oClient.GetStream());
        //			read(ns).ToString();//처음읽으면 이상한값이... 나온다.. 어째서일까..
        //			read(ns).ToString();//로그인 입력하라는 메세지가 읽어진다.
        //			write(ns, "admin");//아이디입력
        //			read(ns).ToString();//아이디 기록 되는지 확인
        //			write(ns, "admin");//암호입력
        //			read(ns).ToString();//비번 기록 되는지 확인
        //			string pc = read(ns);//접속되었는지 확인
        //			pc = pc.Substring(pc.Length - 2, 1);
        //			if(pc == "#") //내가 한 기계에 연결결과 로그인하고 나면 맨 마지막 커맨드에 #이붙어
        //						  //서 이것을 기준으로 접속 되는지 안되는지 확인함. 접속하는것 마다 다
        //						  //를거라고 생각함.
        //			{
        //				l_TelnetState.ForeColor = Color.Green;
        //				l_TelnetState.Text = "연결됨";
        //			}
        //			else
        //			{
        //				l_TelnetState.ForeColor = Color.Red;
        //				l_TelnetState.Text = "연결안됨";
        //			}
        //			ns.Close();
        //			oClient.Close();
        //		}
        //		else
        //		{
        //			l_TelnetState.ForeColor = Color.Red;
        //			l_TelnetState.Text = "연결안됨";
        //		}
        //	}
        //	catch(Exception)
        //	{
        //		l_TelnetState.ForeColor = Color.Red;
        //		l_TelnetState.Text = "연결안됨";
        //		if(oClient.Connected)
        //			oClient.Close();
        //	}
        //}

        //private string read(NetworkStream ns)
        //{
        //	StringBuilder sb = new StringBuilder();

        //	if(ns.CanRead)
        //	{

        //		byte[] readBuffer = new byte[1024];

        //		int numBytesRead = 0;

        //		do
        //		{
        //			numBytesRead = ns.Read(readBuffer, 0, readBuffer.Length);
        //			sb.AppendFormat(
        //			"{0}", Encoding.ASCII.GetString(readBuffer, 0, numBytesRead));
        //			sb.Replace(
        //			Convert.ToChar(24), ' ');
        //			sb.Replace(
        //			Convert.ToChar(255), ' ');
        //			sb.Replace(
        //			'?', ' ');
        //		}

        //		while(ns.DataAvailable);
        //	}

        //	return sb.ToString();
        //}

        //private void write(NetworkStream ns, string message)
        //{

        //	byte[] msg = Encoding.ASCII.GetBytes(message + Environment.NewLine);
        //	ns.Write(msg, 0, msg.Length);
        //}



        private static string SendCommand(ShellStream stream, string customCMD)
        {
            StringBuilder strAnswer = new StringBuilder();

            var reader = new StreamReader(stream);
            var writer = new StreamWriter(stream);

            //writer.AutoFlush = true;
            WriteStream(customCMD, writer, stream);

            strAnswer.AppendLine(ReadStream(reader));
            stream.Flush();

            string answer = strAnswer.ToString();

            return(answer);
        }
        public void FlushShouldSendRemainingBytesInBufferToServer()
        {
            var expectedBytesSent = _data.Take(_bufferSize - _bufferData.Length, _data.Length + _bufferData.Length - _bufferSize);

            byte[] actualBytesSent = null;

            _channelSessionMock.InSequence(_mockSequence)
            .Setup(p => p.SendData(It.IsAny <byte[]>()))
            .Callback <byte[]>(data => actualBytesSent = data);

            _shellStream.Flush();

            Assert.IsNotNull(actualBytesSent);
            Assert.AreEqual(expectedBytesSent.Length, actualBytesSent.Length);
            Assert.IsTrue(expectedBytesSent.IsEqualTo(actualBytesSent));

            _channelSessionMock.Verify(p => p.SendData(It.IsAny <byte[]>()), Times.Exactly(2));
        }
 public void ShellSend(Gdk.Key key)
 {
     if (UserInputMode)
     {
         LastKeyPress = key;
         userkeypress.Set();
     }
     else
     {
         if (LocalEcho)
         {
             Write(key.ToString());
         }
         if (shellStream != null && shellStream.CanWrite)
         {
             shellStream.WriteByte((byte)key);
             shellStream.Flush();
         }
     }
 }
Exemple #22
0
        private void Tomcat_LogCommad()
        {
            if (cSSH_TomCat_Log1.IsConnected)
            {
                Tomcat_Log_sShell1.Write("tail -f " + textBox7.Text + listBox1.Items[1].ToString() + "/logs/catalina.out \n");
                Tomcat_Log_sShell1.Flush();
            }

            if (cSSH_TomCat_Log2.IsConnected)
            {
                Tomcat_Log_sShell2.Write("tail -f " + textBox7.Text + listBox1.Items[2].ToString() + "/logs/catalina.out \n");
                Tomcat_Log_sShell2.Flush();
            }

            if (cSSH_TomCat_Log3.IsConnected)
            {
                Tomcat_Log_sShell3.Write("tail -f " + textBox7.Text + listBox1.Items[3].ToString() + "/logs/catalina.out \n");
                Tomcat_Log_sShell3.Flush();
            }
        }
Exemple #23
0
        private static void sendCommand(string command)
        {
            //BackgroundReConnector.RunWorkerAsync();
            LinuxTreeViewItem.ReConnect();

            try
            {
                // send
                if (shell_stream != null)
                {
                    shell_stream.Write(command);
                    shell_stream.Write("\n");
                    shell_stream.Flush();
                    Log.Print(command, "send command" /*, Home.m_wnd.richTextBox_status*/);
                }
            }
            catch (Exception ex)
            {
                Log.PrintError(ex.Message, "send command", Home.m_wnd.richTextBox_status);
            }
        }
Exemple #24
0
        private void TextBox_input_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key != Key.Enter)
            {
                return;
            }


            //var x = client.RunCommand(textBox_input.Text);
            //Console.WriteLine(x.Result);
            //textBox_result.Text += SendCommand(stream, textBox_input.Text);
            if (sshClient.IsConnected)
            {
                stream.Write(textBox_input.Text);
                stream.Write("\n");
                stream.Flush();
                string str = read();
                textBox_result.Text += str;
                //string str;
                //while((str = stream.ReadLine()) != null)
                //{
                //	Console.WriteLine("read" + str);
                //}
            }
            //input.Write(textBox_input.Text);
            //input.Flush();

            //if(input != null)
            //	Console.WriteLine("input = " + input.Read());
            //if(output != null)
            //	Console.WriteLine("output = " + output.Read());
            //if(exoutput != null)
            //	Console.WriteLine("exoutput = " + exoutput.Read());

            //textBox_input.Text = "";
            //textBox_result.Text += "result\n" + output.Read() + "\n";


            textBox_input.Text = "";
        }
Exemple #25
0
        private static void sendCommand(string command)
        {
            //LinuxTreeViewItem.ReconnectServer();
            //LinuxTreeViewItem.ReConnect();
            LinuxTreeViewItem.ReConnect(1000);

            try
            {
                // send
                if (shell_stream != null)
                {
                    shell_stream.Write(command);
                    shell_stream.Write("\n");
                    shell_stream.Flush();
                    Log.Print(command, "send command" /*, test4.m_wnd.richTextBox_status*/);
                }
            }
            catch (Exception ex)
            {
                Log.PrintError(ex.Message, "send command", WindowMain.m_wnd.richTextBox_status);
            }
        }
Exemple #26
0
        private string ExecuteCommandUsingShellStream(ShellStream shell, string Command)
        {
            string       cmdResult = string.Empty;
            StreamReader reader    = new StreamReader(shell);

            shell.Flush();
            cmdResult = string.Empty;
            ExInfo   += ", Sending Command: " + Command;
            shell.Write(Command + "\n");
            cmdResult = reader.ReadToEnd();
            int   iCount = 1;
            Regex regExp = new Regex(@"ENTER ...|continue ...|option :|\> |\$ |\%");

            while (regExp.Matches(cmdResult.ToString()).Count == 0 && iCount < 20)
            {
                cmdResult += reader.ReadToEnd();

                cmdResult = Regex.Replace(cmdResult, @"[\u001b]\[[0-9]+m", "");
                Thread.Sleep(1000);
                iCount++;
            }
            return(cmdResult);
        }
Exemple #27
0
        /// <summary>
        /// Wrtites a msg to the SSH stream
        /// </summary>
        /// <param name="msg">msg to send</param>
        /// <returns></returns>
        public uint Send(RSProtoBuffSSHMsg msg)
        {
            System.Diagnostics.Debug.WriteLineIf(DEBUG, "send: sending packet " + msg.ReqID + " MsgID: " + msg.MsgID + " body size: " + msg.BodySize);
            if (_stream.CanWrite)
            {
                try
                {
                    _stream.Write(CreatePacketFromMsg(msg), 0, 16 + (int)msg.BodySize);
                    _stream.Flush();
                }
                catch (Exception e)
                {
                    _parent.Error(e, RSRPC.ErrorFrom.ProtoBuf);
                }
            }
            else
            {
                System.Diagnostics.Debug.WriteLine("send: can't write stream");
                _parent.Error(new IOException("send: can't write stream"), RSRPC.ErrorFrom.ProtoBuf);
            }

            return(msg.ReqID);
        }
Exemple #28
0
        public void FlushShouldSendNoBytesToServer()
        {
            _shellStream.Flush();

            _channelSessionMock.Verify(p => p.SendData(It.IsAny <byte[]>()), Times.Never);
        }
        /// <summary>
        /// Starts the user interaction.
        /// </summary>
        /// <param name="sshClient">The SSH client.</param>
        /// <param name="sftpClient">The SFTP client.</param>
        /// <param name="shellStream">The shell stream.</param>
        /// <param name="verbOptions">The verb options.</param>
        private static void StartUserInteraction(
            SshClient sshClient,
            SftpClient sftpClient,
            ShellStream shellStream,
            MonitorVerbOptions verbOptions)
        {
            _forwardShellStreamInput = false;

            while (true)
            {
                var readKey = Console.ReadKey(true);

                if (readKey.Key == ConsoleKey.F1)
                {
                    _forwardShellStreamInput = !_forwardShellStreamInput;
                    if (_forwardShellStreamInput)
                    {
                        Program.Title = "Monitor (Interactive)";
                        Terminal.WriteLine("    >> Entered console input forwarding.", ConsoleColor.Green);
                        _forwardShellStreamOutput = true;
                    }
                    else
                    {
                        Program.Title = "Monitor (Press H for Help)";
                        Terminal.WriteLine("    >> Left console input forwarding.", ConsoleColor.Red);
                    }

                    continue;
                }

                if (_forwardShellStreamInput)
                {
                    if (readKey.Key == ConsoleKey.Enter)
                    {
                        shellStream.Write("\r\n");
                    }
                    else
                    {
                        shellStream.WriteByte((byte)readKey.KeyChar);
                    }

                    shellStream.Flush();
                    continue;
                }

                switch (readKey.Key)
                {
                case ConsoleKey.Q:
                    return;

                case ConsoleKey.C:
                    Console.Clear();
                    break;

                case ConsoleKey.N:
                    CreateNewDeployment(sshClient, sftpClient, shellStream, verbOptions);
                    break;

                case ConsoleKey.E:
                    RunSshClientCommand(sshClient, verbOptions);
                    break;

                case ConsoleKey.S:
                    RunShellStreamCommand(shellStream, verbOptions);
                    break;

                case ConsoleKey.H:

                    const ConsoleColor helpColor = ConsoleColor.Cyan;
                    Terminal.WriteLine("Console help", helpColor);
                    Terminal.WriteLine("    H    Prints this screen", helpColor);
                    Terminal.WriteLine("    Q    Quits this application", helpColor);
                    Terminal.WriteLine("    C    Clears the screen", helpColor);
                    Terminal.WriteLine("    N    Force a deployment cycle", helpColor);
                    Terminal.WriteLine("    E    Run the Pre-deployment command", helpColor);
                    Terminal.WriteLine("    S    Run the Post-deployment command", helpColor);
                    Terminal.WriteLine("    F1   Toggle shell-interactive mode", helpColor);

                    Terminal.WriteLine();
                    break;

                default:
                    Terminal.WriteLine($"Unrecognized command '{readKey.KeyChar}' -- Press 'H' to get a list of available commands.", ConsoleColor.Red);
                    break;
                }
            }
        }
Exemple #30
0
 public void FlushTest()
 {
     Session session = null; // TODO: Initialize to an appropriate value
     string terminalName = string.Empty; // TODO: Initialize to an appropriate value
     uint columns = 0; // TODO: Initialize to an appropriate value
     uint rows = 0; // TODO: Initialize to an appropriate value
     uint width = 0; // TODO: Initialize to an appropriate value
     uint height = 0; // TODO: Initialize to an appropriate value
     int maxLines = 0; // TODO: Initialize to an appropriate value
     IDictionary<TerminalModes, uint> terminalModeValues = null; // TODO: Initialize to an appropriate value
     ShellStream target = new ShellStream(session, terminalName, columns, rows, width, height, maxLines, terminalModeValues); // TODO: Initialize to an appropriate value
     target.Flush();
     Assert.Inconclusive("A method that does not return a value cannot be verified.");
 }
Exemple #31
0
        public void SSHRunCommand(string command)
        {
            StringBuilder reply = new StringBuilder();

            ss.Flush();
            StreamReader sreader = new StreamReader(ss);

            sreader.ReadToEnd();
            if (command != "\u0003\n")
            {
                while (!sreader.EndOfStream)
                {
                    if (!this.IsDriverRunning)
                    {
                        break;
                    }
                    reply.AppendLine(sreader.ReadLine());
                    Thread.Sleep(1000);
                }
            }
            if (command.StartsWith("CHAR_"))
            {
                command = command.Replace("CHAR_", "").Replace("\n", "");
                try
                {
                    ss.WriteByte(System.Convert.ToByte(Convert.ToInt32(command)));
                }
                catch (Exception ex) { Reporter.ToLog(eLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name}, Error - {ex.Message}", ex); }
            }
            else
            {
                ss.Write(command);
            }
            try
            {
                if (mWait == 0 || mWait == null)
                {
                    mWait = this.ImplicitWait;
                }
                if (mWait == 0)
                {
                    mWait = 30;
                }

                DateTime startingTime = DateTime.Now;
                bool     expOut       = false;
                Regex    regExp;
                mExpString = string.IsNullOrEmpty(mExpString) ? "" : mExpString;
                if (mExpString != "" && command != "\u0003\n")
                {
                    regExp = new Regex(@"~~~GINGER_RC_END~~~|" + mExpString);
                }
                else
                {
                    regExp = new Regex(@"\> |\$ |\% |assword: |\. |~~~GINGER_RC_END~~~");
                }

                while ((DateTime.Now - startingTime).TotalSeconds <= mWait && taskFinished != true)
                {
                    if (!this.IsDriverRunning)
                    {
                        break;
                    }

                    reply.AppendLine(sreader.ReadToEnd());
                    Thread.Sleep(1000);
                    if (regExp.Matches(reply.ToString()).Count > 0)
                    {
                        if (reply.ToString().Contains(command) && expOut == false)
                        {
                            taskFinished = true;
                            expOut       = true;
                        }
                        else
                        {
                            break;
                        }
                    }

                    if (sreader.EndOfStream)
                    {
                        Thread.Sleep(1000);
                        continue;
                    }
                    if ((DateTime.Now - startingTime).TotalSeconds >= mWait)
                    {
                        taskFinished = true;
                        break;
                    }
                }
                if (command != "\u0003\n")
                {
                    mConsoleDriverWindow.ConsoleWriteText(reply.ToString(), true);
                    reply.Clear();
                }
                taskFinished = true;
            }
            catch (Exception ex)
            {
                Reporter.ToLog(eLogLevel.ERROR, ex.Message);
            }
            mConsoleDriverWindow.ConsoleWriteText(reply.ToString(), true);
            reply.Clear();
        }