Exemplo n.º 1
0
        private IEnumerable<FilesItemViewModel> GetChildItems(FilesGetRequest filesRequest)
        {
            var parentPath = PathUtils.CombinePaths(this.GetApplicationRootPath(), filesRequest.Path);

            var dirs = Directory.GetDirectories(parentPath).Select(d => new FilesItemViewModel() { IsFolder = true, Name = d.Substring(parentPath.Length), HasChildren = !this.IsDirectoryEmpty(d, filesRequest.Extension) }).OrderBy(d => d.Name);

            var files = Directory.GetFiles(parentPath, string.Format("*.{0}", filesRequest.Extension)).Select(f => new FilesItemViewModel() { Name = f.Substring(parentPath.Length).TrimStart('\\') }).OrderBy(f => f.Name);

            return dirs.Union(files).Skip(filesRequest.Skip).Take(filesRequest.Take == 0 ? FilesWebServiceConstants.MaxItemsPerRequest : filesRequest.Take);
        }
Exemplo n.º 2
0
        public FilesViewModel Get(FilesGetRequest filesRequest)
        {
            ServiceUtility.RequestBackendUserAuthentication();

            var result = new FilesViewModel();

            string error;
            if (this.ValidateFilesRequest(filesRequest, out error))
            {
                result.Items = this.GetChildItems(filesRequest);
            }
            else
            {
                result.Error = error;
            }

            ServiceUtility.DisableCache();

            return result;
        }
Exemplo n.º 3
0
        private bool ValidateFilesRequest(FilesGetRequest filesRequest, out string error)
        {
            var isValid = this.ValidateExtension(filesRequest.Extension, out error)
                && this.ValidatePath(filesRequest.Path, out error)
                && this.ValidateSkipTake(filesRequest.Skip, filesRequest.Take, out error);

            return isValid;
        }