Пример #1
0
        private IEnumerable <IndexedEntry> Index(DirectoryPath path)
        {
            var stack = new Stack <DirectoryPath>();

            stack.Push(path);

            while (stack.Count > 0)
            {
                var current = stack.Pop();

                var directory = _fileSystem.GetDirectorySafe(current);
                if (directory != null)
                {
                    // Index the directory.
                    yield return(DocumentIndexSourceEntry.Directory(directory.Path,
                                                                    directory.Path.GetDirectoryName(), directory.Path.FullPath,
                                                                    directory.Path.ToUri("shell", new Dictionary <string, string>
                    {
                        { "isDirectory", "true" }
                    })));

                    // Get all files in the directory.
                    var files = _fileSystem.GetFilesSafe(directory.Path, "*.*", SearchScope.Current);
                    if (files == null)
                    {
                        continue;
                    }

                    // Index all files in the directory.
                    foreach (var file in files)
                    {
                        if (file.Path.GetFilename().FullPath.StartsWith("."))
                        {
                            // TODO: Temporary fix due to Spectre.System lib.
                            continue;
                        }

                        yield return(DocumentIndexSourceEntry.File(file.Path,
                                                                   file.Path.GetFilename().FullPath, file.Path.FullPath,
                                                                   file.Path.ToUri("shell")));
                    }

                    // Push immediate child directories to the stack.
                    directory.GetDirectories("*", SearchScope.Current)
                    .ForEach(child => stack.Push(child.Path));
                }
            }
        }
        private IEnumerable <IndexedEntry> Index(
            DirectoryPath path,
            HashSet <DirectoryPath> excludedFolders,
            HashSet <string> includedExtensions,
            List <Regex> excludedPatterns)
        {
            var stack = new Stack <DirectoryPath>();

            stack.Push(path);

            while (stack.Count > 0)
            {
                var current = stack.Pop();

                // Folder excluded?
                if (excludedFolders.Contains(current))
                {
                    _log.Debug($"Folder '{current.FullPath}' has been excluded.");
                    continue;
                }

                // Folder name not allowed?
                if (TryMatchPattern(current, excludedPatterns, out var pattern))
                {
                    _log.Debug($"Folder '{current.FullPath}' matched pattern '{pattern}' that has been excluded.");
                    continue;
                }

                var directory = _fileSystem.GetDirectorySafe(current);
                if (directory != null)
                {
                    // Index the directory.
                    yield return(DocumentIndexSourceEntry.Directory(directory.Path,
                                                                    directory.Path.GetDirectoryName(), directory.Path.FullPath,
                                                                    directory.Path.ToUri("shell", new Dictionary <string, string>
                    {
                        { "isDirectory", "true" }
                    })));

                    // Get all files in the directory.
                    var files = _fileSystem.GetFilesSafe(directory.Path, "*.*", SearchScope.Current);
                    if (files == null)
                    {
                        continue;
                    }

                    // Index all files in the directory.
                    foreach (var file in files)
                    {
                        if (file.Path.GetFilename().FullPath.StartsWith("."))
                        {
                            // TODO: Temporary fix due to Spectre.System lib.
                            continue;
                        }
                        if ((file.Attributes & FileAttributes.System) == FileAttributes.System)
                        {
                            continue;
                        }
                        if ((file.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden)
                        {
                            continue;
                        }
                        if (!includedExtensions.Contains(file.Path.GetExtension().Name))
                        {
                            continue;
                        }

                        yield return(DocumentIndexSourceEntry.File(file.Path,
                                                                   file.Path.GetFilename().FullPath, file.Path.FullPath,
                                                                   file.Path.ToUri("shell")));
                    }

                    // Push immediate child directories to the stack.
                    directory.GetDirectories("*", SearchScope.Current)
                    .ForEach(child => stack.Push(child.Path));
                }
            }
        }