Example #1
0
        /// <summary>
        /// Gets the file system entries.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>IEnumerable{FileSystemEntryInfo}.</returns>
        private IEnumerable <FileSystemEntryInfo> GetFileSystemEntries(GetDirectoryContents request)
        {
            var entries = _fileSystem.GetFileSystemEntries(request.Path).OrderBy(i => i.FullName).Where(i =>
            {
                if (!request.IncludeHidden && i.IsHidden)
                {
                    return(false);
                }

                var isDirectory = i.IsDirectory;

                if (!request.IncludeFiles && !isDirectory)
                {
                    return(false);
                }

                if (!request.IncludeDirectories && isDirectory)
                {
                    return(false);
                }

                return(true);
            });

            return(entries.Select(f => new FileSystemEntryInfo
            {
                Name = f.Name,
                Path = f.FullName,
                Type = f.IsDirectory ? FileSystemEntryType.Directory : FileSystemEntryType.File
            }));
        }
Example #2
0
        /// <summary>
        /// Gets the file system entries.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>IEnumerable{FileSystemEntryInfo}.</returns>
        private IEnumerable <FileSystemEntryInfo> GetFileSystemEntries(GetDirectoryContents request)
        {
            // using EnumerateFileSystemInfos doesn't handle reparse points (symlinks)
            var entries = _fileSystem.GetFileSystemEntries(request.Path).Where(i =>
            {
                if (!request.IncludeHidden && i.Attributes.HasFlag(FileAttributes.Hidden))
                {
                    return(false);
                }

                var isDirectory = i.IsDirectory;

                if (!request.IncludeFiles && !isDirectory)
                {
                    return(false);
                }

                if (!request.IncludeDirectories && isDirectory)
                {
                    return(false);
                }

                return(true);
            });

            return(entries.Select(f => new FileSystemEntryInfo
            {
                Name = f.Name,
                Path = f.FullName,
                Type = f.IsDirectory ? FileSystemEntryType.Directory : FileSystemEntryType.File
            }).ToList());
        }
        /// <summary>
        /// Gets the file system entries.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>IEnumerable{FileSystemEntryInfo}.</returns>
        private IEnumerable <FileSystemEntryInfo> GetFileSystemEntries(GetDirectoryContents request)
        {
            var entries = new DirectoryInfo(request.Path).EnumerateFileSystemInfos().Where(i =>
            {
                if (!request.IncludeHidden && i.Attributes.HasFlag(FileAttributes.Hidden))
                {
                    return(false);
                }

                var isDirectory = i.Attributes.HasFlag(FileAttributes.Directory);

                if (!request.IncludeFiles && !isDirectory)
                {
                    return(false);
                }

                if (!request.IncludeDirectories && isDirectory)
                {
                    return(false);
                }

                return(true);
            });

            return(entries.Select(f => new FileSystemEntryInfo
            {
                Name = f.Name,
                Path = f.FullName,
                Type = f.Attributes.HasFlag(FileAttributes.Directory) ? FileSystemEntryType.Directory : FileSystemEntryType.File
            }).ToList());
        }
Example #4
0
        /// <summary>
        /// Gets the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>System.Object.</returns>
        /// <exception cref="System.ArgumentNullException">Path</exception>
        /// <exception cref="System.ArgumentException"></exception>
        public object Get(GetDirectoryContents request)
        {
            var path = request.Path;

            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException("Path");
            }

            // If it's not a drive trim trailing slashes.
            if (!path.EndsWith(":\\"))
            {
                path = path.TrimEnd('\\');
            }

            if (path.StartsWith(NetworkPrefix, StringComparison.OrdinalIgnoreCase) && path.LastIndexOf('\\') == 1)
            {
                return(ToOptimizedResult(GetNetworkShares(path).OrderBy(i => i.Path).ToList()));
            }

            // Reject invalid input
            if (!Path.IsPathRooted(path))
            {
                throw new ArgumentException(string.Format("Invalid path: {0}", path));
            }

            return(ToOptimizedResult(GetFileSystemEntries(request).OrderBy(i => i.Path).ToList()));
        }
Example #5
0
        /// <summary>
        /// Gets the file system entries.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>IEnumerable{FileSystemEntryInfo}.</returns>
        private IEnumerable <FileSystemEntryInfo> GetFileSystemEntries(GetDirectoryContents request)
        {
            var entries = _fileSystem.GetFileSystemEntries(request.Path).OrderBy(i => i.FullName).Where(i =>
            {
                var isDirectory = i.IsDirectory;

                if (!request.IncludeFiles && !isDirectory)
                {
                    return(false);
                }

                return(request.IncludeDirectories || !isDirectory);
            });

            return(entries.Select(f => new FileSystemEntryInfo(f.Name, f.FullName, f.IsDirectory ? FileSystemEntryType.Directory : FileSystemEntryType.File)));
        }
        /// <summary>
        /// Gets the file system entries.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>IEnumerable{FileSystemEntryInfo}.</returns>
        private IEnumerable <FileSystemEntryInfo> GetFileSystemEntries(GetDirectoryContents request)
        {
            var fileSystemEntries = FileSystem.GetFileSystemEntries(request.Path, "*", request.IncludeFiles, request.IncludeDirectories).Where(f => !f.IsSystemFile);

            if (!request.IncludeHidden)
            {
                fileSystemEntries = fileSystemEntries.Where(f => !f.IsHidden);
            }

            return(fileSystemEntries.Select(f => new FileSystemEntryInfo
            {
                Name = f.cFileName,
                Path = f.Path,
                Type = f.IsDirectory ? FileSystemEntryType.Directory : FileSystemEntryType.File
            }));
        }
Example #7
0
        /// <summary>
        /// Gets the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>System.Object.</returns>
        public object Get(GetDirectoryContents request)
        {
            var path = request.Path;

            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException("Path");
            }

            var networkPrefix = UncSeparatorString + UncSeparatorString;

            if (path.StartsWith(networkPrefix, StringComparison.OrdinalIgnoreCase) && path.LastIndexOf(UncSeparator) == 1)
            {
                return(ToOptimizedSerializedResultUsingCache(GetNetworkShares(path).OrderBy(i => i.Path).ToList()));
            }

            return(ToOptimizedSerializedResultUsingCache(GetFileSystemEntries(request).ToList()));
        }
Example #8
0
        /// <summary>
        /// Gets the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>System.Object.</returns>
        public object Get(GetDirectoryContents request)
        {
            var path = request.Path;

            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException(nameof(Path));
            }

            var networkPrefix = UncSeparatorString + UncSeparatorString;

            if (path.StartsWith(networkPrefix, StringComparison.OrdinalIgnoreCase) &&
                path.LastIndexOf(UncSeparator) == 1)
            {
                return(ToOptimizedResult(Array.Empty <FileSystemEntryInfo>()));
            }

            return(ToOptimizedResult(GetFileSystemEntries(request).ToList()));
        }