/// <summary> /// Dump the input until we see a particular string in the returning text. /// </summary> /// <param name="s"></param> /// <param name="refreshTimeout">If we see something back from the host, reset the timeout counter</param> /// <param name="p"></param> /// <param name="failNow">Function that returns true if we should throw out right away</param> private void DumpTillFind(ShellStream s, string matchText, Action<string> ongo = null, bool dontdumplineofmatch = true, int secondsTimeout = 60*60, bool refreshTimeout = false, Func<bool> failNow = null ) { var lb = new LineBuffer(ongo); if (dontdumplineofmatch) { lb.Suppress(matchText); } var timeout = DateTime.Now + TimeSpan.FromSeconds(secondsTimeout); bool gotmatch = false; while (timeout > DateTime.Now) { s.Expect(TimeSpan.FromMilliseconds(100), new ExpectAction(matchText, l => { lb.Add(l); gotmatch = true; })); gotmatch = gotmatch || lb.Match(matchText); if (gotmatch) break; var data = s.Read(); if (data != null && data.Length > 0 && refreshTimeout) { timeout = DateTime.Now + TimeSpan.FromSeconds(secondsTimeout); } lb.Add(data); if (failNow != null && failNow()) { throw new SSHCommandInterruptedException("Calling routine requested termination of command"); } } if (!gotmatch) { throw new TimeoutException(string.Format("Waiting for '{0}' back from host and it was not seen inside of {1} seconds.", matchText, secondsTimeout)); } lb.DumpRest(); }
public void MatchOnCharByChar() { var l = new LineBuffer(); l.Add("b"); l.Add("a"); Assert.IsFalse(l.Match("bash")); l.Add("s"); l.Add("h"); Assert.IsTrue(l.Match("bash")); }
public void TestEmptyLineWidth() { var l = new LineBuffer(null); Assert.IsFalse(l.Match("bogus")); }
public void SimpleMatchWithExtra() { var l = new LineBuffer(); l.Add("bogusbashdude"); Assert.IsTrue(l.Match("bash")); }
public void SimpleMatch() { var l = new LineBuffer(); l.Add("bash"); Assert.IsTrue(l.Match("bash")); }
public void MissMatchOnNewLine() { var l = new LineBuffer(); l.Add("bash" + CrLf + "dude"); Assert.IsFalse(l.Match("bash")); }