コード例 #1
0
        private XMLResult ExecCall(XElement xElem, XMLContext context)
        {
            var name   = (String)xElem.Attribute("name");
            var result = (String)xElem.Attribute("result");

            var @params = new XMLContext(_globalContext);

            foreach (var paramXElem in xElem.Elements("param"))
            {
                var paramName  = (String)paramXElem.Attribute("name");
                var paramValue = CreateVarValue(paramXElem, context);

                @params.SetValue(paramName, paramValue);
            }

            XElement methodXElem;

            if (!_methods.TryGetValue(name, out methodXElem))
            {
                throw new Exception();
            }

            var xmlReturn = ExecContent(methodXElem, @params) as XMLReturn;

            if (!String.IsNullOrWhiteSpace(result))
            {
                if (xmlReturn != null)
                {
                    context.SetValue(result, xmlReturn.Value);
                }
            }

            return(null);
        }
コード例 #2
0
        private XMLResult ExecSet(XElement xElem, XMLContext context)
        {
            var name = (String)xElem.Attribute("name");

            if (String.IsNullOrWhiteSpace(name))
            {
                throw new Exception();
            }

            var value  = (String)xElem.Attribute("value");
            var varVal = (Object)null;

            if (!String.IsNullOrWhiteSpace(value))
            {
                varVal = EvalObj(value, context);
            }
            else
            {
                var type = (String)xElem.Attribute("type");
                if (type == "list")
                {
                    varVal = new ArrayList();
                }
            }

            context.SetValue(name, varVal);
            return(null);
        }
コード例 #3
0
        private XMLResult ExecFor(XElement xElem, XMLContext context)
        {
            var @var  = (String)xElem.Attribute("var");
            var start = (String)xElem.Attribute("start");
            var end   = (String)xElem.Attribute("end");
            var step  = (String)xElem.Attribute("step");

            if (String.IsNullOrWhiteSpace(@var))
            {
                throw new Exception();
            }

            var startVal = Convert.ToString(EvalObj(start, context));
            var endVal   = Convert.ToString(EvalObj(end, context));
            var stepVal  = Convert.ToString(EvalObj(step, context));

            double startDbl;

            if (!double.TryParse(startVal, NumberStyles.Any, NumberFormatInfo.CurrentInfo, out startDbl))
            {
                throw new Exception();
            }

            double endDbl;

            if (!double.TryParse(endVal, NumberStyles.Any, NumberFormatInfo.CurrentInfo, out endDbl))
            {
                throw new Exception();
            }

            double stepDbl;

            if (!double.TryParse(stepVal, NumberStyles.Any, NumberFormatInfo.CurrentInfo, out stepDbl))
            {
                stepDbl = 1D;
            }

            var subContent = new XMLContext(context);

            for (double i = startDbl; i < endDbl; i += stepDbl)
            {
                subContent.SetValue(@var, i);

                var xmlResult = ExecContent(xElem, subContent);

                if (ReferenceEquals(xmlResult, XMLBreak.Value))
                {
                    break;
                }

                if (xmlResult != null)
                {
                    return(xmlResult);
                }
            }

            subContent.Clear();
            return(null);
        }
コード例 #4
0
        private XMLResult ExecForEach(XElement xElem, XMLContext context)
        {
            var @var = (String)xElem.Attribute("var");

            if (String.IsNullOrWhiteSpace(@var))
            {
                throw new Exception();
            }

            var items = (String)xElem.Attribute("items");

            if (String.IsNullOrWhiteSpace(items))
            {
                throw new Exception();
            }

            var list = EvalObj(items, context) as IEnumerable;

            if (list == null)
            {
                throw new Exception();
            }

            var subContent = new XMLContext(context);

            foreach (var item in items)
            {
                subContent.SetValue(@var, item);

                var xmlResult = ExecContent(xElem, subContent);

                if (ReferenceEquals(xmlResult, XMLBreak.Value))
                {
                    break;
                }

                if (xmlResult != null)
                {
                    return(xmlResult);
                }
            }

            subContent.Clear();
            return(null);
        }
コード例 #5
0
        public Object Exec(IDictionary <String, Object> context)
        {
            if (context != null)
            {
                foreach (var pair in context)
                {
                    _globalContext.SetValue(pair.Key, pair.Value);
                }
            }

            var xmlReturn = ExecContent(_rootXElem, _globalContext) as XMLReturn;

            if (xmlReturn != null)
            {
                return(xmlReturn.Value);
            }

            return(null);
        }