private void AddParentFolder(FolderItem parentFolder)
        {
            if (FolderItem.IsProper(parentFolder) == false)
            {
                return;
            }

            if (_parentFolders == null)
            {
                _parentFolders =
                    new Dictionary <string, FolderItem>
                {
                    { parentFolder.ItemPath.ToLower(), parentFolder }
                };


                return;
            }

            if (_parentFolders.ContainsKey(parentFolder.ItemPath.ToLower()) == false)
            {
                _parentFolders.Add(parentFolder.ItemPath.ToLower(), parentFolder);
            }
        }
Exemple #2
0
 public static bool IsProper(FolderItem folder)
 {
     return
         (ReferenceEquals(folder, null) == false &&
          folder.IsMultiRootParentFolder == false);
 }
Exemple #3
0
        public static FolderItem CreateMultiRoot(IEnumerable <string> itemsPaths)
        {
            //Create a list of accepted files and folders
            var acceptedFolders = new List <string>();
            var acceptedFiles   = new List <string>();

            var itemsPathsArray = itemsPaths.ToArray();

            //Find all existing folder paths in the input items_paths list
            var foldersPaths =
                itemsPathsArray
                .Where(Directory.Exists)
                .OrderBy(itemPath => itemPath);

            //Find all existing file paths in the input items_paths list
            var filesPaths =
                itemsPathsArray
                .Where(File.Exists)
                .OrderBy(itemPath => itemPath);

            //Reject any folder that is a sub-folder of any already accepted folder
            var foldersList =
                foldersPaths.Where(
                    folderPath =>
                    acceptedFolders.Exists(
                        acceptedFolder =>
                        folderPath
                        .ToLower()
                        .StartsWith(acceptedFolder.ToLower())
                        ) == false
                    );

            acceptedFolders.AddRange(foldersList);

            //Reject any file that is a sub-file of any already accepted folder
            //Reject any file that is already accepted
            var filePathsList =
                filesPaths
                .Where(
                    filePath =>
                    acceptedFolders
                    .Exists(
                        acceptedFolder =>
                        filePath
                        .ToLower()
                        .StartsWith(acceptedFolder.ToLower())
                        ) == false
                    )
                .Where(
                    filePath =>
                    acceptedFiles.Exists(
                        acceptedFile =>
                        String
                        .Equals(filePath, acceptedFile, StringComparison.InvariantCultureIgnoreCase)
                        ) == false
                    );

            acceptedFiles.AddRange(filePathsList);

            //When there is only one accepted folder and no accepted files just create a normal root folder item
            if (acceptedFolders.Count == 1 && Directory.Exists(acceptedFolders[0]))
            {
                return(new FolderItem(acceptedFolders[0]));
            }

            //Create a multi-rooted folder item and fill it with the accepted root folders and root files
            var multirootFolder = new FolderItem();

            if (acceptedFiles.Count > 0)
            {
                multirootFolder._files = new Dictionary <string, FileItem>();

                foreach (var filePath in acceptedFiles)
                {
                    multirootFolder._files.Add(filePath, new FileItem(multirootFolder, filePath));
                }
            }

            if (acceptedFolders.Count <= 0)
            {
                return(multirootFolder);
            }

            multirootFolder._folders = new Dictionary <string, FolderItem>();

            foreach (var folderPath in acceptedFolders)
            {
                multirootFolder._folders.Add(folderPath, new FolderItem(multirootFolder, folderPath));
            }

            return(multirootFolder);
        }
Exemple #4
0
 /// <summary>
 /// Create a non-root folder item
 /// </summary>
 /// <param name="parentFolder"></param>
 /// <param name="folderName"></param>
 internal FolderItem(FolderItem parentFolder, string folderName)
     : base(parentFolder, folderName)
 {
     _level = parentFolder._level + 1;
 }
Exemple #5
0
 protected FolderTreeItem(FolderItem parentFolder, string itemName)
 {
     ParentFolder = parentFolder;
     ItemName     = itemName;
 }