public static void GetAllChildFolders(TreeNode node, List<string> result) { if (node.Folder != null) { result.Add(node.Folder.FolderId); foreach (var child in node.Childrens) { GetAllChildFolders(child, result); } } }
public static TreeNode FindFolderId(TreeNode node, string folderId) { if (node.FolderId == folderId) return node; foreach (var child in node.Childrens) { var result = FindFolderId(child, folderId); if (result != null) return result; } return null; }
public static List<string> GetAllFoldersAndChildFolders(TreeNode root, List<string> folderIds) { HashSet<string> result = new HashSet<string>(folderIds); foreach (var id in folderIds) { var eachResult = GetAllFoldersAndChildFolders(root, id); foreach (var eachid in eachResult) { if (!result.Contains(eachid)) { result.Add(eachid); } } } return result.ToList(); }
public static void DepthFirstTraverseTree(TreeNode root, FuncForDealEachNodeWhenDepthFirstTraverse func) { DepthFirstTraverseTree(root, 0, func); }
private static void DepthFirstTraverseTree(TreeNode node, int depth, FuncForDealEachNodeWhenDepthFirstTraverse func) { int childCount = 0; foreach(var child in node.Childrens) { DepthFirstTraverseTree(child, depth + 1, func); childCount++; } if (func != null) func(node, depth, childCount); }
private static void TraverseTree(TreeNode child, Dictionary<string, List<IFolderDataBase>> result, List<IFolderDataBase> paths) { result.Add(child.Folder.FolderId, paths); var children = child.Childrens; if (children.Count > 0) { foreach (var node in children) { var childpaths = new List<IFolderDataBase>(); childpaths.AddRange(paths); childpaths.Add(node.Folder); TraverseTree(node, result, childpaths); } } }
private static TreeNode CreateOrGetParentNode(string parentId, Dictionary<string, TreeNode> folderId2Node) { TreeNode result = null; if (!folderId2Node.TryGetValue(parentId, out result)) { result = new TreeNode(); folderId2Node.Add(parentId, result); } result.FolderId = parentId; return result; }
private static TreeNode CreateNode(IFolderData folder, Dictionary<string, TreeNode> folderId2Node) { TreeNode result = null; if (!folderId2Node.TryGetValue(folder.FolderId, out result)) { result = new TreeNode(); folderId2Node.Add(folder.FolderId, result); } result.Folder = folder; result.FolderId = folder.FolderId; return result; }
public static Dictionary<string, List<IFolderDataBase>> GetEachFolderPath(TreeNode root) { Dictionary<string, List<IFolderDataBase>> result = new Dictionary<string, List<IFolderDataBase>>(); List<IFolderDataBase> paths = new List<IFolderDataBase>(); var children = root.Childrens; foreach (var node in children) { paths = new List<IFolderDataBase>(); paths.Add(node.Folder); TraverseTree(node, result, paths); } return result; }
public static List<string> GetAllFoldersAndChildFolders(TreeNode root, string folderId) { var findNode = FindFolderId(root, folderId); if (findNode == null) throw new NullReferenceException(string.Format("can't find folder [{0}]", folderId)); var result = new List<string>(); GetAllChildFolders(findNode, result); return result; }
internal MailboxFolderTreePath(string mailboxAddress, Dictionary<string, List<IFolderDataBase>> folderPaths, TreeNode root) { MailboxAddress = mailboxAddress; FolderPaths = folderPaths; Root = root; }