Example #1
0
        /// <summary>
        /// Executes all the statements in the script.
        /// </summary>
        public override PhaseResult Execute(PhaseContext phaseCtx)
        {
            // 1. Check number of statements.
            var statements = _execAllNodes ? phaseCtx.Nodes : phaseCtx.NodesStack[phaseCtx.NodesStack.Count - 1];

            var now = DateTime.Now;

            // 2. No statements ? return
            if (statements == null || statements.Count == 0)
                return ToPhaseResult(now, now, true, "There are 0 nodes to execute");

            // 3. Execute the nodes and get the run-result which captures various data
            var runResult = LangHelper.Execute(() =>
            {
                var execution = new Execution();
                execution.Ctx = this.Ctx;
                EvalHelper.Ctx = this.Ctx;
                execution.VisitExprs(statements);
            });

            // 4. Simply wrap the run-result ( success, message, start/end times )
            // inside of a phase result.
            return new PhaseResult(runResult);
        }
Example #2
0
        /// <summary>
        /// Call a fluent script function from c#.
        /// </summary>
        /// <param name="context">The context of the call.</param>
        /// <param name="expr">The lambda function</param>
        /// <param name="convertApplicableTypes">Whether or not to convert applicable c# types to fluentscript types, eg. ints and longs to double, List(object) to LArrayType and Dictionary(string, object) to LMapType</param>
        /// <param name="args"></param>
        public static object CallFunctionViaCSharpUsingLambda(Context context, FunctionExpr expr, bool convertApplicableTypes, params object[] args)
        {
            var argsList = args.ToList<object>();
            if (convertApplicableTypes)
                LangTypeHelper.ConvertToLangTypeValues(argsList);
            var execution = new Execution();
            execution.Ctx = context;
            if (EvalHelper.Ctx == null)
                EvalHelper.Ctx = context;

            var result = FunctionHelper.CallFunctionInScript(context, expr, expr.Meta.Name, null, argsList, false, execution);
            return result;
        }
Example #3
0
        /// <summary>
        /// Call a fluent script function from c#.
        /// </summary>
        /// <param name="functionName">The name of the function to call</param>
        /// <param name="convertApplicableTypes">Whether or not to convert applicable c# types to fluentscript types, eg. ints and longs to double, List(object) to LArrayType and Dictionary(string, object) to LMapType</param>
        /// <param name="args"></param>
        public static object CallFunctionViaCSharp(Context context, string functionName, bool convertApplicableTypes, params object[] args)
        {
            var argsList = args.ToList<object>();
            if (convertApplicableTypes)
                LangTypeHelper.ConvertToLangTypeValues(argsList);
            var exists = context.Symbols.IsFunc(functionName);
            if (!exists)
                return null;
            var sym = context.Symbols.GetSymbol(functionName) as SymbolFunction;
            var expr = sym.FuncExpr as FunctionExpr;
            var execution = new Execution();
            execution.Ctx = context;
            if (EvalHelper.Ctx == null)
                EvalHelper.Ctx = context;

            var result = FunctionHelper.CallFunctionInScript(context, expr, functionName, null, argsList, false, execution);
            return result;
        }
Example #4
0
        /// <summary>
        /// Executes the script
        /// </summary>
        /// <param name="script">Script text</param>
        /// <param name="clearExistingCode">Whether or not to clear existing parsed code and start fresh.</param>
        public void Execute(string script, bool clearExistingCode, bool resetScript, params IPhase[] phases)
        {
            this.InitPlugins();
            if(_parser != null)
            {
                var execution = new Execution();
                execution.Ctx = _context;
                EvalHelper.Ctx = _context;
                _parser.OnDemandEvaluator = execution;
            }
            var phaseExecutor = new PhaseExecutor();

            // 1. Create the execution phase
            if (clearExistingCode)
            {
                _phaseCtx = new PhaseContext();
                _phaseCtx.Ctx = _context;
            }
            if (resetScript)
                _phaseCtx.ScriptText = script;

            var phasesList = phases.ToList();
            var result = phaseExecutor.Execute(script, _phaseCtx, _context, phasesList);
            this._runResult = result.Result;
        }