public override bool CreateReader(ref Exception error)
 {
     try
     {
         Ssh = new SshShell(Recorder.RemoteHost, Recorder.User, Recorder.Password);
         Ssh.Connect(Port <= 0 ? 22 : Port, int.MaxValue);
         Keyword = DateTime.Now.Ticks + "." + Guid.NewGuid() + "." + random.Next();
         if (!SendCommand(ref error))
             return false;
         WaitBegin = true;
         sshReader = new StreamExpect
             {
                 Data = Ssh,
                 Expect = Pattern,
                 ReadTimeout = ReadTimeout,
                 Stream = Ssh.IO
             };
         sshReader.OnReadTimeout += sshReader_OnReadTimeout;
         return true;
     }
     catch (Exception e)
     {
         error = e;
     }
     return false;
 }
        public override NextInstruction CreateStream(ref Exception error)
        {
            try
            {
                if (TerminalReady())
                    return NextInstruction.Do;
                CloseTerminal();

                Recorder.Log(LogLevel.DEBUG, "Var:" + Recorder.CustomVar1);
                Terminal = CreateTerminal();
                if (Terminal.Connect(Port <= 0 ? 22 : Port, ref error))
                {
                    Stream = Terminal.GetInputStream(ref error);
                    Recorder.Log(LogLevel.INFORM, "Create Terminal ReadTimeout: " + ReadTimeout);
                    streamExpect = new StreamExpect
                    {
                        Data = Terminal,
                        Expect = Pattern,
                        ReadTimeout = ReadTimeout,
                        Stream = Terminal.GetInputStream(ref error)
                    };
                    streamExpect.OnReadTimeout += StreamExpectOnReadTimeout;
                    return NextInstruction.Do;
                }
            }
            catch (Exception e)
            {
                Recorder.Log(LogLevel.ERROR, "CReate Stream Error:" + e);
                error = e;
            }
            return NextInstruction.Abort;
        }
 public void TearDown()
 {
     _streamExpect = null;
 }
        public virtual void CloseTerminal()
        {
            Recorder.Log(LogLevel.DEBUG, "Close Terminal");
            if (streamExpect != null)
            {
                streamExpect.OnReadTimeout -= StreamExpectOnReadTimeout;
                streamExpect = null;
            }

            DisposeHelper.Close(Terminal, streamExpect);
            Terminal = null;
        }
 public void SetUp()
 {
     _streamExpect = new StreamExpect();
 }