Пример #1
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(),
            });
        }
Пример #2
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(),
            });
        }