Esempio n. 1
0
        /// Execute action
        public override object Execute()
        {
            string id = Context.TransformStr(SubId, Transform);
            Sub    f  = Context.Find <Sub>(id);

            if (f == null)
            {
                throw new ParsingException("A subroutine with id=" + id + " not found");
            }

            var cp = new List <CallParam>();

            if (Value != null)
            {
                var o = GetTransformedValue();
                if (o is Array)
                {
                    foreach (var elem in (Array)o)
                    {
                        cp.Add(new CallParam(null, elem, TransformRules.None));
                    }
                }
                else
                {
                    List <string> p = new List <string>();
                    string        v = Utils.To <string>(o);
                    if (!string.IsNullOrEmpty(v))
                    {
                        p.AddRange(Utils.SplitArgs(v));
                    }
                    foreach (var o1 in p)
                    {
                        cp.Add(new CallParam(null, o1, TransformRules.None));
                    }
                }
            }
            if (Parameters != null)
            {
                cp.AddRange(Parameters);
            }
            object r = Context.ExecuteAction(f, cp, Isolation);

            Context.OutTo(OutTo, ReturnValue.Unwrap(r));
            return(null);
        }
Esempio n. 2
0
        /// <summary>
        /// Execute script action
        /// </summary>
        /// <param name="action">action to execute</param>
        /// <param name="args">list of parameters, in case the action is Call</param>
        /// <param name="isolation">isolation</param>
        /// <returns>action result</returns>
        public object ExecuteAction(IScriptAction action, IEnumerable <CallParam> args, CallIsolation isolation)
        {
            Vars snapshot = null;

            if (isolation != CallIsolation.None)
            {
                snapshot = new Vars(this);
            }
            try
            {
                // Clear vars
                if (isolation == CallIsolation.High)
                {
                    base.Clear();
                }


                return(RunOnStack(ScriptOperation.Executing, action, delegate
                {
                    Sub sub = action as Sub;
                    if (sub != null)
                    {
                        return sub.ExecuteSub(args);
                    }
                    return action.Execute();
                }));
            }
            finally
            {
                if (snapshot != null)
                {
                    base.Clear();
                    AddRange(snapshot);
                }
            }
        }