Пример #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FileFolderTree"/> class.
        /// </summary>
        /// <param name="baseDirectory">The base directory. </param>
        /// <param name="validExtensions">The file filter to apply. </param>
        public FileFolderTree(string baseDirectory, IEnumerable <string> validExtensions)
        {
            this.BaseDirectory   = baseDirectory;
            this.ValidExtensions = validExtensions;
            var rootNode = new FileFolderNode
            {
                Id       = baseDirectory,
                Name     = Path.GetDirectoryName(baseDirectory),
                ParentId = Directory.GetParent(baseDirectory).FullName,
                IsDir    = true
            };

            this.Tree = new Tree <FileFolderNode>(rootNode);
            this.RecursiveDirectorySearch();
        }
Пример #2
0
 /// <summary>
 /// Searches a directory for files and folders.
 /// </summary>
 /// <param name="dir">The directory path.</param>
 /// <param name="parentNode">The parent node.</param>
 private void RecurseDirectory(string dir, Node <FileFolderNode> parentNode)
 {
     foreach (var directory in Directory.GetDirectories(dir))
     {
         var fileFolderNode = new FileFolderNode
         {
             Name     = Path.GetFileName(directory),
             Id       = directory,
             ParentId = dir,
             IsDir    = true
         };
         var newNode = new Node <FileFolderNode>(fileFolderNode);
         this.PopulateFilesInFolder(directory, newNode);
         parentNode.Children.Add(newNode);
         this.RecurseDirectory(directory, newNode);
     }
 }
Пример #3
0
 /// <summary>
 /// Encodes the file paths in a file folder node to base 64.
 /// </summary>
 /// <param name="node">The file folder node.</param>
 /// <returns>The <see cref="FileFolderNode"/> encded in base 64.</returns>
 private FileFolderNode EncodeFilePaths(FileFolderNode node)
 {
     node.Id       = Base64.Encode(node.Id);
     node.ParentId = Base64.Encode(node.ParentId);
     return(node);
 }