Exemple #1
0
        public static ICondition[] ReadConditionList(XmlReader reader, string endElement, AddIn addIn)
        {
            var conditions = new List <ICondition>();

            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                case XmlNodeType.EndElement:
                    if (reader.LocalName == endElement)
                    {
                        return(conditions.ToArray());
                    }
                    break;

                case XmlNodeType.Element:
                    switch (reader.LocalName)
                    {
                    case "And":
                        conditions.Add(AndCondition.Read(reader, addIn));
                        break;

                    case "Or":
                        conditions.Add(OrCondition.Read(reader, addIn));
                        break;

                    case "Not":
                        conditions.Add(NegatedCondition.Read(reader, addIn));
                        break;

                    case "Condition":
                        conditions.Add(Condition.Read(reader, addIn));
                        break;

                    default:
                        throw new AddInLoadException("Invalid element name '" + reader.LocalName
                                                     + "', entries in a <" + endElement + "> " +
                                                     "must be <And>, <Or>, <Not> or <Condition>");
                    }
                    break;
                }
            }
            return(conditions.ToArray());
        }
Exemple #2
0
        public static ICondition ReadComplexCondition(XmlReader reader, AddIn addIn)
        {
            var properties = Properties.ReadFromAttributes(reader);

            reader.Read();
            ICondition condition = null;

            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                case XmlNodeType.Element:
                    switch (reader.LocalName)
                    {
                    case "And":
                        condition = AndCondition.Read(reader, addIn);
                        goto exit;

                    case "Or":
                        condition = OrCondition.Read(reader, addIn);
                        goto exit;

                    case "Not":
                        condition = NegatedCondition.Read(reader, addIn);
                        goto exit;

                    default:
                        throw new AddInLoadException("Invalid element name '" + reader.LocalName
                                                     + "', the first entry in a ComplexCondition " +
                                                     "must be <And>, <Or> or <Not>");
                    }
                }
            }
exit:
            if (condition != null)
            {
                ConditionFailedAction action = properties.Get("action", ConditionFailedAction.Exclude);
                condition.Action = action;
            }
            return(condition);
        }