Example #1
0
 private void ReportProgress(BackgroundIndexer worker, string path)
 {
     if (worker.CancellationPending)
     {
         throw new OperationCanceledException();
     }
     worker.ReportProgressInCurrentThread(path);
 }
Example #2
0
        // running in UI thread
        public void ReindexSearchTree(BackgroundIndexerParams indexerParams)
        {
            if (indexerParams.PathsChanged == null)
            {
                lock (this.BackgroundIndexers)
                {
                    foreach (var ind in this.BackgroundIndexers)
                    {
                        ind.CancelAsync();
                    }
                    this.BackgroundIndexers.Clear();
                }
            }

            var indexer = new BackgroundIndexer();

            indexer.RunWorkerCompleted += this.BackgroundIndexerWorkCompleted;
            indexer.ProgressChanged    += this.BackgroundIndexerProgressChanged;
            indexer.RunWorkerAsync(indexerParams);
            lock (this.BackgroundIndexers)
            {
                this.BackgroundIndexers.Add(indexer);
            }
        }
Example #3
0
        public bool UpdateDocumentHierarchy(IEnumerable <string> pathsToUpdate, FilesPatternProvider filesPatternProvider, BackgroundIndexer worker)
        {
            if (this.DocumentHierarchy == null)
            {
                return(false);
            }
            bool changed = false;

            foreach (string path in pathsToUpdate)
            {
                INode node = this.DocumentHierarchy.GetNode(path);
                bool  nodeShouldBeRemoved = node != null;
                var   fileSystemEntryList = this.GetFileList(path, filesPatternProvider, worker);

                foreach (PowershellParseResult fileSystemEntry in fileSystemEntryList)
                {
                    // this is to prevent from reporting progress after deletion if the node is only updated
                    if (fileSystemEntry.Path == path && node != null)
                    {
                        this.DocumentHierarchy.RemoveNode(node);
                        nodeShouldBeRemoved = false;
                    }
                    this.documentHierarchyIndexer.AddFileSystemNode(this.DocumentHierarchy, fileSystemEntry);
                    changed = true;
                }
                if (nodeShouldBeRemoved)
                {
                    this.DocumentHierarchy.RemoveNode(node);
                    changed = true;
                    this.ReportProgress(worker, path);
                }
            }
            return(changed);
        }
Example #4
0
        private IEnumerable <PowershellParseResult> GetFileList(string path, FilesPatternProvider filesPatternProvider, BackgroundIndexer worker)
        {
            PowershellParseResult parseResult      = null;
            Queue <string>        pathsToEnumerate = new Queue <string>();

            if (File.Exists(path) && filesPatternProvider.DoesFileMatch(path))
            {
                parseResult = this.powershellFileParser.ParseFile(path, isDirectory: false, isExcluded: false, errorMessage: null);
                yield return(parseResult);

                this.ReportProgress(worker, path);
                yield break;
            }
            if (!Directory.Exists(path) || !filesPatternProvider.DoesDirectoryMatch(path))
            {
                yield break;
            }
            parseResult = this.powershellFileParser.ParseFile(path, isDirectory: true, isExcluded: false, errorMessage: null);
            yield return(parseResult);

            pathsToEnumerate.Enqueue(path);
            while (pathsToEnumerate.Any())
            {
                IEnumerable <string> dirs = null;
                parseResult = null;
                string currentPath = pathsToEnumerate.Dequeue();

                foreach (var file in this.GetFilesInDirectory(currentPath, filesPatternProvider))
                {
                    yield return(file);
                }

                try {
                    dirs = Directory.EnumerateDirectories(currentPath).Where(dir => filesPatternProvider.DoesDirectoryMatch(dir));
                } catch (Exception e)
                {
                    parseResult = this.powershellFileParser.ParseFile(currentPath, isDirectory: true, isExcluded: false, errorMessage: e.Message);
                }
                if (parseResult != null)
                {
                    yield return(parseResult);

                    continue;
                }
                foreach (string dir in dirs)
                {
                    bool isExcluded = filesPatternProvider.IsExcludedFromIndexing(dir);
                    if (filesPatternProvider.DoesDirectoryMatch(dir) && (isExcluded || filesPatternProvider.IncludeAllFiles || filesPatternProvider.IsInAdditonalPaths(dir)))
                    {
                        parseResult = this.powershellFileParser.ParseFile(dir, isDirectory: true, isExcluded: isExcluded, errorMessage: null);
                        yield return(parseResult);
                    }
                    if (!isExcluded)
                    {
                        pathsToEnumerate.Enqueue(dir);
                    }
                }
                this.ReportProgress(worker, currentPath);
            }
            while (pathsToEnumerate.Any())
            {
                ;
            }
        }