예제 #1
0
        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);
                }
            }
        }
예제 #2
0
        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;
                }
            }
        }
예제 #3
0
 protected virtual void OnRaiseFileFoundEvent(FileEventArgs fileEventArgs)
 {
     FileFoundEvent?.Invoke(this, fileEventArgs);
 }