public PageViewModel GetFolderContent(int moduleId, int folderId, int startIndex, int numItems, string sortExpression)
        {
            var folder = GetFolderInfo(folderId);

            if (!FolderPermissionController.CanBrowseFolder((FolderInfo)folder))
            {
                //The user cannot access the content
                return(new PageViewModel
                {
                    Folder = GetFolderViewModel(folder),
                    Items = new List <ItemViewModel>(),
                    TotalCount = 0
                });
            }

            var sortProperties = SortProperties.Parse(sortExpression);

            List <IFolderInfo> folders;

            var subfolderFilter = SettingsRepository.GetSubfolderFilter(moduleId);

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

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

            IEnumerable <ItemViewModel> content;

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

            return(new PageViewModel
            {
                Folder = GetFolderViewModel(folder),
                Items = content.ToList(),
                TotalCount = folders.Count() + files.Count()
            });
        }
Exemple #2
0
        public void SyncFolderContent(int folderId, bool recursive)
        {
            var folder = GetFolderInfo(folderId);

            if (!FolderPermissionController.CanBrowseFolder((FolderInfo)folder))
            {
                //The user cannot access the content
                return;
            }

            FolderManager.Instance.Synchronize(folder.PortalID, folder.FolderPath, recursive, true);
        }
Exemple #3
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(),
            });
        }
Exemple #4
0
        public IEnumerable <FolderViewModel> GetFolders(int moduleId, int folderId)
        {
            var subfolderFilter = SettingsRepository.GetSubfolderFilter(moduleId);

            if (subfolderFilter != SubfolderFilter.IncludeSubfoldersFolderStructure)
            {
                return(new List <FolderViewModel>());
            }

            var folder = GetFolderInfo(folderId);

            if (!FolderPermissionController.CanBrowseFolder((FolderInfo)folder))
            {
                //The user cannot access the content
                return(new List <FolderViewModel>());
            }
            return(AssetManager.Instance.GetFolders(folder, "FolderName", true).Select(GetFolderViewModel));
        }
Exemple #5
0
        /// <summary>
        /// Get children folders of the specified parent.
        /// </summary>
        /// <param name="parent">Parent folder</param>
        /// <param name="isRoot">True if it's the root folder</param>
        /// <returns>List of folder</returns>
        private IEnumerable <FolderDTO> GetChildrenFolder(IFolderInfo parent, bool isRoot)
        {
            List <FolderDTO> children = null;

            if (parent.HasChildren)
            {
                children = new List <FolderDTO>();
                IEnumerable <IFolderInfo> folders = FolderManager.Instance.GetFolders(parent);

                foreach (IFolderInfo folder in folders)
                {
                    FolderInfo current = folder as FolderInfo;

                    if (FolderPermissionController.CanBrowseFolder(current))
                    {
                        if (current.IsProtected || current.FolderPath == "Cache/")
                        {
                            continue;
                        }

                        if (current.FolderPath == "Users/" && !IsAdmin)
                        {
                            continue;
                        }

                        FolderDTO child = new FolderDTO
                        {
                            Label = current.FolderName,
                            Data  = new FolderDataDTO {
                                Path = current.FolderPath, CanManage = FolderPermissionController.CanManageFolder(current)
                            },
                            Leaf     = !current.HasChildren,
                            Children = current.HasChildren ? new List <FolderDTO>() : null
                        };

                        children.Add(child);
                    }
                }

                if (isRoot)
                {
                    // Add personal folder at the end for not admin users
                    if (!IsAdmin)
                    {
                        DocumentSettings settings = new DocumentSettings(ActiveModule);

                        if (settings.UserFolder)
                        {
                            FolderInfo userFolder = FolderManager.Instance.GetUserFolder(UserInfo) as FolderInfo;

                            FolderDTO userChild = new FolderDTO
                            {
                                Label = LocalizeString("UserFolder"),
                                Data  = new FolderDataDTO {
                                    Path = userFolder.FolderPath, CanManage = FolderPermissionController.CanManageFolder(userFolder)
                                },
                                Leaf     = !userFolder.HasChildren,
                                Children = userFolder.HasChildren ? new List <FolderDTO>() : null
                            };

                            children.Add(userChild);
                        }
                    }

                    List <FolderDTO> rootFolders = new List <FolderDTO>();

                    FolderDTO root = new FolderDTO
                    {
                        Label = LocalizeString("RootFolder"),
                        Data  = new FolderDataDTO {
                            Path = "", CanManage = FolderPermissionController.CanManageFolder(parent as FolderInfo)
                        },
                        Leaf     = children.Count == 0,
                        Expanded = true,
                        Children = children
                    };

                    rootFolders.Add(root);

                    return(rootFolders);
                }
            }

            return(children);
        }