public void Combine(Wz_Node wzNode) { this.LinkNodes.Add(wzNode); bool needCheck = this.ChildNodes.Count > 0; foreach (var fromChild in wzNode.Nodes) { //如果当前本身为空 省去检查合并 因为wz本身并不重复... WzVirtualNode toChild = null; if (needCheck) { toChild = FindChild(fromChild.Text); } if (toChild == null) //没有找到 新增 { this.AddChild(fromChild, true); } else if (fromChild.Value == null && toChild.HasNoValue()) //同为目录 { toChild.Combine(fromChild); } else if (fromChild.Nodes.Count <= 0 && !toChild.HasDirectory()) //没有子集 合并测试 { toChild.Combine(fromChild); } else { throw new Exception(string.Format("Wz merge failed,{0} already exists and has children.", fromChild.FullPathToFile)); } } }
private WzVirtualNode RebuildWzFile(Wz_File wzFile) { //分组 List <Wz_File> subFiles = new List <Wz_File>(); WzVirtualNode topNode = new WzVirtualNode(wzFile.Node); foreach (var childNode in wzFile.Node.Nodes) { var subFile = childNode.GetValue <Wz_File>(); if (subFile != null) //wz子文件 { subFiles.Add(subFile); } else //其他 { topNode.AddChild(childNode, true); } } if (wzFile.Type == Wz_Type.Base) { foreach (var grp in subFiles.GroupBy(f => f.Type)) { WzVirtualNode fileNode = new WzVirtualNode(); fileNode.Name = grp.Key.ToString(); foreach (var file in grp) { fileNode.Combine(file.Node); } topNode.AddChild(fileNode); } } return(topNode); }