public CCSTestInterface() { InitializeComponent(); run_bt.Enabled = false; clear_bt.Enabled = false; baseline = new SearchList[5]; demoList = new DemoGuiList(); //--List Default-- SearchList sl = new SearchList("CiscoIOS-Default"); // Main Command List SearchListData sldf0 = sl.AddKeyList("interface"); SearchListData sldf1 = sl.AddKeyList("username cisco privilege 15"); SearchListData sldf2 = sl.AddKeyList("line"); //Value Check Command SearchListData value1 = sl.AddChildValueKey("*", sldf0); SearchListData value2 = sl.AddChildValueKey("FastEthernet*", sldf0); SearchListData value3 = sl.AddChildValueKey("GigabitEthernet*", sldf0); SearchListData value4 = sl.AddChildValueKey("*", sldf1); SearchListData value5 = sl.AddChildValueKey("*", sldf2); // Child Command // -- Child Interface any except Fastethernet and GigabitEthernet sl.AddChildData("no ip proxy-arp", null, "interface", "system", "Interface-Disable proxy arp", value1); // -- Child Interface Fastethernet sl.AddChildData("no ip proxy-arp", null, "interface", "system", "Interface-Disable proxy arp", value2); sl.AddChildData("no ip redirects", null, "interface", "system", "Interface-Redirection", value2); // -- Child Interface GigabitEthernet sl.AddChildData("no ip proxy-arp", null, "interface", "system", "Interface-Disable proxy arp", value3); sl.AddChildData("no ip redirects", null, "interface", "system", "Interface-Redirection", value3); sl.AddChildData("no ip unreachables", null, "interface", "system", "Interface-IP Unreachables Enabled", value3); // -- Child username cisco privilege 15 //NULL // -- Child Line sl.AddChildData("password", null, "line", "system", "Line - Password Login", value5); baseline[0] = sl; //init list in combobox for (int i = 0; i < baseline.Length; i++) { if (baseline[i] != null) { ComboBoxItem comItem = new ComboBoxItem(baseline[i].listName, i); baseline_cb.Items.Add(comItem); } } //always select index 0 baseline_cb.SelectedIndex = 0; //load default BaseLine to screen AddListToScreen(baseline[0],demoList); //resultBox.Text = "fastEthernet0/0/1\r\n"; //resultBox.AppendText("line 2 \r\n"); }
//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)); }
public SearchList ExcleToSerachListProfile(object[,] excelObjArr) { //remark must be skip first line from excel file // SearchList returnList = null; if (excelObjArr != null) { returnList = new SearchList(); int row = excelObjArr.GetLength(0); int col = excelObjArr.GetLength(1); //Col ---> Category(1) | Control(2) | Description(3) | flag(4) | Key(5) | Value(6) | Child(7) //excel first row is 1 and skip header 1 Row; //excel first col is 1 for (int i = 2; i < row; i++) { //skip empty main command if (excelObjArr[i, 5] == null) { continue; } //check existing command SearchListData mainCmdList = returnList.FindTopList(excelObjArr[i, 5].ToString()); //is new command in list if (mainCmdList == null) { #if (DEBUG) Console.WriteLine("setProfileToDataList : add new key to list -> " + excelObjArr[i, 5].ToString()); #endif //Add first Key to List SearchListData newKey = returnList.AddKeyList(excelObjArr[i, 5].ToString()); //SearchListData childValue = returnList.AddChild( if (excelObjArr[i, 7] == null || excelObjArr[i, 7].ToString() == "*") { // for struct is a single command #if (DEBUG) Console.WriteLine("setProfileToDataList : -> " + excelObjArr[i, 5].ToString() + " - isn't has any child"); #endif //SearchListData vChild = returnList.AddChildValueKey(value, newKey); string value = "*"; if (excelObjArr[i, 6] != null) { value = excelObjArr[i, 6].ToString(); } else { //Throw exception } //Col ---> Category(1) | Control(2) | Description(3) | flag(4) | Key(5) | Value(6) | Child(7) SearchListData vChild = returnList.AddChildData(value, null, excelObjArr[i, 1].ToString(), excelObjArr[i, 2].ToString(), excelObjArr[i, 3].ToString(), newKey); } else { // for struct have a child command #if (DEBUG) Console.WriteLine("setProfileToDataList : add value list -> " + excelObjArr[i, 6].ToString() + " - has any child"); #endif string value = "*"; if (excelObjArr[i, 6] != null) { value = excelObjArr[i, 6].ToString(); } else { //Throw exception } SearchListData vChild = returnList.AddChildValueKey(value, newKey); //Col ---> Category(1) | Control(2) | Description(3) | flag(4) | Key(5) | Value(6) | Child(7) // key of child node is col 7 SearchListData childdata = returnList.AddChildData(excelObjArr[i, 7].ToString(), null, excelObjArr[i, 1].ToString(), excelObjArr[i, 2].ToString(), excelObjArr[i, 3].ToString(), vChild); } //add main command(KEY) must be unique key } else { //find already existing in this list //get value //check has child command or not? string value = "*"; if (excelObjArr[i, 6] != null) { value = excelObjArr[i, 6].ToString(); } else { //Throw exception } if (excelObjArr[i, 7] == null || excelObjArr[i, 7].ToString() == "*") { //Col ---> Category(1) | Control(2) | Description(3) | flag(4) | Key(5) | Value(6) | Child(7) //SearchListData vChild = returnList.AddChildData(value, null, excelObjArr[i, 1].ToString(), excelObjArr[i, 2].ToString(), excelObjArr[i, 3].ToString(), mainCmdList); //check existing value if (returnList.FindList(mainCmdList.child, value) == null) { SearchListData childdata = returnList.AddChildData(excelObjArr[i, 7].ToString(), null, excelObjArr[i, 1].ToString(), excelObjArr[i, 2].ToString(), excelObjArr[i, 3].ToString(), mainCmdList.child); } } else { SearchListData vChild = returnList.FindList(mainCmdList.child, value); if (vChild == null) { //add value to child of mainCmdList //vChild = returnList.AddChildData(value, null, excelObjArr[i, 1].ToString(), excelObjArr[i, 2].ToString(), excelObjArr[i, 3].ToString(), mainCmdList); vChild = returnList.AddChildValueKey(value, mainCmdList); } SearchListData childdata = returnList.AddChildData(excelObjArr[i, 7].ToString(), null, excelObjArr[i, 1].ToString(), excelObjArr[i, 2].ToString(), excelObjArr[i, 3].ToString(), vChild); } //string value = "*"; //if (excelObjArr[i, 6] != null) { value = excelObjArr[i, 6].ToString(); } } } } return returnList; }