public bool ContainsAll(string[] InPatternStrings) { bool containsAll = false; if (Arrayer.ContainsAll <string>( this.StringArray, InPatternStrings) == true) { containsAll = true; } return(containsAll); }
/// <summary> /// Scan forward in string for any of the pattern strings. /// </summary> /// <param name="InString"></param> /// <param name="InBx"></param> /// <param name="InLx"></param> /// <param name="InPattern"></param> /// <returns></returns> public static ScanPatternResults ScanEqualAnyStrings( string InString, int InBx, int InLx, string[] InPattern) { // build array of pattern leading characters. char[] patChars = Arrayer.StringArrayToLeadingCharArray(InPattern); ScanPatternResults spr = ScanEqualAnyStrings( InString, InBx, InLx, InPattern, patChars); return(spr); }
/// <summary> /// Scan the bounded string for any of the pattern characters, /// bypassing quoted strings within the scan space. /// </summary> /// <param name="InBounded"></param> /// <param name="InBx"></param> /// <param name="InPatternChars"></param> /// <param name="InQem"></param> /// <returns></returns> public static ScanCharResults ScanEqualAny_BypassQuoted( BoundedString InBounded, int InBx, char[] InPatternChars, QuoteEncapsulation InQem) { ScanCharResults res; int Fx; char[] patternChars = Arrayer.Concat <char>(InPatternChars, new char[] { '"', '\'' }); int Ix = InBx; while (true) { res = ScanEqualAny(InBounded, Ix, patternChars); if (res.ResultPos == -1) { break; } else if (IsOpenQuoteChar(res.ResultChar) == true) { Fx = ScanCloseQuote(InBounded, res.ResultPos, InQem); if (Fx == -1) { throw new ApplicationException("End of quoted string not found"); } else if (Fx == InBounded.Ex) { res = new ScanCharResults(-1); break; } else { Ix = Fx + 1; } } else { break; } } return(res); }
// --------------------------------- Login ------------------------------ public virtual string[] Login( CommandThread InCmdThread, ReadBuffer InReadBuffer, delWriteEventLog InWriteEventLog, string InNullText) { StringBuilder accumRead = new StringBuilder(); string[] lines = null; string[] loginPrompts = new string[] { ":" }; // telnet server sends a login prompt. read until it arrives. if (InCmdThread.ShutdownFlag.State == false) { if (InWriteEventLog != null) { InWriteEventLog(null, "Read login prompt ...", "Login"); } lines = InReadBuffer.ReadUntilEndsWith(loginPrompts); ThreadCommon.WriteToEventLog(InWriteEventLog, lines, "Login"); } // send username to the telnet server. if (InCmdThread.ShutdownFlag.State == false) { if (InWriteEventLog != null) { InWriteEventLog(null, "Username " + mLoginProperties.LoginUser, "Login"); } InCmdThread.Conn.WriteLine(mLoginProperties.LoginUser); } // read back the prompt for password. if (InCmdThread.ShutdownFlag.State == false) { if (InWriteEventLog != null) { InWriteEventLog(null, "Read password prompt ...", "Login"); } lines = InReadBuffer.ReadUntilEndsWith(loginPrompts); ThreadCommon.WriteToEventLog(InWriteEventLog, lines, "Login"); } // send password to telnet server. if (InCmdThread.ShutdownFlag.State == false) { if (InWriteEventLog != null) { InWriteEventLog(null, "Password ********", "Login"); } InCmdThread.Conn.WriteLine(mLoginProperties.LoginPass); } // read back until the logged in command prompt. if (InCmdThread.ShutdownFlag.State == false) { if (InWriteEventLog != null) { InWriteEventLog(null, "Read command prompt ...", "Login"); } while (true) { string[] xx = null; xx = InReadBuffer.Read(); ThreadCommon.WriteToEventLog(InWriteEventLog, xx, "Login"); string lastLine = Arrayer.LastItem(xx); if (lastLine != null) { string trimLastLine = lastLine.TrimEnd(new char[] { ' ', '\t', '\r', '\n' }); string lsChar = StringExt.Tail(trimLastLine, 1); if (lsChar == ">") { break; } } } } // return all the response line received from the server. return(lines); }
/// <summary> /// Scan for any of the pattern strings in the search string. /// </summary> /// <param name="InString"></param> /// <param name="InBx"></param> /// <param name="InLx"></param> /// <param name="InPattern"></param> /// <returns></returns> public static ScanStringResults ScanEqualAnyxStrings( string InString, int InBx, int InLx, string[] InPattern) { string foundPat = null; int fx = -1; int lx = InLx; int ix = InBx; int Ex = InBx + InLx - 1; // build array of pattern leading characters. char[] patChars = Arrayer.StringArrayToLeadingCharArray(InPattern); while (foundPat == null) { lx = Ex - ix + 1; fx = InString.IndexOfAny(patChars, ix, lx); if (fx == -1) { break; } // length remaining in search string. from found location to end. int remLx = Ex - fx + 1; char ch1 = InString[fx]; int mx = 0; while (true) { int nx = Array.IndexOf(patChars, ch1, mx); if (nx == -1) { break; } // test if the substring starting at the char found position matches the full // pattern of the found char. string pat = InPattern[nx]; if ((pat.Length <= remLx) && (InString.Substring(fx, pat.Length) == pat)) { break; } // full pattern does not match. Setup in patChars array to search for the next // pattern search string with the found leading char. mx = nx + 1; } foreach (string s1 in InPattern) { if ((s1.Length <= remLx) && (InString.Substring(fx, s1.Length) == s1)) { foundPat = s1; break; } } } return(new ScanStringResults(foundPat, fx)); }