Example #1
0
        //执行脚本;
        public object ExecScript(string scriptnames)
        {
            if (scriptnames.Length <= 0)
            {
                return(null);
            }


            string[] eventList = scriptnames.Split(';');

            for (int i = 0; i < eventList.Count(); i++)
            {
                try
                {
                    string scrpitName = eventList[i];
                    if (scrpitName.Length <= 0)
                    {
                        continue;
                    }
                    string scrpitTxt = "";
                    if (this._scriptDictionary.ContainsKey(scrpitName))
                    {
                        scrpitTxt = this._scriptDictionary[scrpitName];
                    }
                    if (scrpitTxt.Length <= 0)
                    {
                        continue;
                    }

                    var actual = IronPythonManager.ScriptExec(this, scrpitTxt);
                    if (actual == null)
                    {
                        //memoEdit_Print.Text = "> 无返回结果";
                    }
                    else
                    {
                        if (eventList.Count() <= 1)
                        {
                            return(actual);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Common.Util.NocsMessageBox.Error(ex.Message);
                    //MessageBox.Show(ex.Message);
                    //this.memoEdit_Print.ForeColor = Color.Red;
                    //memoEdit_Print.Text = "> Error:" + ex.ToString();
                }
            }

            return(null);
        }
Example #2
0
        void ApiHelper_ApiRequsetSendedEvent(EohiDataRemoteObject.ApiHelper apiHelper, Hashtable hashtable)
        {
            try
            {
                //MessageBox.Show(hashtable.Count.ToString());

                string method = hashtable["method"].ToString();

                EohiDataRemoteObject.ApiResult result = new EohiDataRemoteObject.ApiResult();

                ApiHost apihost = new ApiHost();
                apihost.apiResult    = result;
                apihost.requestParas = hashtable;


                //执行查询;
                ApiItem apiItem = this.apiItemList.Find(x => x.apiname == method);
                if (apiItem == null)
                {
                    result.Code           = 1;
                    result.ResultDataType = 2;
                    result.Msg            = "未找到名为" + method + "的方法,该api可能不存在未处于在线服务状态";
                    result.ResultDataType = 4;
                }
                else
                {
                    //执行脚本;
                    IronPythonManager.ScriptExec(apihost, apiItem.apiscript);
                }


                //将查询结果返回;
                apiHelper._reslut = result;

                PrintLog("> " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " " + method + ",执行完成", true);
            }
            catch (Exception ex)
            {
                //MessageBox.Show(ex.Message);
                PrintLog("> Error:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " " + ex.ToString(), false);
            }
        }
        private void btn_test_Click(object sender, EventArgs e)
        {
            try
            {
                Hashtable hashTable = new Hashtable();
                string[]  paras     = this.textEdit_pars.Text.Trim().Split('&');
                for (int a = 0; a < paras.Length; a++)
                {
                    string[] parasv = paras[a].Split('=');
                    if (parasv.Length > 1)
                    {
                        hashTable.Add(parasv[0], parasv[1]);
                    }
                }


                EohiDataRemoteObject.ApiResult apiResult = new EohiDataRemoteObject.ApiResult();



                ApiHost apihost = new ApiHost();
                apihost.apiResult    = apiResult;
                apihost.requestParas = hashTable;


                //执行脚本;

                var actual = IronPythonManager.ScriptExec(apihost, this.textEditorControl.Text);
            }
            catch (Exception ex)
            {
                //MessageBox.Show(ex.Message);
                this.memoEdit_Print.ForeColor = Color.Red;
                memoEdit_Print.Text           = "> Error:" + ex.ToString();
            }
        }