/// <summary>
        /// 执行if框
        /// </summary>
        /// <param name="box"></param>
        /// <returns></returns>
        protected void DoIfFunction(ItemBox box, WriteStreamCallBack wrs, IScriptLayout ml)
        {
            ScriptInput si = new ScriptInput();

            foreach (var item in box.InputDatas)
            {
                if (item.PIEnum != ParaItemEnum.INPUT)
                {
                    si.SetValue(item.Name, GetValue(item as ParatItem));
                }
            }

            //检测是否需要断点停止
            checkScriptRunForStopPoint(box, si, null);

            if (Convert.ToBoolean(si.GetFirst()))
            {
                RunningFunction((box as ItemBox).Children[0], wrs, ml);
            }
            else
            {
                RunningFunction((box as ItemBox).Children[1], wrs, ml);
            }
            si.Dispose();
            si = null;
        }
Beispiel #2
0
 /// <summary>
 /// 释放
 /// </summary>
 public void Dispose()
 {
     ValuePairs.Dispose();
     ValuePairs = null;
     Stream     = null;
     ApiName    = null;
 }
        /// <summary>
        /// 执行准确的函数
        /// </summary>
        /// <param name="box"></param>
        protected void Dofunction(ItemBox box, WriteStreamCallBack wrs, IScriptLayout ml)
        {
            if (isStop)
            {
                throw new Exception("主动停止了脚本!");
            }
            ml.SetFunctionBoxRun(box);
            ScriptInput si = new ScriptInput();

            foreach (var item in box.InputDatas)
            {
                if (item.PIEnum != ParaItemEnum.INPUT)
                {
                    si.SetValue(item.Name, GetValue(item as ParatItem));
                }
            }

            ScriptOutput so = RunScript(box, si);

            //ScriptOutput so = null;             ////////////////////////////////////待修改
            if (so != null)
            {
                if (so.LogMessage != null && so.LogMessage.Equals("") == false)
                {
                    wrs?.Invoke(so.LogMessage);
                }
                foreach (var item in box.OutDatas)
                {
                    if (item.PIEnum != ParaItemEnum.OUTPUT)
                    {
                        item.Value = so.GetValue(item.Name);
                        SetValue(item as ParatItem);
                    }
                }
            }
            //检测是否需要断点停止
            checkScriptRunForStopPoint(box, si, null);
            if (so != null)
            {
                so.Dispose();
                so = null;
            }
            si.Dispose();
            si = null;
            ml.SetFunctionBoxStop(box);
        }
        /// <summary>
        /// 请求回调
        /// </summary>
        /// <param name="arg1">请求流</param>
        /// <param name="response">回写流</param>
        protected void RequestCallBack(HttpListenerRequest request, HttpListenerResponse response)
        {
            RequestMsg requestMsg = null;

            try
            {
                requestMsg = ScriptServer.GetRequestMessage(request);
                Log.Write("收到接口请求 : ", requestMsg.ApiName);
                if (requestMsg.ApiName.Equals(GetAllAPIUrlAPIName))
                {
                    updateAPIsRequest?.Invoke();
                    writeResponse(getAllApi(), response, 200);
                }
                else if (scriptAPIs.ContainsKey(requestMsg.ApiName))
                {
                    ScriptInput  scriptInput  = requestMsg.ValuePairs;
                    ScriptOutput scriptOutput = scriptAPIs[requestMsg.ApiName].ScriptFunction(scriptInput);
                    writeResponse(scriptOutput, response, 200);
                    scriptOutput.Dispose();
                    scriptInput.Dispose();
                    scriptOutput = null;
                    scriptInput  = null;
                }
                else
                {
                    ///回复客户端异常
                    writeResponse(response, 201);
                }
            }
            catch (Exception ex)
            {
                writeResponse(response, 201);
                Log.Write("客户端调用出错", ex);
            }
            finally
            {
                if (requestMsg != null)
                {
                    requestMsg.Dispose();
                    requestMsg = null;
                }
            }
        }
        /// <summary>
        /// 做循环
        /// </summary>
        /// <param name="box"></param>
        /// <returns></returns>
        protected void DoWhileFunction(ItemBox box, WriteStreamCallBack wrs, IScriptLayout ml)
        {
            ItemBox sbox = box as ItemBox;

            if (box.InputDatas.Count == 1)
            {
                if (box.InputDatas[0].PIEnum == ParaItemEnum.BOOL)
                {
                    ScriptInput si = GetFunctionInput(box);
                    //检测是否需要断点停止
                    checkScriptRunForStopPoint(box, si, null);
                    while (true)
                    {
                        if (Convert.ToBoolean(si.GetFirst()))
                        {
                            RunningFunction(box, wrs, ml);
                        }
                        else
                        {
                            return;
                        }
                        si.Dispose();
                        si = null;
                        si = GetFunctionInput(box);
                    }
                }
                else if (box.InputDatas[0].PIEnum == ParaItemEnum.DATETIME)
                {
                    ScriptInput si = GetFunctionInput(box);
                    //检测是否需要断点停止
                    checkScriptRunForStopPoint(box, si, null);
                    while (true)
                    {
                        if (Convert.ToDateTime(si.GetFirst()) > DateTime.Now)
                        {
                            RunningFunction(box, wrs, ml);
                        }
                        else
                        {
                            return;
                        }
                        si.Dispose();
                        si = null;
                        si = GetFunctionInput(box);
                    }
                }
            }
            else
            {
                ScriptInput si = GetFunctionInput(box);
                while (true)
                {
                    int idxs   = Convert.ToInt32(si.GetFirst());
                    int idxe   = Convert.ToInt32(si.GetSecond());
                    int boxidx = GetWhileBoxIdx(sbox, idxs);
                    //if (box.IsHasBreakPoint)
                    //{
                    //    ScriptOutput so = new ScriptOutput();
                    //    so.SetValue("Idx", boxidx);
                    //    ScriptBreakPoint?.Invoke(box, si, so);
                    //}
                    //检测是否需要断点停止
                    checkScriptRunForStopPoint(box, si, null);

                    if (boxidx > idxe)
                    {
                        return;
                    }
                    else
                    {
                        RunningFunction(box, wrs, ml);
                    }
                    si.Dispose();
                    si = null;
                    si = GetFunctionInput(box);
                }
            }
        }