private DefaultAddInTreeNode CreateTreeNode(DefaultAddInTreeNode parentNode, string path) { if (path == null || path.Length == 0) { return(parentNode); } string[] splittedPath = path.Split(new char[] { '/' }); DefaultAddInTreeNode currentNode = parentNode; int i = 0; while (i < splittedPath.Length) { DefaultAddInTreeNode childNode = (DefaultAddInTreeNode)currentNode.ChildNodes[splittedPath[i]]; if (childNode == null) { childNode = new DefaultAddInTreeNode(); childNode.Path = splittedPath[i]; currentNode.ChildNodes[splittedPath[i]] = childNode; childNode.Parent = currentNode; } currentNode = childNode; ++i; } return(currentNode); }
/// <summary> /// Create a tree node /// </summary> /// <param name="currentNode">the local root node in the add in tree</param> /// <param name="path">the path of the node</param> /// <returns></returns> DefaultAddInTreeNode CreateTreeNode(DefaultAddInTreeNode currentNode, string path) { if (path == null || path.Length == 0) { return(currentNode); } string[] splittedPath = path.Split(new char[] { '/' }); DefaultAddInTreeNode curNode = currentNode; int i = 0; //逐层创建要创建的节点,如果某层的节点未创建,则创建之,并作为当前节点的子节点; //如果已经创建了该节点,则直接将该节点作为当前节点 while (i < splittedPath.Length) { DefaultAddInTreeNode childNode = (DefaultAddInTreeNode)curNode.ChildNodes[splittedPath[i]]; if (childNode == null) { childNode = new DefaultAddInTreeNode(); curNode.ChildNodes[splittedPath[i]] = childNode; } curNode = childNode; ++i; } return(curNode); }
/// <summary> /// Create a tree node /// </summary> /// <param name="currentNode">the local root node in the add in tree</param> /// <param name="path">the path of the node</param> /// <returns></returns> DefaultAddInTreeNode CreateTreeNode(DefaultAddInTreeNode currentNode, string path) { if (path == null || path.Length == 0) { return currentNode; } string[] splittedPath = path.Split(new char[] {'/'}); DefaultAddInTreeNode curNode = currentNode; int i = 0; //逐层创建要创建的节点,如果某层的节点未创建,则创建之,并作为当前节点的子节点; //如果已经创建了该节点,则直接将该节点作为当前节点 while (i < splittedPath.Length) { DefaultAddInTreeNode childNode = (DefaultAddInTreeNode)curNode.ChildNodes[splittedPath[i]]; if (childNode == null) { childNode = new DefaultAddInTreeNode(); curNode.ChildNodes[splittedPath[i]] = childNode; } curNode = childNode; ++i; } return curNode; }
private DefaultAddInTreeNode CreateTreeNode(DefaultAddInTreeNode parentNode, string path) { if (path == null || path.Length == 0) { return parentNode; } string[] splittedPath = path.Split(new char[] {'/'}); DefaultAddInTreeNode currentNode = parentNode; int i = 0; while (i < splittedPath.Length) { DefaultAddInTreeNode childNode = (DefaultAddInTreeNode)currentNode.ChildNodes[splittedPath[i]]; if (childNode == null) { childNode = new DefaultAddInTreeNode(); childNode.Path = splittedPath[i]; currentNode.ChildNodes[splittedPath[i]] = childNode; childNode.Parent = currentNode; } currentNode = childNode; ++i; } return currentNode; }
private void AddExtensions(AddIn.Extension extension) { DefaultAddInTreeNode localRoot = CreateTreeNode(root, extension.Path); foreach (ICodon codon in extension.CodonCollection) { DefaultAddInTreeNode treeNode = CreateTreeNode(localRoot, codon.ID); if (treeNode.Codon != null) { throw new DuplicateCodonException(codon.ID); } treeNode.Codon = codon; treeNode.ConditionCollection = (ConditionCollection)extension.Conditions[codon.ID]; } }
/// <summary> /// Add a <see cref="AddIn"/> object to the tree, inserting all it's extensions. /// </summary> public void InsertAddIn(AddIn addIn) { addIns.Add(addIn); foreach (AddIn.Extension extension in addIn.Extensions) { //先根据一个如<Extension path = "/Workspace/Services">之类的extension.Path扩展路径创建一个节点 DefaultAddInTreeNode currentNode = CreateTreeNode(root, extension.Path); //然后对该扩展路径下的代码子集合列表进行迭代,分别创建为currentNode的子节点,以构成一个树状结构 foreach (ICodon codon in extension.CodonCollection) { DefaultAddInTreeNode currentChildNode = CreateTreeNode(currentNode, codon.ID); if (currentChildNode.Codon != null) { throw new Exception("已经存在一个名为 : " + codon.ID + " 的代码子"); } currentChildNode.Codon = codon; } } }
public IAddInTreeNode GetTreeNode(string path) { if (path == null || path.Length == 0) { return(root); } string[] splittedPath = path.Split(new char[] { '/' }); DefaultAddInTreeNode currentNode = root; int i = 0; while (i < splittedPath.Length) { DefaultAddInTreeNode childNode = (DefaultAddInTreeNode)currentNode.ChildNodes[splittedPath[i]]; if (childNode == null) { throw new TreePathNotFoundException(path); } currentNode = childNode; ++i; } return(currentNode); }
/// <summary> /// Searches a requested path and returns the TreeNode in this path as value. /// If path is <code>null</code> or path.Length is zero the root node is returned. /// </summary> /// <param name="path"> /// The path inside the tree structure. /// </param> /// <exception cref="TreePathNotFoundException"> /// Is thrown when the path is not found in the tree. /// </exception> public IAddInTreeNode GetTreeNode(string path) { if (path == null || path.Length == 0) { return(root); } string[] splittedPath = path.Split(new char[] { '/' }); DefaultAddInTreeNode curPath = root; //每次要找某个节点的路径时,都是从根节点出发 int i = 0; while (i < splittedPath.Length) { DefaultAddInTreeNode nextPath = (DefaultAddInTreeNode)curPath.ChildNodes[splittedPath[i]]; if (nextPath == null) { throw new Exception("插件树路径没有找到 : " + path); } curPath = nextPath; ++i; } return(curPath); //返回找到的插件树中的逻辑路径,一个结点 }
private DefaultAddInTreeNode CreateTreeNode(DefaultAddInTreeNode localRoot, string path) { if (path == null || path.Length == 0) { return(localRoot); } string[] splittedPath = path.Split(new char[] { '/' }); DefaultAddInTreeNode curNode = localRoot; int i = 0; while (i < splittedPath.Length) { DefaultAddInTreeNode nextNode = (DefaultAddInTreeNode)curNode.ChildNodes[splittedPath[i]]; if (nextNode == null) { curNode.ChildNodes[splittedPath[i]] = nextNode = new DefaultAddInTreeNode(); } curNode = nextNode; ++i; } return(curNode); }