private IEnumerable <FileInfoBase> GetFilteredFiles(DirectoryInfoBase directory) { var breakSearch = false; foreach (var file in directory.EnumerateFiles()) { if (Status == FileSystemVisitorStatus.Stopped) { break; } var excludeItem = false; FileFoundEvent?.Invoke(file, ref breakSearch, ref excludeItem); if (Filter != null && !Filter.Invoke(file)) { continue; } FilterItemActions(file, ref breakSearch, ref excludeItem); if (breakSearch) { Status = FileSystemVisitorStatus.Stopped; } if (!excludeItem) { yield return(file); } } }
private IEnumerable <FileSystemInfoBase> GetFilteredItems(DirectoryInfoBase directory) { var breakSearch = false; foreach (var item in directory.GetFileSystemInfos()) { if (Status == FileSystemVisitorStatus.Stopped) { break; } var excludeItem = false; var dir = item as DirectoryInfoBase; if (dir != null) { DirectoryFoundEvent?.Invoke(dir, ref breakSearch, ref excludeItem); if (!breakSearch && !excludeItem) { foreach (var i in GetFilteredItems(dir)) //going recursion here { yield return(i); } } } else { var file = item as FileInfoBase; if (file != null) { FileFoundEvent?.Invoke(file, ref breakSearch, ref excludeItem); } } if (breakSearch) { Status = FileSystemVisitorStatus.Stopped; } if (excludeItem) { continue; } if (Filter != null && !Filter.Invoke(item)) { continue; } FilterItemActions(item, ref breakSearch, ref excludeItem); if (!excludeItem) { yield return(item); } else if (breakSearch) { Status = FileSystemVisitorStatus.Stopped; } } }
protected virtual void OnRaiseFileFoundEvent(FileEventArgs fileEventArgs) { FileFoundEvent?.Invoke(this, fileEventArgs); }