/// <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();
}