static void SetupPlugin(XmlReader reader, Plugin plugin, string hintPath) { while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element && reader.IsStartElement()) { switch (reader.LocalName) { case "StringResources": case "BitmapResources": if (reader.AttributeCount != 1) { throw new PluginLoadException("BitmapResources requires ONE attribute."); } string filename = StringParser.Parse(reader.GetAttribute("file")); if (reader.LocalName == "BitmapResources") { plugin.BitmapResources.Add(filename); } else { plugin.StringResources.Add(filename); } break; case "Runtime": if (!reader.IsEmptyElement) { Runtime.ReadSection(reader, plugin, hintPath); } break; case "Include": if (reader.AttributeCount != 1) { throw new PluginLoadException("Include requires ONE attribute."); } if (!reader.IsEmptyElement) { throw new PluginLoadException("Include nodes must be empty!"); } if (hintPath == null) { throw new PluginLoadException("Cannot use include nodes when hintPath was not specified (e.g. when PluginManager reads a .addin file)!"); } string fileName = Path.Combine(hintPath, reader.GetAttribute(0)); XmlReaderSettings xrs = new XmlReaderSettings(); xrs.ConformanceLevel = ConformanceLevel.Fragment; using (XmlReader includeReader = XmlTextReader.Create(fileName, xrs)) { SetupPlugin(includeReader, plugin, Path.GetDirectoryName(fileName)); } break; case "Path": if (reader.AttributeCount != 1) { throw new PluginLoadException("Import node requires ONE attribute."); } string pathName = reader.GetAttribute(0); ExtensionPath extensionPath = plugin.GetExtensionPath(pathName); if (!reader.IsEmptyElement) { ExtensionPath.SetUp(extensionPath, reader, "Path"); } break; case "Manifest": plugin.Manifest.ReadManifestSection(reader, hintPath); break; default: throw new PluginLoadException("Unknown root path node:" + reader.LocalName); } } } }
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 { Properties properties = Properties.ReadFromAttributes(reader); string extensionType = "Class"; switch (elementName) { case "Extension": string type = properties["type"]; if (!string.IsNullOrEmpty(type)) { extensionType = type; } break; case "Sub": case "Simple": case "String": case "Include": extensionType = elementName; break; default: throw new ApplicationException("Unknown element '" + elementName + "'"); } Extension newExtension = new Extension(extensionPath.Plugin, extensionType, properties, conditionStack.ToArray()); extensionPath.extensions.Add(newExtension); if (!reader.IsEmptyElement) { ExtensionPath subPath = extensionPath.Plugin.GetExtensionPath(extensionPath.Name + "/" + newExtension.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; } } }