Exemplo n.º 1
0
        private XMLResult ExecWhile(XElement xElem, XMLContext context)
        {
            var test = (String)xElem.Attribute("test");

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

            var subContent = new XMLContext(context);

            while (EvalLogic(test, context))
            {
                var xmlResult = ExecContent(xElem, subContent);

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

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

            subContent.Clear();
            return(null);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
        private XMLResult ExecCheck(XElement xElem, XMLContext context)
        {
            var ifXElem = xElem.Element("if");

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

            var elseifsXElems = xElem.Elements("elseif");
            var elseXElem     = xElem.Element("else");

            var ifTest = (String)ifXElem.Attribute("test");

            var ifRes = EvalLogic(ifTest, context);

            if (ifRes)
            {
                var subContent = new XMLContext(context);
                var xmlResult  = ExecContent(ifXElem, subContent);

                subContent.Clear();
                return(xmlResult);
            }

            foreach (var elseifsXElem in elseifsXElems)
            {
                var elseIfTest = (String)elseifsXElem.Attribute("test");

                var elseIfRes = EvalLogic(elseIfTest, context);
                if (elseIfRes)
                {
                    var subContent = new XMLContext(context);
                    var xmlResult  = ExecContent(elseifsXElem, subContent);

                    subContent.Clear();
                    return(xmlResult);
                }
            }

            if (elseXElem != null)
            {
                var subContent = new XMLContext(context);
                var xmlResult  = ExecContent(elseXElem, subContent);

                subContent.Clear();
                return(xmlResult);
            }

            return(null);
        }
Exemplo n.º 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);
        }