private void AddCmd(Cmd cmd) { //try //{ try { keyhashCommands.Add(cmd.Key, cmd); } catch (Exception ex) { System.Console.WriteLine(cmd.Key + ",duplicated"); } //} //catch (Exception ex) //{ // Console.WriteLine(ex.Message); //} func_name_hashCommands.Add(cmd.cmdName,cmd); Commands.Add(cmd); }
protected override Object CreateObject(NonterminalToken token) { string name; int bytes, inx, value; CmdItem cmdItem; TestValue testval; try { switch (token.Rule.Id) { case (int)RuleConstants.RULE_TESTGROUPEXPRESS_TESTEQ: CanTest = false; break; case (int)RuleConstants.RULE_VERSION_VERSIONEQ_FLOAT: this.version = token.Tokens[1].UserObject.ToString(); break; case (int)RuleConstants.RULE_TESTGROUPEXPRESS_TESTEQ2: CanTest = true; break; case (int)RuleConstants.RULE_TESTEXPRESS_ATCMD: tmpTestExpress.Add(tmpTestValues); tmpTestValues = new System.Collections.ArrayList(10); break; case (int)RuleConstants.RULE_TESTREPEATITEMS_LBRACE_RBRACE: testval = (TestValue)token.Tokens[0].UserObject; inx = tmpTestValues.IndexOf(testval); for (int i = inx + 1; i < tmpTestValues.Count; i++) testval.subValues.Add(tmpTestValues[i]); for (int i = tmpTestValues.Count - 1; i > inx; i--) tmpTestValues.RemoveAt(i); break; case (int)RuleConstants.RULE_TESTSELECTVALUE_NUMBER: return token.Tokens[0].ToString(); case (int)RuleConstants.RULE_TESTSELECTVALUES: return token.Tokens[0].UserObject; case (int)RuleConstants.RULE_TESTSELECTITEM_IDENTIFIER_LPARAN_RPARAN: name = token.Tokens[0].UserObject.ToString(); value = Convert.ToInt32(token.Tokens[2].UserObject.ToString()); tmpTestValues.Add(testval = new TestValue(name, value)); return testval; case (int)RuleConstants.RULE_TESTITEM2: return token.Tokens[0].UserObject; case (int)RuleConstants.RULE_RANGEITEM_IDENTIFIER_LPARAN_RPARAN: NonterminalToken ntok; name = token.Tokens[getTokenInx(token, "Identifier")].UserObject.ToString(); ntok = findToken(token, "Bytes"); bytes = Convert.ToInt32(ntok.Tokens[0].UserObject.ToString()); ntok = findToken(token, "LValue"); int lval = Convert.ToInt32(ntok.Tokens[0].UserObject.ToString()); ntok = findToken(token, "HValue"); int hval = Convert.ToInt32(ntok.Tokens[0].UserObject.ToString()); TmpCmdItems.Add(cmdItem = new CmdItem(name, bytes, lval, hval)); return cmdItem; case (int)RuleConstants.RULE_SELECTITEM_IDENTIFIER_LPARAN_RPARAN: SelectValue[] selectvalues; name = token.Tokens[0].UserObject.ToString(); bytes = Convert.ToInt32(findToken(token, "Bytes").Tokens[0].UserObject.ToString()); selectvalues = new SelectValue[TmpSelectValues.Count]; for (int i = 0; i < TmpSelectValues.Count; i++) { selectvalues[i] = (SelectValue)TmpSelectValues[i]; } TmpCmdItems.Add(cmdItem = new CmdItem(name, bytes, selectvalues)); TmpSelectValues.Clear(); return cmdItem; case (int)RuleConstants.RULE_SELECTVALUE_NUMBER: SelectValue sVal = new SelectValue(); sVal.value = Convert.ToInt32(token.Tokens[0].UserObject.ToString()); sVal.valueName = findToken(token, "ValueDescription").Tokens[0].UserObject.ToString(); TmpSelectValues.Add(sVal); break; case (int)RuleConstants.RULE_EXPRESSITEM: return token.Tokens[0].UserObject; case (int)RuleConstants.RULE_REPEATEXPRESS_LBRACE_RBRACE: inx = TmpCmdItems.IndexOf(token.Tokens[0].UserObject); for (int i = inx + 1; i < TmpCmdItems.Count; i++) ((CmdItem)TmpCmdItems[inx]).AddSubItems((CmdItem)TmpCmdItems[i]);//reduce repeat item for (int i = TmpCmdItems.Count - 1; i > inx; i--) TmpCmdItems.RemoveAt(i); return TmpCmdItems[inx]; case (int)RuleConstants.RULE_SENDEXPRESS_SENDEQ: //send express tmpSendExpress.Clear(); break; case (int)RuleConstants.RULE_SENDEXPRESS_SENDEQ2: //sendexpress tmpSendExpress = (System.Collections.ArrayList)TmpCmdItems.Clone(); TmpCmdItems.Clear(); break; case (int)RuleConstants.RULE_RETURNEXPRESS_RETURNEQ: tmpReturnExpress.Clear(); break; case (int)RuleConstants.RULE_RETURNEXPRESS_RETURNEQ2: tmpReturnExpress = (System.Collections.ArrayList)TmpCmdItems.Clone(); TmpCmdItems.Clear(); break; case (int)RuleConstants.RULE_DEVICETYPE_DEVICETYPEEQ_IDENTIFIER: this.DeviceType = token.Tokens[1].UserObject.ToString(); break; case (int)RuleConstants.RULE_IP_IPEQ_IP: ip = token.Tokens[1].UserObject.ToString(); break; case (int)RuleConstants.RULE_PORT_PORTEQ_NUMBER: port = int.Parse(token.Tokens[1].UserObject.ToString()); break; case (int)RuleConstants.RULE_DEVICEID_DEVICEIDEQ_DEVICEID: deviceId = Convert.ToInt32(token.Tokens[1].ToString(), 16); break; case (int)RuleConstants.RULE_CMD_CMDEQ_CMD: //Cmd cmd; //if(token.Tokens[2].UserObject==null) // cmd=new Cmd(Convert.ToByte(token.Tokens[1].UserObject.ToString(),16)); //else //cmd=new Cmd(Convert.ToByte(token.Tokens[1].UserObject.ToString(),16), // Convert.ToByte(token.Tokens[2].UserObject.ToString(),16)); // return cmd; break; case (int)RuleConstants.RULE_COMMAND: //CmdClass cls; //CmdType type; //string desc; //string func_name; //byte cmdcode; Cmd cmd = new Cmd(this); // inx = getTokenInx(token, "Description"); for (int i = 0; i < token.Tokens.Length; i++) { NonterminalToken ttok; ttok = (NonterminalToken)token.Tokens[i]; if (token.Rule.Rhs[i].Name == "Description") { cmd.description = ((NonterminalToken)token.Tokens[i]).Tokens[1].UserObject.ToString().Trim(new char[] { '\"' }); } else if (token.Rule.Rhs[i].Name == "FuncName") { cmd.cmdName = ((NonterminalToken)token.Tokens[i]).Tokens[1].UserObject.ToString().Trim(new char[] { '\"' }); } else if (token.Rule.Rhs[i].Name == "CmdClass") { switch (((NonterminalToken)token.Tokens[i]).Tokens[1].UserObject.ToString()[0]) { case 'A': cmd.cmdClass = CmdClass.A; break; case 'B': cmd.cmdClass = CmdClass.B; break; case 'C': cmd.cmdClass = CmdClass.C; break; case 'D': cmd.cmdClass = CmdClass.D; break; } } else if (token.Rule.Rhs[i].Name == "CmdType") { if (((NonterminalToken)token.Tokens[i]).Tokens[1].UserObject.ToString() == "Set") cmd.cmdType = CmdType.CmdSet; else if (((NonterminalToken)token.Tokens[i]).Tokens[1].UserObject.ToString() == "Query") cmd.cmdType = CmdType.CmdQuery; else if (((NonterminalToken)token.Tokens[i]).Tokens[1].UserObject.ToString() == "Report") cmd.cmdType = CmdType.CmdReport; else cmd.cmdType = CmdType.CmdUnkonwn; } else if (token.Rule.Rhs[i].Name == "Cmd") { cmd.cmd = Convert.ToByte(ttok.Tokens[1].UserObject.ToString(), 16); //cmd if (((NonterminalToken)ttok.Tokens[2]).Tokens.Length > 0) cmd.subCmd = Convert.ToByte(((NonterminalToken)ttok.Tokens[2]).Tokens[0].UserObject.ToString(), 16); //subCmd } } //for cmd.SendCmdItems = (System.Collections.ArrayList)tmpSendExpress.Clone(); cmd.ReturnCmdItems = (System.Collections.ArrayList)tmpReturnExpress.Clone(); cmd.TestGroupValues = tmpTestExpress; cmd.CanTest = CanTest; tmpReturnExpress.Clear(); tmpSendExpress.Clear(); tmpTestValues.Clear(); tmpTestExpress = new System.Collections.ArrayList(5); //try //{ if (cmd.cmdType != CmdType.CmdReport) cmd.CheckTestValue(); cmd.GenerateCmdDataSet(); //} //catch (Exception ex) //{ // Console.WriteLine(ex.StackTrace); //} this.AddCmd(cmd); break; } } catch (Exception ex) { Console.WriteLine(ex.StackTrace); throw ex; } return null; }