/// <summary>
        /// See <c>IScanner</c> documentation.
        /// </summary>
        public IMultiFileScanResult Scan(IEnumerable<string> filePaths, IEnumerable<ITermTable> termTables, FileScanCompleted callback, FileContentGetter contentGetter, ScanStopper stopper)
        {
            if (filePaths == null)
            {
                throw new ArgumentNullException("filePaths");
            }
            if (termTables == null)
            {
                throw new ArgumentNullException("termTables");
            }

            MatchFinder finder = new MatchFinder(termTables);

            MultiFileScanResult allResults = new MultiFileScanResult();

            foreach (string filePath in filePaths)
            {
                if (stopper != null && stopper())
                {
                    break;
                }

                if (FileShouldBeScanned(filePath))
                {
                    IScanResult fileResult = ScanFile(filePath, finder, contentGetter, stopper);
                    allResults.Append(fileResult);
                    if (callback != null)
                    {
                        callback(fileResult);
                    }
                }
            }

            return allResults;
        }
        private static IScanResult ScanFile(string filePath, MatchFinder finder, FileContentGetter contentGetter, ScanStopper stopper)
        {
            if (filePath == null)
            {
                throw new ArgumentNullException("filePath");
            }

            // See if the content getter can give us the file contents.  If so, we'll scan that
            // string rather than loading the file from disk.
            if (contentGetter != null)
            {
                string content = contentGetter(filePath);
                if (content != null)
                {
                    return(ScanResult.ScanOccurred(filePath, GetScanHits(filePath, content, finder, stopper)));
                }
            }

            StreamReader reader = null;

            try
            {
                try
                {
                    reader = File.OpenText(filePath);
                }
                catch (Exception ex)
                {
                    if (ex is UnauthorizedAccessException ||
                        ex is ArgumentException ||
                        ex is ArgumentNullException ||
                        ex is PathTooLongException ||
                        ex is DirectoryNotFoundException ||
                        ex is FileNotFoundException ||
                        ex is NotSupportedException ||
                        ex is IOException)
                    {
                        return(ScanResult.ScanNotPossible(filePath));
                    }
                    else
                    {
                        throw;
                    }
                }

                return(ScanResult.ScanOccurred(filePath, GetScanHits(filePath, reader, finder, stopper)));
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }
        }
        /// <summary>
        /// See <c>IScanner</c> documentation.
        /// </summary>
        public IMultiFileScanResult Scan(IEnumerable <string> filePaths, string searchingWord, FileScanCompleted callback, FileContentGetter contentGetter, ScanStopper stopper)
        {
            if (filePaths == null)
            {
                throw new ArgumentNullException("filePaths");
            }
            if (string.IsNullOrEmpty(searchingWord))
            {
                throw new ArgumentNullException("termTables");
            }

            MatchFinder finder = new MatchFinder(searchingWord);

            MultiFileScanResult allResults = new MultiFileScanResult();

            foreach (string filePath in filePaths)
            {
                if (stopper != null && stopper())
                {
                    break;
                }

                if (FileShouldBeScanned(filePath))
                {
                    IScanResult fileResult = ScanFile(filePath, finder, contentGetter, stopper);
                    allResults.Append(fileResult);
                    if (callback != null)
                    {
                        callback(fileResult);
                    }
                }
            }

            return(allResults);
        }
 /// <summary>
 /// See <c>IScanner</c> documentation.
 /// </summary>
 public IMultiFileScanResult Scan(IEnumerable <string> filePaths, string searchingWord, FileScanCompleted callback, FileContentGetter contentGetter)
 {
     return(Scan(filePaths, searchingWord, callback, contentGetter, null));
 }
 /// <summary>
 /// See <c>IScanner</c> documentation.
 /// </summary>
 public IMultiFileScanResult Scan(IEnumerable <string> filePaths, IEnumerable <ITermTable> termTables, FileScanCompleted callback, FileContentGetter contentGetter)
 {
     return(Scan(filePaths, termTables, callback, contentGetter, null));
 }
 /// <summary>
 /// See <c>IScanner</c> documentation.
 /// </summary>
 public IMultiFileScanResult Scan(IEnumerable<string> filePaths, IEnumerable<ITermTable> termTables, FileScanCompleted callback, FileContentGetter contentGetter)
 {
     return Scan(filePaths, termTables, callback, contentGetter, null);
 }
        private static IScanResult ScanFile(string filePath, MatchFinder finder, FileContentGetter contentGetter, ScanStopper stopper)
        {
            if (filePath == null)
            {
                throw new ArgumentNullException("filePath");
            }

            // See if the content getter can give us the file contents.  If so, we'll scan that
            // string rather than loading the file from disk.
            if (contentGetter != null)
            {
                string content = contentGetter(filePath);
                if (content != null)
                {
                    return ScanResult.ScanOccurred(filePath, GetScanHits(filePath, content, finder, stopper));
                }
            }

            StreamReader reader = null;

            try
            {
                try
                {
                    reader = File.OpenText(filePath);
                }
                catch (Exception ex)
                {
                    if (ex is UnauthorizedAccessException ||
                        ex is ArgumentException ||
                        ex is ArgumentNullException ||
                        ex is PathTooLongException ||
                        ex is DirectoryNotFoundException ||
                        ex is FileNotFoundException ||
                        ex is NotSupportedException ||
                        ex is IOException)
                    {
                        return ScanResult.ScanNotPossible(filePath);
                    }
                    else
                    {
                        throw;
                    }
                }

                return ScanResult.ScanOccurred(filePath, GetScanHits(filePath, reader, finder, stopper));
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }
        }