Exemple #1
0
        public static object ScriptExec(ApiHost runtimeHost, string scrpitTxt)
        {
            //if (runtimeHost._isDesign)
            //{
            //    runtimeHost.printout(scrpitTxt);
            //}
            //创建一个IpyRunTime,需要2-3秒时间。建议进入全局时加载,此为演示
            var engine = CreateScriptEngine();// IronPython.Hosting.Python.CreateEngine();
            var code   = engine.CreateScriptSourceFromString(scrpitTxt);

            //设置参数;
            ScriptScope scope = engine.CreateScope();

            scope.SetVariable("apihost", runtimeHost);

            var actual = code.Execute <object>(scope);

            return(actual);
        }
Exemple #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();
            }
        }