コード例 #1
0
        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);
        }
コード例 #2
0
        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));
            }
        }
コード例 #3
0
        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);
                    }
                }
            }
        }
コード例 #4
0
 public FileSystemNode(string name, FileSystemNode <T> parent)
 {
     Name   = name;
     Parent = parent;
 }