示例#1
0
        public static IElement CreateControlFlowElement(XmlNode node, ControlFlowType type)
        {
            IElement _return = null;

            switch (type)
            {
            case ControlFlowType.If:
                _return = new IfElement(node, CreateElements(node.SelectNodes(DO_NODE)), CreateElements(node.SelectNodes(ELSE_NODE)));
                break;

            case ControlFlowType.ForEach:
                _return = new ForEachElement(node, CreateElements(node.SelectNodes(DO_NODE)));
                break;

            case ControlFlowType.Repeat:
                _return = new RepeatElement(node, CreateElements(node.SelectNodes(DO_NODE)));
                break;

            case ControlFlowType.While:
                break;

            case ControlFlowType.Switch:
                break;

            default:
                break;
            }
            return(_return);
        }
        private void executeForEach(ForEachElement forEachNode)
        {
            string valueOf        = forEachNode.getAttribute(AttributeConstants.VALUE_OF).getValue().ToString();
            string asVariableName = forEachNode.getAttribute(AttributeConstants.AS).getValue().ToString();

            object selectedValue = this._AttributeSelector.valueOf(valueOf);

            if (selectedValue == null)
            {
                throw new Exception("Could not do ForEach, [null] activity return.");
            }

            if (selectedValue.GetType() != typeof(List <string>))
            {
                throw new Exception("Could not do ForEach, expected return-type 'List'.");
            }

            IList <string> list = (IList <string>)selectedValue;

            foreach (var item in list)
            {
                this._stateProvider.getVariables().Add(asVariableName, item);
                IList <IElement> doNodes = forEachNode.DoNodes;

                runRecursive(doNodes);

                this._stateProvider.getVariables().Remove(asVariableName); // remove in memory
            }
        }
        public void Parse(string data, ref TemplateElementContainer parent)
        {
            var regex = @"foreach\(\s*(?<identifier>.*)\s+in\s+(?<source>.*)\s*\)";

            var match = Regex.Match(data, regex);

            if (!match.Success)
            {
                throw new InvalidOperationException($"Unable to parse foreach epxression: {data}");
            }

            var newForeach = new ForEachElement(parent)
            {
                Identifier      = match.Groups["identifier"].Value,
                SourceReference = match.Groups["source"].Value
            };

            parent.Children.Add(newForeach);

            parent = newForeach;
        }