public static TreeElement CreateTreeFromFlatNodes(this TreeElement root, List <TreeNode> flatNodes) { var treeElements = new List <TreeElement>(); foreach (var node in flatNodes) { treeElements.Add(new TreeElement(node)); } root.BuildTree(treeElements); return(root); }
public static TreeElement GetHierarchy(this IEnumerable <string> paths, string userId) { var baseRelativePath = "/" + userId; var root = new TreeElement() { Name = userId, Children = new List <TreeElement>(), RelativePath = baseRelativePath }; foreach (var path in paths) { var splitBetweenBaseAndDirectory = path.IndexOf(userId, StringComparison.Ordinal) + userId.Length; var pathWithoutUser = path.Remove(0, splitBetweenBaseAndDirectory).TrimStart('/'); if (!string.IsNullOrWhiteSpace(pathWithoutUser)) { var parts = pathWithoutUser.Split('/'); var baseAbsolutePath = path.Substring(0, splitBetweenBaseAndDirectory); root.BuildTree(parts, baseAbsolutePath, baseRelativePath); } } return(root); }