public System.Collections.IEnumerable GetChildren(TreePath treePath) { if (string.IsNullOrEmpty(this.basePath) && treePath.IsEmpty()) { foreach (string str in Environment.GetLogicalDrives()) { LogicalDriveItem item = new LogicalDriveItem(str); yield return(item); } } else { List <BaseItem> items = new List <BaseItem>(); BaseItem parent = treePath.LastNode as BaseItem; string path = parent != null ? parent.ItemPath : this.basePath; if (!string.IsNullOrEmpty(path) && Directory.Exists(path)) { try { IEnumerable <string> dirQuery = Directory.GetDirectories(path); IEnumerable <string> fileQuery = Directory.GetFiles(path); if (this.filter != null) { dirQuery = dirQuery.Where(s => this.filter(s)); fileQuery = fileQuery.Where(s => this.filter(s)); } foreach (string str in dirQuery) { items.Add(new FolderItem(str, parent)); } foreach (string str in fileQuery) { items.Add(new FileItem(str, parent)); } } catch (UnauthorizedAccessException) {} this.itemsToRead.AddRange(items); if (!this.itemLoader.IsBusy) { this.itemLoader.RunWorkerAsync(); } foreach (BaseItem item in items) { yield return(item); } } else { yield break; } } }
public System.Collections.IEnumerable GetChildren(TreePath treePath) { if (string.IsNullOrEmpty(this.basePath) && treePath.IsEmpty()) { foreach (string str in Environment.GetLogicalDrives()) { LogicalDriveItem item = new LogicalDriveItem(str); yield return item; } } else { List<BaseItem> items = new List<BaseItem>(); BaseItem parent = treePath.LastNode as BaseItem; string path = parent != null ? parent.ItemPath : this.basePath; if (!string.IsNullOrEmpty(path) && Directory.Exists(path)) { try { IEnumerable<string> dirQuery = Directory.GetDirectories(path); IEnumerable<string> fileQuery = Directory.GetFiles(path); if (this.filter != null) { dirQuery = dirQuery.Where(s => this.filter(s)); fileQuery = fileQuery.Where(s => this.filter(s)); } foreach (string str in dirQuery) items.Add(new FolderItem(str, parent)); foreach (string str in fileQuery) items.Add(new FileItem(str, parent)); } catch (UnauthorizedAccessException) {} this.itemsToRead.AddRange(items); if (!this.itemLoader.IsBusy) this.itemLoader.RunWorkerAsync(); foreach (BaseItem item in items) yield return item; } else yield break; } }