예제 #1
0
        //=====================================================================

        /// <inheritdoc />
        public override void Initialize(XPathNavigator configuration)
        {
            // get the condition
            XPathNavigator condition_element = configuration.SelectSingleNode("switch");

            if (condition_element == null)
            {
                throw new ConfigurationErrorsException("You must specify a condition using the <switch> statement with a 'value' attribute.");
            }

            string condition_value = condition_element.GetAttribute("value", String.Empty);

            if (String.IsNullOrEmpty(condition_value))
            {
                throw new ConfigurationErrorsException("The switch statement must have a 'value' attribute, which is an xpath expression.");
            }

            condition = XPathExpression.Compile(condition_value);

            // load the component stacks for each case
            XPathNodeIterator case_elements = configuration.Select("case");

            foreach (XPathNavigator case_element in case_elements)
            {
                string case_value = case_element.GetAttribute("value", String.Empty);

                cases.Add(case_value, BuildAssembler.LoadComponents(case_element));
            }
        }
예제 #2
0
        /// <inheritdoc />
        public override void Initialize(XPathNavigator configuration)
        {
            // Get the condition
            XPathNavigator conditionElement = configuration.SelectSingleNode("switch");

            if (conditionElement == null)
            {
                throw new ConfigurationErrorsException("You must specify a condition using the <switch> statement with a 'value' attribute.");
            }

            string conditionValue = conditionElement.GetAttribute("value", String.Empty);

            if (String.IsNullOrEmpty(conditionValue))
            {
                throw new ConfigurationErrorsException("The switch statement must have a 'value' attribute, which is an xpath expression.");
            }

            condition = XPathExpression.Compile(conditionValue);

            // Load the component stacks for each case
            XPathNodeIterator caseElements = configuration.Select("case");

            foreach (XPathNavigator caseElement in caseElements)
            {
                string caseValue = caseElement.GetAttribute("value", String.Empty);

                this.WriteMessage(MessageLevel.Info, "Loading components for " + caseValue + " case");

                cases.Add(caseValue, BuildAssembler.LoadComponents(caseElement));
            }

            // Set a default group ID
            this.GroupId = null;
        }
예제 #3
0
        /// <summary>
        /// Initializes new instance of the <see cref="CloneComponent"/> class with
        /// the specified parameters.
        /// </summary>
        /// <param name="assembler"></param>
        /// <param name="configuration"></param>
        public CloneComponent(BuildAssembler assembler, XPathNavigator configuration)
            : base(assembler, configuration)
        {
            try
            {
                _listBranches = new List <IList <BuildComponent> >();

                // Select and process all the branches...
                XPathNodeIterator branchNodes = configuration.Select("branch");
                if (branchNodes != null && branchNodes.Count != 0)
                {
                    foreach (XPathNavigator branchNode in branchNodes)
                    {
                        IList <BuildComponent> components = assembler.LoadComponents(branchNode);
                        if (components != null && components.Count != 0)
                        {
                            _listBranches.Add(components);
                        }
                    }
                }

                // Select and process the "default" node, only one is expected...
                XPathNavigator defaultNode = configuration.SelectSingleNode("default");
                if (defaultNode != null)
                {
                    _defaultBranch = assembler.LoadComponents(defaultNode);
                }

                // For the special case where neither "branch" nor "default" is
                // specified, we treat anything there as default...
                if ((branchNodes == null || branchNodes.Count == 0) &&
                    defaultNode == null)
                {
                    _defaultBranch = assembler.LoadComponents(configuration);
                }
            }
            catch (Exception ex)
            {
                this.WriteMessage(MessageLevel.Error, ex);
            }
        }
예제 #4
0
        /// <inheritdoc />
        public override void Initialize(XPathNavigator configuration)
        {
            // Get the context namespaces
            XPathNodeIterator contextNodes = configuration.Select("context");

            foreach (XPathNavigator contextNode in contextNodes)
            {
                contextNamespaces[contextNode.GetAttribute("prefix", String.Empty)] =
                    contextNode.GetAttribute("name", String.Empty);
            }

            // Get the condition
            XPathNavigator ifNode = configuration.SelectSingleNode("if");

            if (ifNode == null)
            {
                throw new ConfigurationErrorsException("You must specify a condition using the <if> element.");
            }

            string conditionXPath = ifNode.GetAttribute("condition", String.Empty);

            if (String.IsNullOrEmpty(conditionXPath))
            {
                throw new ConfigurationErrorsException("You must define a condition attribute on the <if> element");
            }

            condition = XPathExpression.Compile(conditionXPath);

            // Construct the true branch
            XPathNavigator thenNode = configuration.SelectSingleNode("then");

            if (thenNode != null)
            {
                trueBranch = BuildAssembler.LoadComponents(thenNode);
            }

            // Construct the false branch
            XPathNavigator elseNode = configuration.SelectSingleNode("else");

            if (elseNode != null)
            {
                falseBranch = BuildAssembler.LoadComponents(elseNode);
            }

            // Set a default group ID
            this.GroupId = null;
        }
예제 #5
0
        //=====================================================================

        /// <inheritdoc />
        public override void Initialize(XPathNavigator configuration)
        {
            // set up the context
            XPathNodeIterator context_nodes = configuration.Select("context");

            foreach (XPathNavigator context_node in context_nodes)
            {
                string prefix = context_node.GetAttribute("prefix", String.Empty);
                string name   = context_node.GetAttribute("name", String.Empty);
                context.AddNamespace(prefix, name);
            }

            // load the expression format
            XPathNavigator variable_node = configuration.SelectSingleNode("variable");

            if (variable_node == null)
            {
                throw new ConfigurationErrorsException("When instantiating a ForEach component, you must " +
                                                       "specify a variable using the <variable> element.");
            }

            string xpath_format = variable_node.GetAttribute("expression", String.Empty);

            if ((xpath_format == null) || (xpath_format.Length == 0))
            {
                throw new ConfigurationErrorsException("When instantiating a ForEach component, you must " +
                                                       "specify a variable expression using the expression attribute");
            }

            xpath = XPathExpression.Compile(xpath_format);

            // load the subcomponents
            WriteMessage(MessageLevel.Info, "Loading subcomponents.");
            XPathNavigator components_node = configuration.SelectSingleNode("components");

            if (components_node == null)
            {
                throw new ConfigurationErrorsException("When instantiating a ForEach component, you must " +
                                                       "specify subcomponents using the <components> element.");
            }

            components = BuildAssembler.LoadComponents(components_node);

            WriteMessage(MessageLevel.Info, "Loaded {0} subcomponents.", components.Count());
        }
        //=====================================================================

        /// <inheritdoc />
        public override void Initialize(XPathNavigator configuration)
        {
            // Get the condition
            XPathNavigator if_node = configuration.SelectSingleNode("if");

            if (if_node == null)
            {
                throw new ConfigurationErrorsException("You must specify a condition using the <if> element.");
            }

            string condition_xpath = if_node.GetAttribute("condition", String.Empty);

            if (String.IsNullOrEmpty(condition_xpath))
            {
                throw new ConfigurationErrorsException("You must define a condition attribute on the <if> element");
            }

            condition = XPathExpression.Compile(condition_xpath);

            // Construct the true branch
            XPathNavigator then_node = configuration.SelectSingleNode("then");

            if (then_node != null)
            {
                true_branch = BuildAssembler.LoadComponents(then_node);
            }

            // Construct the false branch
            XPathNavigator else_node = configuration.SelectSingleNode("else");

            if (else_node != null)
            {
                false_branch = BuildAssembler.LoadComponents(else_node);
            }

            // Keep a pointer to the context for future use
            context = this.BuildAssembler.Context;
        }