Esempio n. 1
0
        private IEnumerable <IFileInfo> GetFiles(IFolderInfo folder, SortProperties sortProperties, int startIndex, bool recursive)
        {
            Requires.NotNull("folder", folder);

            if (Host.EnableFileAutoSync && startIndex == 0)
            {
                FolderManager.Instance.Synchronize(folder.PortalID, folder.FolderPath, false, true);
            }

            return(SortFiles(FolderManager.Instance.GetFiles(folder, recursive, true), sortProperties));
        }
Esempio n. 2
0
        public ContentPage GetFolderContent(int folderId, int startIndex, int numItems, string sortExpression = null, SubfolderFilter subfolderFilter = SubfolderFilter.IncludeSubfoldersFolderStructure)
        {
            var folder = this.GetFolderInfo(folderId);

            if (!FolderPermissionController.CanBrowseFolder((FolderInfo)folder))
            {
                throw new AssetManagerException(Localization.GetExceptionMessage("UserHasNoPermissionToBrowseFolder", UserHasNoPermissionToBrowseFolderDefaultMessage));
            }

            var sortProperties = SortProperties.Parse(sortExpression);

            List <IFolderInfo> folders;

            if (subfolderFilter != SubfolderFilter.IncludeSubfoldersFolderStructure)
            {
                folders = new List <IFolderInfo>();
            }
            else
            {
                folders = this.GetFolders(folder, sortProperties.Column == "ItemName" ? "FolderName" : sortProperties.Column, sortProperties.Ascending).ToList();
            }

            var recursive = subfolderFilter == SubfolderFilter.IncludeSubfoldersFilesOnly;
            var files     = this.GetFiles(folder, sortProperties, startIndex, recursive).ToList();

            IEnumerable <object> content;

            if (startIndex + numItems <= folders.Count())
            {
                content = folders.Skip(startIndex).Take(numItems);
            }
            else if (startIndex >= folders.Count())
            {
                content = files.Skip(startIndex - folders.Count).Take(numItems);
            }
            else
            {
                var numFiles = numItems - (folders.Count - startIndex);
                content = folders.Skip(startIndex);
                content = content.Union(files.Take(numFiles));
            }

            return(new ContentPage
            {
                Folder = folder,
                Items = content.ToList(),
                TotalCount = folders.Count() + files.Count(),
            });
        }
Esempio n. 3
0
        public ContentPage SearchFolderContent(int folderId, string pattern, int startIndex, int numItems, string sortExpression = null, SubfolderFilter subfolderFilter = SubfolderFilter.IncludeSubfoldersFolderStructure)
        {
            var recursive = subfolderFilter != SubfolderFilter.ExcludeSubfolders;
            var folder    = this.GetFolderInfo(folderId);

            var files          = FolderManager.Instance.SearchFiles(folder, pattern, recursive);
            var sortProperties = SortProperties.Parse(sortExpression);
            var sortedFiles    = SortFiles(files, sortProperties).ToList();

            IEnumerable <object> content = sortedFiles.Skip(startIndex).Take(numItems);

            return(new ContentPage
            {
                Folder = folder,
                Items = content.ToList(),
                TotalCount = sortedFiles.Count(),
            });
        }
Esempio n. 4
0
        private static IEnumerable <IFileInfo> SortFiles(IEnumerable <IFileInfo> files, SortProperties sortProperties)
        {
            switch (sortProperties.Column)
            {
            case "ItemName":
                return(OrderBy(files, f => f.FileName, sortProperties.Ascending));

            case "LastModifiedOnDate":
                return(OrderBy(files, f => f.LastModifiedOnDate, sortProperties.Ascending));

            case "Size":
                return(OrderBy(files, f => f.Size, sortProperties.Ascending));

            case "ParentFolder":
                return(OrderBy(files, f => f.FolderId, new FolderPathComparer(), sortProperties.Ascending));

            case "CreatedOnDate":
                return(OrderBy(files, f => f.CreatedOnDate, sortProperties.Ascending));

            default:
                return(files);
            }
        }