/// <summary> /// Generate a directory tree rooted at <code>rootName</code> /// The number of subtree is in the range of [minWidth, maxWidth]. /// </summary> /// <remarks> /// Generate a directory tree rooted at <code>rootName</code> /// The number of subtree is in the range of [minWidth, maxWidth]. /// The maximum depth of each subtree is in the range of /// [2*maxDepth/3, maxDepth]. /// </remarks> private StructureGenerator.INode GenDirStructure(string rootName, int maxDepth) { StructureGenerator.INode root = new StructureGenerator.INode(rootName); if (maxDepth > 0) { maxDepth--; int minDepth = maxDepth * 2 / 3; // Figure out the number of subdirectories to generate int numOfSubDirs = minWidth + r.Next(maxWidth - minWidth + 1); // Expand the tree for (int i = 0; i < numOfSubDirs; i++) { int childDepth = (maxDepth == 0) ? 0 : (r.Next(maxDepth - minDepth + 1) + minDepth ); StructureGenerator.INode child = GenDirStructure("dir" + i, childDepth); root.AddChild(child); } } return(root); }
/// <summary>Generates a directory tree with a max depth of <code>maxDepth</code></summary> private void GenDirStructure() { root = GenDirStructure(string.Empty, maxDepth); }
/// <summary>Add a child (subdir/file)</summary> private void AddChild(StructureGenerator.INode child) { children.AddItem(child); }