public virtual async Task <PagedResultDto <FileSystemDto> > GetListAsync(GetFileSystemListDto input) { return(await FileSystemAppService.GetListAsync(input)); }
public virtual Task <PagedResultDto <FileSystemDto> > GetListAsync(GetFileSystemListDto input) { List <FileSystemDto> fileSystems = new List <FileSystemDto>(); string fileSystemPath = GetFileSystemBashPath(); if (!input.Parent.IsNullOrWhiteSpace()) { fileSystemPath = GetFileSystemPath(input.Parent); } var directoryInfo = new DirectoryInfo(fileSystemPath); if (!directoryInfo.Exists) { return(Task.FromResult(new PagedResultDto <FileSystemDto>(0, fileSystems))); } // 查询全部文件系统 var fileSystemInfos = directoryInfo.GetFileSystemInfos(); // 指定搜索条件查询目录 FileSystemInfo[] fileSystemInfoSearchChildren; if (!input.Filter.IsNullOrWhiteSpace()) { var searchPattern = $"*{input.Filter}*"; fileSystemInfoSearchChildren = directoryInfo.GetFileSystemInfos(searchPattern); } else { fileSystemInfoSearchChildren = directoryInfo.GetFileSystemInfos(); } fileSystemInfoSearchChildren = fileSystemInfoSearchChildren .Skip((input.SkipCount - 1) * input.MaxResultCount) .Take(input.MaxResultCount) .ToArray(); foreach (var fileSystemInfo in fileSystemInfoSearchChildren) { var fileSystem = new FileSystemDto { Name = fileSystemInfo.Name, CreationTime = fileSystemInfo.CreationTime, LastModificationTime = fileSystemInfo.LastWriteTime, }; if (fileSystemInfo is FileInfo fileInfo) { fileSystem.Type = FileSystemType.File; fileSystem.Size = fileInfo.Length; fileSystem.Extension = fileInfo.Extension; if (fileInfo.Directory != null && !fileInfo.Directory.FullName.IsNullOrWhiteSpace()) { fileSystem.Parent = GetFileSystemRelativePath(fileInfo.Directory.FullName); } } else if (fileSystemInfo is DirectoryInfo directory) { fileSystem.Type = FileSystemType.Folder; if (directory.Parent != null && !directory.Parent.FullName.IsNullOrWhiteSpace()) { fileSystem.Parent = GetFileSystemRelativePath(directory.Parent.FullName); } } fileSystems.Add(fileSystem); } fileSystems = fileSystems .OrderBy(f => f.Type) .ThenBy(f => f.Name) .ToList(); return(Task.FromResult(new PagedResultDto <FileSystemDto>( fileSystemInfos.Length, fileSystems ))); }