示例#1
0
        public void AddFile(string filepath, int atDepth)
        {
            if (atDepth == 0)
            {
                if (HasSpaceForFile())
                {
                    files.Add(filepath);
                    string path = GetPath();
                    File.Move(filepath, Path.Combine(path, Path.GetFileName(filepath)));
                }
            }
            else
            {
                if (children.Count > 0)
                {
                    // If there is any space available it will be in the child last added
                    DirStore lastChild = children[children.Count - 1];
                    if (atDepth > 1 || lastChild.HasSpaceForFile())
                    {
                        lastChild.AddFile(filepath, atDepth - 1);
                        return;
                    }
                }

                // If we get to here then all currently available places for files are full.
                // Our last option is to create a new child.
                DirStore newChild = new DirStore(branchingFactor, basePath);
                newChild.AddFile(filepath, atDepth - 1);
                AddDirStore(newChild);
            }
        }
示例#2
0
 public void AddFile(string filepath)
 {
     if (IsSpaceAvailable())
     {
         root.AddFile(filepath, height - 1);
         numFiles += 1;
     }
     else
     {
         // No space is available in the current tree -- add a new level
         DirStore new_root = new DirStore(branchingFactor, basePath);
         new_root.AddDirStore(root);
         root    = new_root;
         height += 1;
         AddFile(filepath);
     }
 }
示例#3
0
        public void AddFile(string filepath, int atDepth)
        {
            if (atDepth == 0)
            {
                if (HasSpaceForFile())
                {
                    files.Add(filepath);
                    string path = GetPath();
                    File.Move(filepath, Path.Combine(path, Path.GetFileName(filepath)));
                }
            }
            else
            {
                if (children.Count > 0)
                {
                    // If there is any space available it will be in the child last added
                    DirStore lastChild = children[children.Count - 1];
                    if (atDepth > 1 || lastChild.HasSpaceForFile())
                    {
                        lastChild.AddFile(filepath, atDepth - 1);
                        return;
                    }
                }

                // If we get to here then all currently available places for files are full.
                // Our last option is to create a new child.
                DirStore newChild = new DirStore(branchingFactor, basePath);
                newChild.AddFile(filepath, atDepth - 1);
                AddDirStore(newChild);
            }
        }