void ToolStripButton2Click(object sender, EventArgs e) { TestScriptParser parser = new TestScriptParser(scintilla1.Text, 0); TestScriptDocument document = parser.Parse(); if (OpenConnection()) { TestScriptEvalContext context = new TestScriptEvalContext(protoSpecDocument, socket); TestScriptValue result = TestScriptEval.Do(document, context); treeView4.Nodes.Clear(); foreach (TestScriptValue item in (TestScriptValueList)result.Value) { TreeNode node = treeView4.Nodes.Add(item.ModuleName + ":" + item.ActionName); TestScriptValue value = (TestScriptValue)item.Value; ProtoSpecModule module = protoSpecDocument.Modules.GetByName(item.ModuleName, true); ProtoSpecAction action = module.Actions.GetByName(item.ActionName, true); ParseResponse2(value, action.Output, node.Nodes); } } }
void ParseResponse2(TestScriptValue result, ProtoSpecSubset format, TreeNodeCollection nodes) { foreach (ProtoSpecColumn column in format.Columns) { string columnName = column.Name + " : " + ColumnTypeToString(column.ColumnType) + " = "; switch (column.ColumnType) { case ProtoSpecColumnType.Byte: case ProtoSpecColumnType.Short: case ProtoSpecColumnType.Int: case ProtoSpecColumnType.Long: columnName += result.GetProperty(column.Name).Value; break; case ProtoSpecColumnType.Enum: columnName += result.GetProperty(column.Name).EnumName; break; case ProtoSpecColumnType.String: columnName += "\"" + result.GetProperty(column.Name).Value + "\""; break; case ProtoSpecColumnType.List: { TestScriptValueList list = (TestScriptValueList)result.GetProperty(column.Name).Value; columnName += list.Count; TreeNode node = nodes.Add(columnName); for (int i = 0; i < list.Count; i++) { TreeNode subnode = node.Nodes.Add("[" + i + "]"); ParseResponse2(list[i], column.Format, subnode.Nodes); } } break; } if (column.ColumnType != ProtoSpecColumnType.List) { nodes.Add(columnName); } } }