public (FileSystemNode <INode> parent, string name) GetParentFolder(string file) { int ndx = file.LastIndexOf('\\'); string name = file.Substring(ndx + 1); FileSystemNode <INode> parent = this[file.Substring(0, ndx)]; return(parent, name); }
public FileSystemNode <T> Navigate(string path) { path = path.ToLower().Trim(); if (path == PATH_SEPARATOR.ToString()) { return(Root); } path = path.TrimEnd(PATH_SEPARATOR); if (path == PATH_SAME) { return(this); } else if (path == PATH_PARENT) { return(IsRoot ? this : Parent); } else if (path.Contains(PATH_SEPARATOR)) { int ndx = path.IndexOf(PATH_SEPARATOR); FileSystemNode <T> node = this; if (ndx == 0) { node = Root; } else { string child = path.Remove(ndx).Trim(); if (child == PATH_PARENT) { node = IsRoot ? this : Parent; } else if (child != PATH_SAME) { node = Children.FirstOrDefault(x => x.Name.ToLower() == child); } } return(node?.Navigate(path.Substring(ndx + 1))); } else { return(Children.FirstOrDefault(x => x.Name.ToLower() == path)); } }
public void UpdateNodes(Action <FileSystemNode <INode> > callback = null) { lock (this) { INode[] nodes = Mega.GetNodes().ToArray(); INode rootnd = nodes.First(n => n.Type == NodeType.Root); if (Root != null) { Root.ClearChildren(); } Root = new FileSystemNode <INode>(rootnd.Name, null) { Value = rootnd }; buildtree(Root); callback?.Invoke(Root); void buildtree(FileSystemNode <INode> nd) { foreach (INode child in nodes.Where(x => x.ParentId == nd.Value.Id)) { FileSystemNode <INode> childnode = new FileSystemNode <INode>(child.Name, nd) { Value = child }; buildtree(childnode); nd.Children.Add(childnode); } } } }
public FileSystemNode(string name, FileSystemNode <T> parent) { Name = name; Parent = parent; }