public Task <IEnumerable <FileExplorerEntry> > GetEntries(DirectoryInfoEx directory, CancellationToken token) { var entries = directory.EnumerateFileSystemInfos("*", SearchOption.TopDirectoryOnly, () => token.IsCancellationRequested); return(TaskCombinators.ThrottledAsync(entries, (entry, _) => Task.Run(() => { using (entry) { if (entry.IsFolder) { return GetDirectoryEntry((DirectoryInfoEx)entry, directory); } return GetFileEntry((FileInfoEx)entry); } }, token), CancellationToken.None)); }
public override async Task <IList <IEntryModel> > ListAsync(IEntryModel entry, CancellationToken ct, Func <IEntryModel, bool> filter = null, bool refresh = false) { return(await Task <IEntryModel> .Run(() => { //await Task.Delay(2000); if (filter == null) { filter = (m) => true; } List <IEntryModel> retVal = new List <IEntryModel>(); if (entry.IsDirectory) { DirectoryInfoEx di = createDirectoryInfo(entry.FullPath); retVal.AddRange(from fsi in di.EnumerateFileSystemInfos() let m = Converters.Convert(new FileSystemInfoExModel(this, fsi)) where filter(m) select m); } return (IList <IEntryModel>)retVal; })); }
public async Task <IEnumerable <FileExplorerEntry> > GetEntriesKeepOrder(DirectoryInfoEx directory, CancellationToken token) { var entries = directory.EnumerateFileSystemInfos("*", SearchOption.TopDirectoryOnly).ToList(); var result = new FileExplorerEntry[entries.Count]; await TaskCombinators.ThrottledAsync(entries, (entry, _) => Task.Run(() => { var index = entries.IndexOf(entry); using (entry) { if (entry.IsFolder) { result[index] = GetDirectoryEntry((DirectoryInfoEx)entry, directory); } else { result[index] = GetFileEntry((FileInfoEx)entry); } } }), token); return(result); }