Esempio n. 1
0
        ICondition GetCondition(XmlElement el)
        {
            ConditionCollection conditions = new ConditionCollection();

            foreach (XmlElement child in el.ChildNodes) {
                conditions.Add(GetCondition(child));
            }

            switch (el.Name) {
                case "Condition":
                    if (conditions.Count > 0) {
                        throw new AddInTreeFormatException("Condition node childs found. (doesn't make sense)");
                    }
                    ICondition c = AddInTreeSingleton.AddInTree.ConditionFactory.CreateCondition(this, el);
                    AutoInitializeAttributes(c, el);
                    return c;
                case "And":
                    if (conditions.Count <= 1) {
                        throw new AddInTreeFormatException("And node with none or only one child found.");
                    }
                    return new AndCondition(conditions);
                case "Or":
                    if (conditions.Count <= 1) {
                        throw new AddInTreeFormatException("Or node with none or only one child found.");
                    }
                    return new OrCondition(conditions);
                case "Not":
                    if (conditions.Count > 1) {
                        throw new AddInTreeFormatException("Not node with more than one child found");
                    }
                    if (conditions.Count == 0) {
                        throw new AddInTreeFormatException("Not node without child found.");
                    }
                    return new NegatedCondition(conditions);
            }

            throw new AddInTreeFormatException("node " + el.Name + " not valid in expression.");
        }
Esempio n. 2
0
        void AddCodonsToExtension(Extension e, XmlElement el, ConditionCollection conditions)
        {
            foreach (object o in el.ChildNodes) {
                if (!(o is XmlElement)) {
                    continue;
                }
                XmlElement curEl = (XmlElement)o;

                switch (curEl.Name) {
                    case "And": // these nodes are silently ignored.
                    case "Or":
                    case "Not":
                    case "Condition":
                        break;
                    case "Conditional":
                        ICondition condition = null;

                        // construct condition
                        if (curEl.Attributes.Count == 0 || (curEl.Attributes.Count == 1 && curEl.Attributes["action"] != null)) {
                            condition = BuildComplexCondition(curEl);

                            // set condition action manually
                            if (curEl.Attributes["action"] != null) {
                                condition.Action = (ConditionFailedAction)Enum.Parse(typeof(ConditionFailedAction), curEl.Attributes["action"].InnerText);
                            }

                            if (condition == null) {
                                throw new AddInTreeFormatException("empty conditional, but no condition definition found.");
                            }
                        } else {
                            condition = AddInTreeSingleton.AddInTree.ConditionFactory.CreateCondition(this, curEl);
                            AutoInitializeAttributes(condition, curEl);
                        }

                        // put the condition at the end of the condition 'stack'
                        conditions.Add(condition);

                        // traverse the subtree
                        AddCodonsToExtension(e, curEl, conditions);

                        // now we are back to the old level, remove the condition
                        // that was applied to the subtree.
                        conditions.RemoveAt(conditions.Count - 1);
                        break;
                    default:
                        ICodon codon = AddInTreeSingleton.AddInTree.CodonFactory.CreateCodon(this, curEl);

                        AutoInitializeAttributes(codon, curEl);

                        // Ensure that the codon is inserted after the codon which is defined
                        // before in the add-in definition.
                        // The codons get topologically sorted and if I don't set the InsertAfter they may
                        // change it's sorting order.
                        e.Conditions[codon.ID] = new ConditionCollection(conditions);
                        if (codon.InsertAfter == null && codon.InsertBefore == null && e.CodonCollection.Count > 0) {
                            codon.InsertAfter = new string[] { ((ICodon)e.CodonCollection[e.CodonCollection.Count - 1]).ID };
                        }

                        e.CodonCollection.Add(codon);
                        if (curEl.ChildNodes.Count > 0) {
                            Extension newExtension = new Extension(e.Path + '/' + codon.ID);
                            AddCodonsToExtension(newExtension, curEl, conditions);
                            extensions.Add(newExtension);
                        }
                        break;
                }
            }
        }