Пример #1
0
        /***************************************************/
        /**** Public Methods                            ****/
        /***************************************************/

        public IEnumerable <object> Read(FileDirRequest fdr, PullConfig pullConfig)
        {
            // Copy for immutability in UI
            FileDirRequest fdrCopy = BH.Engine.Base.Query.ShallowClone(fdr);

            // Recursively walk the directories to retrieve File and Directory Info.
            List <IFSInfo> output = new List <IFSInfo>();

            List <FSFile>      files = new List <FSFile>();
            List <FSDirectory> dirs  = new List <FSDirectory>();

            WildcardPattern wildcardPattern = null;

            if (!Modify.ProcessFileDirRequest(fdrCopy, out wildcardPattern))
            {
                return(null);
            }

            int retrievedFiles = 0, retrievedDirs = 0;

            WalkDirectories(files, dirs, fdrCopy, ref retrievedFiles, ref retrievedDirs, pullConfig.IncludeHiddenFiles, pullConfig.IncludeSystemFiles, wildcardPattern);

            output.AddRange(dirs);
            output.AddRange(files);

            // If a sort order is applied, sort separately files and dirs,
            // then return the maxItems of each of those.
            if (fdrCopy.SortOrder != SortOrder.Default)
            {
                output = Query.SortOrder(output, fdrCopy.SortOrder);

                files = output.OfType <FSFile>().Take(fdrCopy.MaxFiles == -1 ? output.Count : fdrCopy.MaxFiles).ToList();
                dirs  = output.OfType <FSDirectory>().Take(fdrCopy.MaxDirectories == -1 ? output.Count : fdrCopy.MaxDirectories).ToList();
            }

            if (fdrCopy.IncludeFileContents)
            {
                files.ForEach(f => ReadAndAddContent(f));
            }

            output = new List <IFSInfo>();

            if (fdrCopy.SortOrder != SortOrder.Default && fdrCopy.SortOrder != SortOrder.ByName)
            {
                output.AddRange(files);
                output.AddRange(dirs);
            }
            else
            {
                output.AddRange(dirs);
                output.AddRange(files);
            }

            return(output);
        }