//SearchList baseLineList; public Form1() { InitializeComponent(); SearchList sl = new SearchList(); //Full test check SearchListData sldf = sl.AddKeyList("interface"); SearchListData sldf1 = sl.AddKeyList("username cisco privilege 15"); SearchListData v1 = sl.AddChildValueKey("*", sldf); SearchListData v2 = sl.AddChildValueKey("GigabitEthernet1/0/2*", sldf); SearchListData v3 = sl.AddChildValueKey("GigabitEthernet1/0/15", sldf); SearchListData v4 = sl.AddChildValueKey("GigabitEthernet1/0/16*", sldf); SearchListData v5 = sl.AddChildValueKey("GigabitEthernet1/0/1", sldf); SearchListData v6 = sl.AddChildValueKey("GigabitEthernet1/0/1*", sldf); SearchListData v7 = sl.AddChildValueKey("GigabitEthernet1/0/*", sldf); SearchListData v8 = sl.AddChildValueKey("GigabitEthernet1/0/11*", sldf); SearchListData v9 = sl.AddChildValueKey("GigabitEthernet1/0/9", sldf); SearchListData v10 = sl.AddChildValueKey("GigabitEthernet1/0/11", sldf); sl.AddChildData("no ip proxy-arp", null, "interface", "system", "Interface-Disable proxy arp", v1); sl.AddChildData("no ip redirects", null, "interface", "system", "Interface-Redirection", v1); sl.AddChildData("no ip proxy-arp", null, "interface", "system", "Interface-Disable proxy arp", v2); sl.AddChildData("no ip proxy-arp", null, "interface", "system", "Interface-Disable proxy arp", v3); sl.AddChildData("no ip proxy-arp", null, "interface", "system", "Interface-Disable proxy arp", v4); sl.AddChildData("no ip proxy-arp", null, "interface", "system", "Interface-Disable proxy arp", v5); sl.AddChildData("no ip proxy-arp", null, "interface", "system", "Interface-Disable proxy arp", v6); sl.AddChildData("no ip proxy-arp", null, "interface", "system", "Interface-Disable proxy arp", v7); sl.AddChildData("no ip proxy-arp", null, "interface", "system", "Interface-Disable proxy arp", v8); sl.AddChildData("no ip proxy-arp", null, "interface", "system", "Interface-Disable proxy arp", v9); sl.AddChildData("no ip proxy-arp", null, "interface", "system", "Interface-Disable proxy arp", v10); SearchListData av1 = sl.AddChildValueKey("*", sldf1); SearchListData root = sl.head; StreamReader readfile = new StreamReader("C:\\Users\\nutkondee\\documents\\visual studio 2012\\Projects\\ConfigCompliance\\ConfigCompliance\\resources\\ex-cisco-ios.txt"); SearchListData mainList = null; while ((line = readfile.ReadLine())!=null) { //Console.WriteLine(""); //checking main command if ((mainList = sl.MatchingOnList(line)) != null) { //check subcommand Console.WriteLine("--> main command match :: "+mainList.key); string fullValue = line.Substring(mainList.key.Length).Trim(); SearchListData longValue = sl.LongestMatch(mainList.child, fullValue); Console.WriteLine("---> value input :: " + fullValue); Console.WriteLine("---> value match on key :: " + longValue.key); //check childcommand if (longValue!=null && longValue.child!=null) { string subline; while ((subline = readfile.ReadLine()) != "!") { Console.WriteLine("---->subline print :: " + subline); } } } } //test zone longest match /* SearchListData sldf = sl.AddKeyList("*"); SearchListData sldf1 = sl.AddKeyList("GigabitEthernet"); SearchListData sldf2 = sl.AddKeyList("GigabitEthernet1/0"); SearchListData sldf3 = sl.AddKeyList("GigabitEthernet1/0/1"); Console.WriteLine("--> logest match :: " + sl.LongestMatch(sl.head, "GigabitEthernet1/0/9").key); */ //test zone add list /* baseLineList = new SearchList(); baseLineList.AddList("interface", "vlan"); baseLineList.AddList("aaa", "server"); baseLineList.AddList("bbb", "server"); baseLineList.AddList("ccc", "server"); Console.WriteLine(baseLineList.getFirst().key); */ //test zone string //string a = "interface GigabitEthernet"; //string b = "interface GigabitEthernet1/0/1"; //Console.WriteLine(b.StartsWith(a, StringComparison.OrdinalIgnoreCase)); }
//public char[] buffer; public ClassForTest() { SearchList sl = new SearchList(); //Full test check SearchListData sldf = sl.AddKeyList("interface"); SearchListData sldf1 = sl.AddKeyList("username cisco privilege 15"); SearchListData sldf2 = sl.AddKeyList("line"); SearchListData v1 = sl.AddChildValueKey("*", sldf); SearchListData v11 = sl.AddChildValueKey("*", sldf1); SearchListData v12 = sl.AddChildValueKey("*", sldf2); SearchListData v2 = sl.AddChildValueKey("FastEthernet*", sldf); SearchListData v3 = sl.AddChildValueKey("GigabitEthernet1/0/15", sldf); SearchListData v4 = sl.AddChildValueKey("GigabitEthernet1/0/16*", sldf); SearchListData v5 = sl.AddChildValueKey("GigabitEthernet1/0/1", sldf); SearchListData v6 = sl.AddChildValueKey("GigabitEthernet1/0/1*", sldf); SearchListData v7 = sl.AddChildValueKey("GigabitEthernet1/0/*", sldf); SearchListData v8 = sl.AddChildValueKey("GigabitEthernet1/0/11*", sldf); SearchListData v9 = sl.AddChildValueKey("GigabitEthernet1/0/9", sldf); SearchListData v10 = sl.AddChildValueKey("GigabitEthernet*", sldf); sl.AddChildData("password", null, "line", "system", "Line - Password Login", v12); sl.AddChildData("no ip proxy-arp", null, "interface", "system", "Interface-Disable proxy arp", v1); sl.AddChildData("no ip redirects", null, "interface", "system", "Interface-Redirection", v1); sl.AddChildData("no ip proxy-arp", null, "interface", "system", "Interface-Disable proxy arp", v2); sl.AddChildData("no ip proxy-arp", null, "interface", "system", "Interface-Disable proxy arp", v3); sl.AddChildData("no ip proxy-arp", null, "interface", "system", "Interface-Disable proxy arp", v4); sl.AddChildData("no ip proxy-arp", null, "interface", "system", "Interface-Disable proxy arp", v5); sl.AddChildData("no ip proxy-arp", null, "interface", "system", "Interface-Disable proxy arp", v6); sl.AddChildData("no ip proxy-arp", null, "interface", "system", "Interface-Disable proxy arp", v7); sl.AddChildData("no ip proxy-arp", null, "interface", "system", "Interface-Disable proxy arp", v8); sl.AddChildData("no ip proxy-arp", null, "interface", "system", "Interface-Disable proxy arp", v9); sl.AddChildData("no ip proxy-arp", null, "interface", "system", "Interface-Disable proxy arp", v10); SearchListData av1 = sl.AddChildValueKey("*", sldf1); SearchListData root = sl.head; //full file StreamReader readfile = new StreamReader("C:\\Users\\nutkondee\\documents\\visual studio 2012\\Projects\\ConfigCompliance\\ConfigCompliance\\resources\\ex-cisco-ios.txt"); //some test case //StreamReader readfile = new StreamReader("C:\\Users\\nutkondee\\documents\\visual studio 2012\\Projects\\ConfigCompliance\\ConfigCompliance\\resources\\ex-cisco-ios-1.txt"); SearchListData mainList = null; line = readfile.ReadLine(); Console.WriteLine(line); while (line != null) { bool skipLine = false; if ((mainList = sl.MatchingOnList(line)) != null) { Console.WriteLine("--> main command match :: " + mainList.key); //cut off main cmd string fullValue = line.Substring(mainList.key.Length).Trim(); //search value in value list SearchListData longValue = sl.LongestMatch(mainList.child, fullValue); Console.WriteLine("---> value input :: " + fullValue); Console.WriteLine("---> value match on key :: " + longValue.key); //check childcommand if (longValue != null && longValue.child != null) { string subline; while ((subline = readfile.ReadLine()) != "!") { SearchListData chkMainList; if ((chkMainList = sl.MatchingOnList(subline)) != null) { line = subline; skipLine = true; break; } else { Console.WriteLine("---->subline print :: " + subline); } } } } if(!skipLine){ line = readfile.ReadLine(); } } /* while ((line = readfile.ReadLine()) != null) { //Console.WriteLine(""); //checking main command //bool foundMainKey = false; if ((mainList = sl.MatchingOnList(line)) != null) { //check subcommand //foundMainKey = true; Console.WriteLine("--> main command match :: " + mainList.key); string fullValue = line.Substring(mainList.key.Length).Trim(); SearchListData longValue = sl.LongestMatch(mainList.child, fullValue); Console.WriteLine("---> value input :: " + fullValue); Console.WriteLine("---> value match on key :: " + longValue.key); //check childcommand if (longValue != null && longValue.child != null) { string subline; while ((subline = readfile.ReadLine()) != "!") { Console.WriteLine("---->subline print :: " + subline); } } } } */ Console.WriteLine("Press any key to continue..."); //test zone longest match /* SearchListData sldf = sl.AddKeyList("*"); SearchListData sldf1 = sl.AddKeyList("GigabitEthernet"); SearchListData sldf2 = sl.AddKeyList("GigabitEthernet1/0"); SearchListData sldf3 = sl.AddKeyList("GigabitEthernet1/0/1"); Console.WriteLine("--> logest match :: " + sl.LongestMatch(sl.head, "GigabitEthernet1/0/9").key); */ //test zone add list /* baseLineList = new SearchList(); baseLineList.AddList("interface", "vlan"); baseLineList.AddList("aaa", "server"); baseLineList.AddList("bbb", "server"); baseLineList.AddList("ccc", "server"); Console.WriteLine(baseLineList.getFirst().key); */ //test zone string //string a = "interface GigabitEthernet"; //string b = "interface GigabitEthernet1/0/1"; //Console.WriteLine(b.StartsWith(a, StringComparison.OrdinalIgnoreCase)); }