private void FindSubNodesAndAppend(DirNode dnode, Int32 pos, String currPath) { Int32 lvl = currPath.Count(ch => ch == '/'); // Уровень вложенности текущей папки for (Int32 i = pos; i < find.n; i++) { var path = find.GetPath(i); Int32 theLvl = path.Count(ch => ch == '/'); if (theLvl == lvl + 1 && path.StartsWith(currPath)) { String name = path.Substring(currPath.Length + 1); if (IsFile(path, i)) { FileNode fnode = new FileNode { id = find.GetId(i), name = name }; xml.Append(dnode.id, fnode); } else { DirNode node = new DirNode { id = find.GetId(i), name = name }; xml.Append(dnode.id, node); FindSubNodesAndAppend(node, i + 1, currPath + "/" + name); } } } }
public AFormat Transform(AFormat aFormat) { var xml = (XMLFormat)aFormat; DirNode root = (DirNode)xml.GetNode(0); pathInfo.Add(new PathInfo(root.name, root.id)); WorkWithSubNodes(root, root.name); pathInfo.Sort(); return(new FindFormat { n = pathInfo.Count, pathInfo = pathInfo.ToArray() }); }
private void WorkWithSubNodes(DirNode dnode, String currPath) { for (Int32 i = 0; i < dnode.subNodes.Count; i++) { var subNode = dnode.subNodes[i]; pathInfo.Add(new PathInfo(currPath + "/" + subNode.name, subNode.id)); if (subNode is DirNode) { WorkWithSubNodes((DirNode)subNode, currPath + "/" + subNode.name); } } }