Read() public static method

public static Read ( XmlReader reader ) : ICondition
reader System.Xml.XmlReader
return ICondition
示例#1
0
		void DoSetUp(XmlReader reader, string endElement, Stack<ICondition> conditionStack)
		{
			List<Codon> innerCodons = new List<Codon>();
			while (reader.Read()) {
				switch (reader.NodeType) {
					case XmlNodeType.EndElement:
						if (reader.LocalName == "Condition" || reader.LocalName == "ComplexCondition") {
							conditionStack.Pop();
						} else if (reader.LocalName == endElement) {
							if (innerCodons.Count > 0)
								this.codons.Add(innerCodons);
							return;
						}
						break;
					case XmlNodeType.Element:
						string elementName = reader.LocalName;
						if (elementName == "Condition") {
							conditionStack.Push(Condition.Read(reader));
						} else if (elementName == "ComplexCondition") {
							conditionStack.Push(Condition.ReadComplexCondition(reader));
						} else {
							Codon newCodon = new Codon(this.AddIn, elementName, Properties.ReadFromAttributes(reader), conditionStack.ToArray());
							innerCodons.Add(newCodon);
							if (!reader.IsEmptyElement) {
								ExtensionPath subPath = this.AddIn.GetExtensionPath(this.Name + "/" + newCodon.Id);
								subPath.DoSetUp(reader, elementName, conditionStack);
							}
						}
						break;
				}
			}
			if (innerCodons.Count > 0)
				this.codons.Add(innerCodons);
		}
示例#2
0
        public static void SetUp(ExtensionPath extensionPath, XmlReader reader, string endElement)
        {
            Stack <ICondition> stack = new Stack <ICondition>();

            while (reader.Read())
            {
                XmlNodeType nodeType = reader.NodeType;
                if (nodeType != XmlNodeType.Element)
                {
                    if (nodeType == XmlNodeType.EndElement)
                    {
                        if (reader.LocalName == "Condition" || reader.LocalName == "ComplexCondition")
                        {
                            stack.Pop();
                        }
                        else
                        {
                            if (reader.LocalName == endElement)
                            {
                                return;
                            }
                        }
                    }
                }
                else
                {
                    string localName = reader.LocalName;
                    if (localName == "Condition")
                    {
                        stack.Push(Condition.Read(reader));
                    }
                    else
                    {
                        if (localName == "ComplexCondition")
                        {
                            stack.Push(Condition.ReadComplexCondition(reader));
                        }
                        else
                        {
                            Codon codon = new Codon(extensionPath.AddIn, localName, Properties.ReadFromAttributes(reader), stack.ToArray());
                            extensionPath.codons.Add(codon);
                            if (!reader.IsEmptyElement)
                            {
                                ExtensionPath extensionPath2 = extensionPath.AddIn.GetExtensionPath(extensionPath.Name + "/" + codon.Id);
                                ExtensionPath.SetUp(extensionPath2, reader, localName);
                            }
                        }
                    }
                }
            }
        }
示例#3
0
        internal static List <Runtime> ReadSection(XmlReader reader, AddIn addIn, string hintPath)
        {
            List <Runtime>     runtimes       = new List <Runtime>();
            Stack <ICondition> conditionStack = new Stack <ICondition>();

            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                case XmlNodeType.EndElement:
                    if (reader.LocalName == "Condition" || reader.LocalName == "ComplexCondition")
                    {
                        conditionStack.Pop();
                    }
                    else if (reader.LocalName == "Runtime")
                    {
                        return(runtimes);
                    }
                    break;

                case XmlNodeType.Element:
                    switch (reader.LocalName)
                    {
                    case "Condition":
                        conditionStack.Push(Condition.Read(reader, addIn));
                        break;

                    case "ComplexCondition":
                        conditionStack.Push(Condition.ReadComplexCondition(reader, addIn));
                        break;

                    case "Import":
                        runtimes.Add(Runtime.Read(addIn, reader, hintPath, conditionStack));
                        break;

                    case "DisableAddIn":
                        if (Condition.GetFailedAction(conditionStack, addIn) == ConditionFailedAction.Nothing)
                        {
                            // The DisableAddIn node not was not disabled by a condition
                            addIn.CustomErrorMessage = reader.GetAttribute("message");
                        }
                        break;

                    default:
                        throw new AddInLoadException("Unknown node in runtime section :" + reader.LocalName);
                    }
                    break;
                }
            }
            return(runtimes);
        }
示例#4
0
        public static void SetUp(ExtensionPath extensionPath, XmlReader reader, string endElement)
        {
            Stack <ICondition> conditionStack = new Stack <ICondition>();

            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                case XmlNodeType.EndElement:
                    if (reader.LocalName == "Condition" || reader.LocalName == "ComplexCondition")
                    {
                        conditionStack.Pop();
                    }
                    else if (reader.LocalName == endElement)
                    {
                        return;
                    }
                    break;

                case XmlNodeType.Element:
                    string elementName = reader.LocalName;
                    if (elementName == "Condition")
                    {
                        conditionStack.Push(Condition.Read(reader));
                    }
                    else if (elementName == "ComplexCondition")
                    {
                        conditionStack.Push(Condition.ReadComplexCondition(reader));
                    }
                    else
                    {
                        Codon newCodon = new Codon(extensionPath.AddIn, elementName, Properties.ReadFromAttributes(reader), conditionStack.ToArray());
                        extensionPath.codons.Add(newCodon);
                        if (!reader.IsEmptyElement)
                        {
                            ExtensionPath subPath = extensionPath.AddIn.GetExtensionPath(extensionPath.Name + "/" + newCodon.Id);
                            //foreach (ICondition condition in extensionPath.conditionStack) {
                            //	subPath.conditionStack.Push(condition);
                            //}
                            SetUp(subPath, reader, elementName);
                            //foreach (ICondition condition in extensionPath.conditionStack) {
                            //	subPath.conditionStack.Pop();
                            //}
                        }
                    }
                    break;
                }
            }
        }
示例#5
0
        public static ICondition[] ReadConditionList(XmlReader reader, string endElement, AddIn addIn)
        {
            List <ICondition> 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());
        }
示例#6
0
        public static ICondition ReadComplexCondition(XmlReader reader)
        {
            Properties 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);
                        goto exit;

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

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

                    case "Condition":
                        condition = Condition.Read(reader);
                        goto exit;
                    }
                    break;
                }
            }
exit:
            if (condition != null)
            {
                ConditionFailedAction action = properties.Get("action", ConditionFailedAction.Exclude);
                condition.Action = action;
            }
            return(condition);
        }
示例#7
0
        public static ICondition[] ReadConditionList(XmlReader reader, string endElement)
        {
            List <ICondition> 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));
                        break;

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

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

                    case "Condition":
                        conditions.Add(Condition.Read(reader));
                        break;
                    }
                    break;
                }
            }
            return(conditions.ToArray());
        }
示例#8
0
        internal static void ReadSection(XmlReader reader, AddIn addIn, string hintPath)
        {
            Stack <ICondition> stack = new Stack <ICondition>();

            while (reader.Read())
            {
                XmlNodeType nodeType = reader.NodeType;
                if (nodeType != XmlNodeType.Element)
                {
                    if (nodeType == XmlNodeType.EndElement)
                    {
                        if (reader.LocalName == "Condition" || reader.LocalName == "ComplexCondition")
                        {
                            stack.Pop();
                        }
                        else
                        {
                            if (reader.LocalName == "Runtime")
                            {
                                return;
                            }
                        }
                    }
                }
                else
                {
                    string localName;
                    if ((localName = reader.LocalName) != null)
                    {
                        if (!(localName == "Condition"))
                        {
                            if (!(localName == "ComplexCondition"))
                            {
                                if (!(localName == "Import"))
                                {
                                    if (localName == "DisableAddIn")
                                    {
                                        if (Condition.GetFailedAction(stack, addIn) == ConditionAction.Nothing)
                                        {
                                            addIn.CustomErrorMessage = reader.GetAttribute("message");
                                        }
                                    }
                                }
                                else
                                {
                                    addIn.Runtimes.Add(Runtime.Read(addIn, reader, hintPath, stack));
                                }
                            }
                            else
                            {
                                stack.Push(Condition.ReadComplexCondition(reader));
                            }
                        }
                        else
                        {
                            stack.Push(Condition.Read(reader));
                        }
                    }
                }
            }
        }