public void open_RunPL_file(string file_path) { initPanel(); StreamReader read = new StreamReader(file_path, Encoding.UTF8); //正则表达式的Bug在于 Descript(".......);"); 末尾的); 将识别不出 string state = "(\\$(\\d+)\\s*=\\s*)?(\\w+)\\s*\\((.*?)\\)\\s*;"; string comment = "#.*"; string line = null; Regex Rstate = new Regex(state, RegexOptions.Singleline); Regex Rcom = new Regex(comment); line = read.ReadToEnd(); line = Regex.Replace(line, comment, ""); if (Rstate.IsMatch(line)) { MatchCollection m = Rstate.Matches(line); for (int i = 0; i < m.Count; i++) { Expression ex = new Expression(); //构造函数表达式 if (m[i].Groups[2].Value.Length > 0) { //说明含有参数 ex.assigne = m[i].Groups[2].Value; } ex.func_type = getKeyType(m[i].Groups[3].Value); ex.func_name = m[i].Groups[3].Value; //方法名称 ex.func_parm = m[i].Groups[4].Value; //方法参数 to_do(ex); } } //一切无错则显示运行按钮 if (this.hasRunPl && this.can_run) { this.btn_run_pl.Enabled = true; } }
//根据方法类型执行函数 private void to_do(Expression ex) { Parser p = null; ArrayList parms = null; try { p = new Parser(ex.func_parm); } catch (Exception e) { rb_result.AppendText(e.Message); this.can_run = false; return; } parms = p.getResult(); switch (ex.func_type) { case KEY.Error: ParmError("错误!!描述文件存在无效函数:" + ex.func_name + "\r\n"); break; case KEY.RunPL: if(checkParmsNum(parms.Count, 1)){ this.hasRunPl = true; setAppPath((string)parms[0]); } break; case KEY.SaveFile: if (parms.Count != 4) { ParmError("SelectFile 参数错误!!"); } else { if (ex.assigne == null) { ParmError("SelectFile 没有赋值对象, 如 $1"); return; } this.argv_nums = Convert.ToInt32( ex.assigne ); if ( !this.existNum(ex.assigne) ) { ht_assign.Add(ex.assigne, parms[3]); addSaveFilePath((string)parms[0], (string)parms[1], (string)parms[2], (string)parms[3]); } } break; case KEY.SelectFolder: if (parms.Count != 3) { ParmError("SelectFolder 参数错误!!"); } else { if (!this.existNum(ex.assigne)) { this.argv_nums = Convert.ToInt32( ex.assigne ); ht_assign.Add(ex.assigne, ""); addSelectFolder((string)parms[0], (string)parms[1], (string)parms[2]); } } break; case KEY.Descript: if(parms.Count != 1) { ParmError("Decript参数错误!!"); return; } tb_descript.Text = (string)parms[0]; break; case KEY.CheckBox: MessageBox.Show("To do show message" + ex.func_parm); break; case KEY.ComboBox: if (parms.Count > 2) { if (!existNum(ex.assigne)) { this.argv_nums = Convert.ToInt16(ex.assigne); ht_assign.Add(ex.assigne, ""); addComboBox(parms.ToArray()); } } else { ParmError("ComboBox 参数错误, 至少要两个参数,如: ComboBox('请选择', [1], 2)"); } break; case KEY.Manual: if (checkParmsNum(parms.Count, 1)) { this.richbox_manual.Text = (string)parms[0]; } else { ParmError("Manual 参数错误!"); } break; case KEY.SelectFile: if (parms.Count != 4) { ParmError("SelectFile 参数错误!!"); } else { if (ex.assigne != null) { this.argv_nums = Convert.ToInt32(ex.assigne); if (!this.existNum(ex.assigne)) { ht_assign.Add(ex.assigne, parms[3]); //用参数名称来保存这个数据 addSelectFilePath((string)parms[0], (string)parms[1], (string)parms[2]); } } else { ParmError("SelectFile 没有赋值对象 例如: $1 !!"); } } break; case KEY.TextBox: if (this.checkParmsNum(parms.Count, 2)) { this.argv_nums = Convert.ToInt32(ex.assigne); if (!this.existNum(ex.assigne)) { ht_assign.Add(ex.assigne, ""); addTextBox((string)parms[0], (string)parms[1]); } } else { ParmError("TextBox 参数错误, TextBox(\"Label\") , \"default\""); } break; case KEY.ShowCMD: if (checkParmsNum(parms.Count, 1)) { this.show_cmd = Convert.ToInt16(parms[0]) == 1 ? true : false; } else { ParmError("ShowCMD 参数错误, 应为ShowCMD(1)或ShowCMD(0)"); } break; case KEY.Command://扩展RunPL能够运行别的脚本名称,比如java, node, ruby等,不再局限于perl, 可以由用户自定义程序 if (parms.Count > 0 ) { String _param = ""; if(parms.Count > 1 ){ _param = parms[1].ToString(); } setCommand(parms[0].ToString(), _param); } else { ParmError("Process 参数错误"); } break; default: return; } }