ExtensionXml DoReadExtension(XmlNode node, string extensionPointId, string parentPath) { if (node.NodeType != XmlNodeType.Element || node.Attributes == null || node.Attributes.Count == 0) { return(null); } var head = new ExtensionHeadXml { // get the extension builder path. this must be as the same as the ExtensionBuilder.Path ExtensionBuilderPath = extensionPointId + SysConstants.PathSeparator + XmlHelper.GetNodeName(node), ParentPath = parentPath }; var data = new ExtensionDataXml(); for (int i = 0; i < node.Attributes.Count; i++) { // no repeated definition now (e.g, one xml node has 2 id attribute defined) var attrib = node.Attributes[i]; if (head.Id == null && XmlHelper.AttribueNameEquals(attrib, AttributeId)) { head.Id = XmlHelper.GetAttribueValue(attrib) ?? i.ToString(); } else if (head.SiblingId == null && (XmlHelper.AttribueNameEquals(attrib, AttributeInsertBefore) || XmlHelper.AttribueNameEquals(attrib, AttributeInsertAfter))) { if (XmlHelper.AttribueNameEquals(attrib, AttributeInsertBefore)) { head.SiblingId = XmlHelper.GetAttribueValue(attrib); head.RelativePosition = RelativePosition.Before; } else if (XmlHelper.AttribueNameEquals(attrib, AttributeInsertAfter)) { head.SiblingId = XmlHelper.GetAttribueValue(attrib); head.RelativePosition = RelativePosition.After; } } else { data.Add(XmlHelper.GetAttribueName(attrib), XmlHelper.GetAttribueValue(attrib)); } } return(new ExtensionXml { Head = head, Data = data }); }
ExtensionXml DoReadExtension(XmlNode node, string extensionPointPath, string parentPath) { if (node.NodeType != XmlNodeType.Element)// || node.Attributes == null || node.Attributes.Count == 0) { return(null); } var head = new ExtensionHeadXml { // get the extension builder path. this must be as the same as the ExtensionBuilder.Path ExtensionBuilderPath = extensionPointPath + SysConstants.PathSeparator + XmlHelper.GetNodeName(node), ParentPath = parentPath }; if (node.Attributes == null || node.Attributes.Count == 0) { return new ExtensionXml { Head = head } } ; var data = new ExtensionDataXml(); for (int i = 0; i < node.Attributes.Count; i++) { // no repeated definition now (e.g, one xml node has 2 id attribute defined) var attrib = node.Attributes[i]; if (head.Id == null && XmlHelper.AttribueNameEquals(attrib, AttributeId)) { head.Id = XmlHelper.GetAttribueValue(attrib) ?? i.ToString(); } else if (head.SiblingId == null && (XmlHelper.AttribueNameEquals(attrib, AttributeInsertBefore) || XmlHelper.AttribueNameEquals(attrib, AttributeInsertAfter))) { if (XmlHelper.AttribueNameEquals(attrib, AttributeInsertBefore)) { head.SiblingId = XmlHelper.GetAttribueValue(attrib); head.RelativePosition = RelativePosition.Before; } else if (XmlHelper.AttribueNameEquals(attrib, AttributeInsertAfter)) { head.SiblingId = XmlHelper.GetAttribueValue(attrib); head.RelativePosition = RelativePosition.After; } } else { data.Add(XmlHelper.GetAttribueName(attrib), XmlHelper.GetAttribueValue(attrib)); } } return(new ExtensionXml { Head = head, Data = data }); } void DoReadExtensionRecursively(XmlNode node, string extensionPointPath, ExtensionXml parent) { var extension = DoReadExtension(node, extensionPointPath, parent.Head.Path); if (extension == null) { return; } parent.AddChild(extension); if (node.HasChildNodes) { for (int i = 0; i < node.ChildNodes.Count; i++) { DoReadExtensionRecursively(node.ChildNodes[i], extensionPointPath, extension); } } } bool TryReadFiles(string addinDir, out List <AssemblyFileXml> assemblyFiles, out List <DataFileXml> dataFiles) { assemblyFiles = null; dataFiles = null; if (_filesNode == null || _filesNode.NodeType != XmlNodeType.Element || !_filesNode.HasChildNodes) { return(false); } for (int i = 0; i < _filesNode.ChildNodes.Count; i++) { var childNode = _filesNode.ChildNodes[i]; var path = XmlHelper.GetMatchingAttribueValue(childNode, AttributePath); string fullPath; if (Path.IsPathRooted(path)) { if (!File.Exists(path)) { continue; } fullPath = path; path = IoHelper.GetRelativePath(path, addinDir); } else { fullPath = Path.Combine(addinDir, path); if (!File.Exists(fullPath)) { continue; } } if (XmlHelper.IsMatchingNode(childNode, NodeFile)) { var dtFile = new DataFileXml { FilePath = path }; dataFiles = dataFiles ?? new List <DataFileXml>(); dataFiles.Add(dtFile); } else if (XmlHelper.IsMatchingNode(childNode, NodeAssembly)) { var asmFile = new AssemblyFileXml { FilePath = path, LastWriteTime = IoHelper.GetLastWriteTime(fullPath) }; assemblyFiles = assemblyFiles ?? new List <AssemblyFileXml>(); assemblyFiles.Add(asmFile); } } return(assemblyFiles != null || dataFiles != null); }