void StartCurrentConfig()
        {
            ScanDelegate scanDelegate = Scanner.Factory.GetScanner().Scan;

            //UpdateStatusBar(true, Resources.AppName, _filesProcessed, _totalFiles);

            var handler = Started;

            if (handler != null)
            {
                handler(this, EventArgs.Empty);
            }

            ScanStopper stopper = () => _stopPending;

            IsRunning = true;
            scanDelegate.BeginInvoke(
                _projectsToScan[_currentProject].FilesToScan,
                _projectsToScan[_currentProject].SearchingWord,
                new FileScanCompleted(ScanResultRecieved),
                new FileContentGetter(GetTextOfFileIfOpenInIde),
                stopper,
                ScanCompleted,
                null /* 'object' argument */);
        }
        /// <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;
        }
        void StartCurrentConfig()
        {
            ScanDelegate scanDelegate = CodeSweep.Scanner.Factory.GetScanner().Scan;

            List <ITermTable> termTables = new List <ITermTable>();

            foreach (string tableFile in _projectsToScan[_currentProject].TermTableFiles)
            {
                try
                {
                    termTables.Add(CodeSweep.Scanner.Factory.GetTermTable(tableFile));
                }
                catch (Exception ex)
                {
                    if (!(ex is ArgumentException || ex is System.Xml.XmlException))
                    {
                        throw;
                    }
                }
            }

            UpdateStatusBar(true, Resources.AppName, _filesProcessed, _totalFiles);

            var handler = Started;

            if (handler != null)
            {
                handler(this, EventArgs.Empty);
            }

            ScanStopper stopper = () => _stopPending;

            IsRunning = true;
            scanDelegate.BeginInvoke(
                _projectsToScan[_currentProject].FilesToScan,
                termTables,
                new FileScanCompleted(ScanResultRecieved),
                new FileContentGetter(GetTextOfFileIfOpenInIde),
                stopper,
                ScanCompleted,
                null /* 'object' argument */);
        }
        /// <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);
        }
        private static IEnumerable <IScanHit> GetScanHits(string filePath, string content, MatchFinder finder, ScanStopper stopper)
        {
            List <IScanHit> hits = new List <IScanHit>();

            MatchFoundCallback callback =
                (term, line, column, lineText, warning) => hits.Add(new ScanHit(filePath, line, column, lineText, term, warning));

            finder.Reset();

            foreach (char c in content)
            {
                if (stopper != null && stopper())
                {
                    break;
                }
                finder.AnalyzeNextCharacter(c, callback);
            }

            finder.Finish(callback);

            return(hits);
        }
        private static IEnumerable <IScanHit> GetScanHits(string filePath, StreamReader reader, MatchFinder finder, ScanStopper stopper)
        {
            List <IScanHit> hits = new List <IScanHit>();

            MatchFoundCallback callback =
                (term, line, column, lineText, warning) => hits.Add(new ScanHit(filePath, line, column, lineText, term, warning));

            finder.Reset();

            while (!reader.EndOfStream)
            {
                if (stopper != null && stopper())
                {
                    break;
                }
                finder.AnalyzeNextCharacter((char)reader.Read(), callback);
            }

            finder.Finish(callback);

            return(hits);
        }
        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();
                }
            }
        }
        private static IEnumerable<IScanHit> GetScanHits(string filePath, string content, MatchFinder finder, ScanStopper stopper)
        {
            List<IScanHit> hits = new List<IScanHit>();

            MatchFoundCallback callback =
                (term, line, column, lineText, warning) => hits.Add(new ScanHit(filePath, line, column, lineText, term, warning));

            finder.Reset();

            foreach (char c in content)
            {
                if (stopper != null && stopper())
                {
                    break;
                }
                finder.AnalyzeNextCharacter(c, callback);
            }

            finder.Finish(callback);

            return hits;
        }
        private static IEnumerable<IScanHit> GetScanHits(string filePath, StreamReader reader, MatchFinder finder, ScanStopper stopper)
        {
            List<IScanHit> hits = new List<IScanHit>();

            MatchFoundCallback callback =
                (term, line, column, lineText, warning) => hits.Add(new ScanHit(filePath, line, column, lineText, term, warning));

            finder.Reset();

            while (!reader.EndOfStream)
            {
                if (stopper != null && stopper())
                {
                    break;
                }
                finder.AnalyzeNextCharacter((char)reader.Read(), callback);
            }

            finder.Finish(callback);

            return hits;
        }
        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();
                }
            }
        }