public static AddIn Load(TextReader textReader, string hintPath) { try { AddIn addIn = new AddIn(); using (XmlTextReader reader = new XmlTextReader(textReader)) { while (reader.Read()) { if (reader.IsStartElement()) { switch (reader.LocalName) { case "AddIn": addIn.properties = Properties.ReadFromAttributes(reader); SetupAddIn(reader, addIn, hintPath); break; default: throw new AddInLoadException("Unknown add-in file."); } } } } return(addIn); } catch (XmlException ex) { throw new AddInLoadException(ex.Message, ex); } }
public static void SetUp(ExtensionPath extensionPath, XmlReader reader, string endElement) { Stack <ICondition> conditionStack = new Stack <ICondition>(); 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) { extensionPath.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(extensionPath.AddIn, elementName, Properties.ReadFromAttributes(reader), conditionStack.ToArray()); innerCodons.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; } } if (innerCodons.Count > 0) { extensionPath.codons.Add(innerCodons); } }
internal static Runtime Read(AddIn addIn, XmlReader reader, string hintPath, Stack <ICondition> conditionStack) { if (reader.AttributeCount != 1) { throw new AddInLoadException("Import node requires ONE attribute."); } Runtime runtime = new Runtime(reader.GetAttribute(0), hintPath); if (conditionStack.Count > 0) { runtime.conditions = conditionStack.ToArray(); } if (!reader.IsEmptyElement) { while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.EndElement: if (reader.LocalName == "Import") { return(runtime); } break; case XmlNodeType.Element: string nodeName = reader.LocalName; Properties properties = Properties.ReadFromAttributes(reader); switch (nodeName) { case "Doozer": if (!reader.IsEmptyElement) { throw new AddInLoadException("Doozer nodes must be empty!"); } runtime.definedDoozers.Add(new LazyLoadDoozer(addIn, properties)); break; case "ConditionEvaluator": if (!reader.IsEmptyElement) { throw new AddInLoadException("ConditionEvaluator nodes must be empty!"); } runtime.definedConditionEvaluators.Add(new LazyConditionEvaluator(addIn, properties)); break; default: throw new AddInLoadException("Unknown node in Import section:" + nodeName); } break; } } } runtime.definedDoozers = (runtime.definedDoozers as List <LazyLoadDoozer>).AsReadOnly(); runtime.definedConditionEvaluators = (runtime.definedConditionEvaluators as List <LazyConditionEvaluator>).AsReadOnly(); return(runtime); }
public void ReadManifestSection(XmlReader reader, string hintPath) { if (reader.AttributeCount != 0) { throw new AddInLoadException("Manifest node cannot have attributes."); } if (reader.IsEmptyElement) { throw new AddInLoadException("Manifest node cannot be empty."); } while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.EndElement: if (reader.LocalName == "Manifest") { return; } break; case XmlNodeType.Element: string nodeName = reader.LocalName; Properties properties = Properties.ReadFromAttributes(reader); switch (nodeName) { case "Identity": AddIdentity(properties["name"], properties["version"], hintPath); break; case "Dependency": dependencies.Add(AddInReference.Create(properties, hintPath)); break; case "Conflict": conflicts.Add(AddInReference.Create(properties, hintPath)); break; default: throw new AddInLoadException("Unknown node in Manifest section:" + nodeName); } break; } } }