예제 #1
0
파일: PGFolder.cs 프로젝트: ianmarshall/HAC
    public void SortSubFolders(SortAction sortAction, ref PGFolderComparer defaultcomparer)
    {
        PGFolderComparer comparer = PGFolderComparer.GetComparerBySortAction(sortAction, defaultcomparer);

        SubFolders.Sort(comparer);
        defaultcomparer = comparer;
    }
예제 #2
0
    public static PGFolderComparer GetComparerBySortAction(SortAction sortAction, PGFolderComparer inheritComparer)
    {
        PGFolderComparer comparer = new PGFolderComparer();

        if (sortAction == SortAction.NameASC)
        {
            comparer = new PGFolderNameASCComparer();
        }
        else if (sortAction == SortAction.NameDESC)
        {
            comparer = new PGFolderNameDESCComparer();
        }
        else if (sortAction == SortAction.DateTimeASC)
        {
            comparer = new PGFolderDateASCComparer();
        }
        else if (sortAction == SortAction.DateTimeDESC)
        {
            comparer = new PGFolderDateDESCComparer();
        }
        else if (sortAction == SortAction.CustomOrderProperty)
        {
            comparer = new PGFolderOrderComparer();
        }
        else if (sortAction == SortAction.Inherit)
        {
            comparer = inheritComparer;
        }
        else
        {
            throw new Exception("Comparer not found");
        }

        return(comparer);
    }
예제 #3
0
        private void FillSubFoldersRecursive(ref PGFolder folder, PGFolderComparer defaultSortingComparer, out List <string> filenames_cache)
        {
            filenames_cache = new List <string>();

            DirectoryInfo directory = new DirectoryInfo(folder.PhysicalPath);

            if (!directory.Exists)
            {
                throw new DirectoryNotFoundException(string.Format("Directory {0} not found", directory));
            }
            else
            {
                //1. READ INFO FILE
                folder.ReadFolder();

                Images.AddRange(folder.Images);     //cache images for easy access
                Comments.AddRange(folder.Comments); //cache comments for easy access.

                //2. LOAD SUB FOLDERS from disk (RECURSIVE)
                folder.SubFolders = new List <PGFolder>();

                defaultSortingComparer = PGFolderComparer.GetComparerBySortAction(folder.SortAction, defaultSortingComparer);

                //3. subfolder recursive
                foreach (DirectoryInfo subDirectory in directory.GetDirectories())
                {
                    if (!IsDirectoryIgnored(subDirectory.FullName))
                    {
                        PGFolder subfolder = new PGFolder()
                        {
                            Name = subDirectory.Name, PhysicalPath = subDirectory.FullName
                        };
                        subfolder.ParentFolder = folder;

                        List <string> filename_cache_subfolder = new List <string>();
                        FillSubFoldersRecursive(ref subfolder, defaultSortingComparer, out filename_cache_subfolder);
                        filenames_cache.AddRange(filename_cache_subfolder);
                        folder.SubFolders.Add(subfolder);
                        folder.NumberNestedImages += subfolder.NumberNestedImages; //todo refactor, inside pgfolder.
                    }
                }

                //4. Sorting?
                folder.SortSubFolders(folder.SortAction, ref defaultSortingComparer);

                AllFolders.Add(folder); //index for faster access

                filenames_cache.Add(folder.FolderInfoFileLocation());
            }

            //5. WRITE if necessary
            if (!folder.ExistFolderInfoFile())
            {
                folder.WriteFolderFileInfo();
            }
        }