Exemplo n.º 1
0
 public MessageProcessor(IBus bus, DocumentIndexer <People> peopleIndexer,
                         ClientIndexer clientIndexer1)
 {
     _bus           = bus;
     _peopleIndexer = peopleIndexer;
     _clientIndexer = clientIndexer1;
 }
        private void CreateIndexer()
        {
            ServiceLocator.Resolve <UIPackage>();

            ServiceLocator.RegisterInstance(new IndexFilterManager());

            PerFieldAnalyzerWrapper analyzer = new PerFieldAnalyzerWrapper(new SnowballAnalyzer("English"));

            analyzer.AddAnalyzer(SandoField.Source.ToString(), new KeywordAnalyzer());
            analyzer.AddAnalyzer(SandoField.AccessLevel.ToString(), new KeywordAnalyzer());
            analyzer.AddAnalyzer(SandoField.ProgramElementType.ToString(), new KeywordAnalyzer());
            ServiceLocator.RegisterInstance <Analyzer>(analyzer);

            var currentIndexer = new DocumentIndexer(TimeSpan.FromSeconds(10), GetTimeToCommit());

            ServiceLocator.RegisterInstance(currentIndexer);
            ServiceLocator.RegisterInstance(new IndexUpdateManager());
            currentIndexer.ClearIndex();
            ServiceLocator.Resolve <InitialIndexingWatcher>().InitialIndexingStarted();

            var dictionary = new DictionaryBasedSplitter();

            dictionary.Initialize(PathManager.Instance.GetIndexPath(ServiceLocator.Resolve <SolutionKey>()));

            var reformer = new QueryReformerManager(dictionary);

            reformer.Initialize(null);
            ServiceLocator.RegisterInstance(reformer);

            var history = new SearchHistory();

            history.Initialize(PathManager.Instance.GetIndexPath
                                   (ServiceLocator.Resolve <SolutionKey>()));
            ServiceLocator.RegisterInstance(history);
        }
Exemplo n.º 3
0
        private bool EnsureSolutionOpen()
        {
            DocumentIndexer indexer = null;
            var             isOpen  = true;

            try
            {
                indexer = ServiceLocator.Resolve <DocumentIndexer>();
                if (indexer == null || indexer.IsDisposingOrDisposed())
                {
                    _searchResultListener.UpdateMessage("Sando searches only the currently open Solution.  Please open a Solution and try again.");
                    isOpen = false;
                }
            }
            catch (Exception e)
            {
                _searchResultListener.UpdateMessage("Sando searches only the currently open Solution.  Please open a Solution and try again.");
                if (indexer != null)
                {
                    LogEvents.UISolutionOpeningError(this, e);
                }
                isOpen = false;
            }
            return(isOpen);
        }
Exemplo n.º 4
0
        public void CreateIndexer()
        {
            TestUtils.InitializeDefaultExtensionPoints();

            _indexerPath = Path.GetTempPath() + "luceneindexer";
            Directory.CreateDirectory(_indexerPath);
            _solutionKey = new SolutionKey(Guid.NewGuid(), "C:/SolutionPath");
            ServiceLocator.RegisterInstance(_solutionKey);
            ServiceLocator.RegisterInstance <Analyzer>(new SimpleAnalyzer());
            _indexer = new DocumentIndexer(TimeSpan.FromSeconds(1));
            ServiceLocator.RegisterInstance(_indexer);

            ClassElement classElement = SampleProgramElementFactory.GetSampleClassElement(
                accessLevel: AccessLevel.Public,
                definitionLineNumber: 11,
                extendedClasses: "SimpleClassBase",
                fullFilePath: "C:/Projects/SimpleClass.cs",
                implementedInterfaces: "IDisposable",
                name: "SimpleName",
                namespaceName: "Sanod.Indexer.UnitTests"
                );
            SandoDocument sandoDocument = DocumentFactory.Create(classElement);

            _indexer.AddDocument(sandoDocument);
            MethodElement methodElement = SampleProgramElementFactory.GetSampleMethodElement(
                accessLevel: AccessLevel.Protected,
                name: "SimpleName",
                returnType: "Void",
                fullFilePath: "C:/stuff"
                );

            sandoDocument = DocumentFactory.Create(methodElement);
            _indexer.AddDocument(sandoDocument);
        }
Exemplo n.º 5
0
        public void CreateIndexer()
        {
            TestUtils.InitializeDefaultExtensionPoints();

            _indexerPath = Path.GetTempPath() + "luceneindexer";
            Directory.CreateDirectory(_indexerPath);
            _solutionKey = new SolutionKey(Guid.NewGuid(), "C:/SolutionPath");
            ServiceLocator.RegisterInstance(_solutionKey);
            ServiceLocator.RegisterInstance<Analyzer>(new SimpleAnalyzer());
            _indexer = new DocumentIndexer();
            ServiceLocator.RegisterInstance(_indexer);

            ClassElement classElement = SampleProgramElementFactory.GetSampleClassElement(
                accessLevel: AccessLevel.Public,
                definitionLineNumber: 11,
                extendedClasses: "SimpleClassBase",
                fullFilePath: "C:/Projects/SimpleClass.cs",
                implementedInterfaces: "IDisposable",
                name: "SimpleName",
                namespaceName: "Sanod.Indexer.UnitTests"
            );
            SandoDocument sandoDocument = DocumentFactory.Create(classElement);
            _indexer.AddDocument(sandoDocument);
            MethodElement methodElement = SampleProgramElementFactory.GetSampleMethodElement(
                accessLevel: AccessLevel.Protected,
                name: "SimpleName",
                returnType: "Void",
                fullFilePath: "C:/stuff"
            );
            sandoDocument = DocumentFactory.Create(methodElement);
            _indexer.AddDocument(sandoDocument);
            Thread.Sleep(2000);
        }
 public void CloseAndReopen()
 {
     var indexer = ServiceLocator.Resolve<DocumentIndexer>();
     indexer.Dispose();
     var currentIndexer = new DocumentIndexer();
     ServiceLocator.RegisterInstance(currentIndexer);
     Assert.IsTrue(currentIndexer.GetNumberOfIndexedDocuments() > 5, "The index is being destroyed when it is closed and reopened");
 }
Exemplo n.º 7
0
        public void CloseAndReopen()
        {
            var indexer = ServiceLocator.Resolve <DocumentIndexer>();

            indexer.Dispose();
            var currentIndexer = new DocumentIndexer(TimeSpan.FromSeconds(10), GetTimeToCommit());

            ServiceLocator.RegisterInstance(currentIndexer);
            Assert.IsTrue(currentIndexer.GetNumberOfIndexedDocuments() > 5, "The index is being destroyed when it is closed and reopened");
        }
Exemplo n.º 8
0
 public void DocumentIndexer_ConstructorDoesNotThrowWhenValidData()
 {
     try
     {
         _documentIndexer = new DocumentIndexer();
     }
     catch(Exception ex)
     {
         Assert.Fail(ex.Message + ". " + ex.StackTrace);
     }
 }
Exemplo n.º 9
0
 public void DocumentIndexer_ConstructorDoesNotThrowWhenValidData()
 {
     try
     {
         _documentIndexer = new DocumentIndexer();
     }
     catch (Exception ex)
     {
         Assert.Fail(ex.Message + ". " + ex.StackTrace);
     }
 }
Exemplo n.º 10
0
 public void DocumentIndexer_AddDocumentThrowsWhenProgramElementIsNull()
 {
     _documentIndexer = new DocumentIndexer();
     try
     {
         _documentIndexer.AddDocument(null);
     }
     catch
     {
         //contract exception catched here
     }
     Assert.True(_contractFailed, "Contract should fail!");
 }
Exemplo n.º 11
0
        public void CreateIndexer()
        {
            TestUtils.InitializeDefaultExtensionPoints();

            _indexerPath = Path.GetTempPath() + "luceneindexer";
            Directory.CreateDirectory(_indexerPath);
            _solutionKey = new SolutionKey(Guid.NewGuid(), "C:/SolutionPath");
            ServiceLocator.RegisterInstance(_solutionKey);
            ServiceLocator.RegisterInstance<Analyzer>(new SimpleAnalyzer());
            _indexer = new DocumentIndexer();
            ServiceLocator.RegisterInstance(_indexer);
            ServiceLocator.RegisterInstance<ISandoOptionsProvider>(new FakeOptionsProvider(String.Empty, 20, false, new List<string>()));

            // xige
            var dictionary = new DictionaryBasedSplitter();
            dictionary.Initialize(PathManager.Instance.GetIndexPath(ServiceLocator.Resolve<SolutionKey>()));
            ServiceLocator.RegisterInstance(dictionary);

            var reformer = new QueryReformerManager(dictionary);
            reformer.Initialize(null);
            ServiceLocator.RegisterInstance(reformer);

            var history = new SearchHistory();
            history.Initialize(PathManager.Instance.GetIndexPath
                (ServiceLocator.Resolve<SolutionKey>()));
            ServiceLocator.RegisterInstance(history);

            ClassElement classElement = SampleProgramElementFactory.GetSampleClassElement(
                accessLevel: AccessLevel.Public,
                definitionLineNumber: 11,
                extendedClasses: "SimpleClassBase",
                fullFilePath: "C:/Projects/SimpleClass.cs",
                implementedInterfaces: "IDisposable",
                name: "SimpleName",
                namespaceName: "Sanod.Indexer.UnitTests"
            );
            SandoDocument sandoDocument = DocumentFactory.Create(classElement);
            _indexer.AddDocument(sandoDocument);
            MethodElement methodElement = SampleProgramElementFactory.GetSampleMethodElement(
                accessLevel: AccessLevel.Protected,
                name: "SimpleName",
                returnType: "Void",
                fullFilePath: "C:/stuff"
            );
            sandoDocument = DocumentFactory.Create(methodElement);
            _indexer.AddDocument(sandoDocument);
            Thread.Sleep(2000);
        }
Exemplo n.º 12
0
 public void DocumentIndexer_AddDocumentDoesNotThrowWhenValidData()
 {
     try
     {
         _documentIndexer = new DocumentIndexer();
         ClassElement classElement = SampleProgramElementFactory.GetSampleClassElement();
         SandoDocument sandoDocument = DocumentFactory.Create(classElement);
         Assert.NotNull(sandoDocument);
         Assert.NotNull(sandoDocument.GetDocument());
         _documentIndexer.AddDocument(sandoDocument);
     }
     catch(Exception ex)
     {
         Assert.Fail(ex.Message + ". " + ex.StackTrace);
     }
 }
Exemplo n.º 13
0
 public void DocumentIndexer_AddDocumentDoesNotThrowWhenValidData()
 {
     try
     {
         _documentIndexer = new DocumentIndexer();
         ClassElement  classElement  = SampleProgramElementFactory.GetSampleClassElement();
         SandoDocument sandoDocument = DocumentFactory.Create(classElement);
         Assert.NotNull(sandoDocument);
         Assert.NotNull(sandoDocument.GetDocument());
         _documentIndexer.AddDocument(sandoDocument);
     }
     catch (Exception ex)
     {
         Assert.Fail(ex.Message + ". " + ex.StackTrace);
     }
 }
Exemplo n.º 14
0
 public void DocumentIndexer_DeleteDocuments()
 {
     try
     {
         TestUtils.ClearDirectory(PathManager.Instance.GetIndexPath(ServiceLocator.Resolve <SolutionKey>()));
         _documentIndexer = new DocumentIndexer(TimeSpan.FromSeconds(1));
         MethodElement sampleMethodElement = SampleProgramElementFactory.GetSampleMethodElement();
         _documentIndexer.AddDocument(DocumentFactory.Create(sampleMethodElement));
         int numDocs = _documentIndexer.GetNumberOfIndexedDocuments();
         Assert.IsTrue(numDocs == 1);
         _documentIndexer.DeleteDocuments(sampleMethodElement.FullFilePath);
         int docs = _documentIndexer.GetNumberOfIndexedDocuments();
         Assert.IsTrue(docs == 0);
     }
     catch (Exception ex)
     {
         Assert.Fail(ex.Message + ". " + ex.StackTrace);
     }
 }
Exemplo n.º 15
0
 public void GIVEN_DocumentIndexer_WHEN_IndexSearcherIsClosed_AND_SearchFailed_THEN_IndexSearcherIsRecreated_AND_SearchReturnsResults()
 {
     try
     {
         TestUtils.ClearDirectory(PathManager.Instance.GetIndexPath(ServiceLocator.Resolve <SolutionKey>()));
         _documentIndexer = new DocumentIndexer(TimeSpan.FromMilliseconds(500));
         var sampleMethodElement = SampleProgramElementFactory.GetSampleMethodElement();
         _documentIndexer.AddDocument(DocumentFactory.Create(sampleMethodElement));
         const string searchQueryString = "body: sth";
         var          query             = _documentIndexer.QueryParser.Parse(searchQueryString);
         int          hitsPerPage       = SearchCriteria.DefaultNumberOfSearchResultsReturned;
         var          collector         = TopScoreDocCollector.create(hitsPerPage, true);
         _documentIndexer.NUnit_CloseIndexSearcher();
         _documentIndexer.Search(query, collector);
     }
     catch (Exception ex)
     {
         Assert.Fail(ex.Message + ". " + ex.StackTrace);
     }
 }
Exemplo n.º 16
0
 public void DocumentIndexer_DeleteDocuments()
 {
     try
     {
         TestUtils.ClearDirectory(PathManager.Instance.GetIndexPath(ServiceLocator.Resolve<SolutionKey>()));
         _documentIndexer = new DocumentIndexer();
         MethodElement sampleMethodElement = SampleProgramElementFactory.GetSampleMethodElement();
         _documentIndexer.AddDocument(DocumentFactory.Create(sampleMethodElement));
         Thread.Sleep(2000);
         int numDocs = _documentIndexer.GetNumberOfIndexedDocuments();
         Assert.IsTrue(numDocs == 1);
         _documentIndexer.DeleteDocuments(sampleMethodElement.FullFilePath);
         Thread.Sleep(2000);
         int docs = _documentIndexer.GetNumberOfIndexedDocuments();
         Assert.IsTrue(docs == 0);
     }
     catch (Exception ex)
     {
         Assert.Fail(ex.Message + ". " + ex.StackTrace);
     }
 }
Exemplo n.º 17
0
        public void CheckFolderForExpectedResults(string searchString, string methodNameToFind, string solutionPath)
        {
            ServiceLocator.RegisterInstance<Analyzer>(new SnowballAnalyzer("English"));
            _indexer = new DocumentIndexer();
            ServiceLocator.RegisterInstance(_indexer);

            try
            {
                IndexFilesInDirectory(solutionPath);
                Thread.Sleep(2000);
                var results = GetResults(searchString);
                Assert.IsTrue(HasResults(methodNameToFind, results), "Can't find expected results");
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message + ". " + ex.StackTrace);
            }
            finally
            {
                if (_indexer != null)
                    _indexer.Dispose(true);
            }
        }
Exemplo n.º 18
0
        public void CheckFolderForExpectedResults(string searchString, string methodNameToFind, string solutionPath)
        {
            ServiceLocator.RegisterInstance <Analyzer>(new SnowballAnalyzer("English"));
            _indexer = new DocumentIndexer(TimeSpan.FromSeconds(1));
            ServiceLocator.RegisterInstance(_indexer);

            try
            {
                IndexFilesInDirectory(solutionPath);
                var results = GetResults(searchString);
                Assert.IsTrue(HasResults(methodNameToFind, results), "Can't find expected results");
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message + ". " + ex.StackTrace);
            }
            finally
            {
                if (_indexer != null)
                {
                    _indexer.Dispose(true);
                }
            }
        }
Exemplo n.º 19
0
        /// <summary>
        /// Respond to solution opening.
        /// Still use Sando's SolutionMonitorFactory because Sando's SolutionMonitorFactory has too much indexer code which is specific with Sando.
        /// </summary>
        private void RespondToSolutionOpened(object sender, DoWorkEventArgs ee)
        {
            try
            {
                updatedForThisSolution = false;
                //TODO if solution is reopen - the guid should be read from file - future change
                var solutionId   = Guid.NewGuid();
                var openSolution = ServiceLocator.Resolve <DTE2>().Solution;
                var solutionPath = openSolution.FileName;
                var key          = new SolutionKey(solutionId, solutionPath);
                ServiceLocator.RegisterInstance(key);

                var  sandoOptions = ServiceLocator.Resolve <ISandoOptionsProvider>().GetSandoOptions();
                bool isIndexRecreationRequired = IndexStateManager.IsIndexRecreationRequired();
                isIndexRecreationRequired = isIndexRecreationRequired || !PathManager.Instance.IndexPathExists(key);

                ServiceLocator.RegisterInstance(new IndexFilterManager());

                ServiceLocator.RegisterInstance <Analyzer>(GetAnalyzer());
                SrcMLArchiveEventsHandlers srcMLArchiveEventsHandlers = ServiceLocator.Resolve <SrcMLArchiveEventsHandlers>();
                var currentIndexer = new DocumentIndexer(srcMLArchiveEventsHandlers, TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(10));
                ServiceLocator.RegisterInstance(currentIndexer);

                ServiceLocator.RegisterInstance(new IndexUpdateManager());

                if (isIndexRecreationRequired)
                {
                    currentIndexer.ClearIndex();
                }

                ServiceLocator.Resolve <InitialIndexingWatcher>().InitialIndexingStarted();

                // JZ: SrcMLService Integration
                // Get the SrcML Service.
                srcMLService = GetService(typeof(SSrcMLGlobalService)) as ISrcMLGlobalService;
                if (null == srcMLService)
                {
                    throw new Exception("Can not get the SrcML global service.");
                }
                else
                {
                    ServiceLocator.RegisterInstance(srcMLService);
                }
                // Register all types of events from the SrcML Service.

                if (!SetupHandlers)
                {
                    SetupHandlers = true;
                    srcMLService.SourceFileChanged += srcMLArchiveEventsHandlers.SourceFileChanged;
                    srcMLService.MonitoringStopped += srcMLArchiveEventsHandlers.MonitoringStopped;
                }

                //This is done here because some extension points require data that isn't set until the solution is opened, e.g. the solution key or the srcml archive
                //However, registration must happen before file monitoring begins below.
                RegisterExtensionPoints();

                SwumManager.Instance.Initialize(PathManager.Instance.GetIndexPath(ServiceLocator.Resolve <SolutionKey>()), !isIndexRecreationRequired);
                //SwumManager.Instance.Archive = _srcMLArchive;

                ////XQ: for testing
                //ISandoGlobalService sandoService = GetService(typeof(SSandoGlobalService)) as ISandoGlobalService;
                //var res = sandoService.GetSearchResults("Monster");

                // xige
                var dictionary = new DictionaryBasedSplitter();
                dictionary.Initialize(PathManager.Instance.GetIndexPath(ServiceLocator.Resolve <SolutionKey>()));
                ServiceLocator.Resolve <IndexUpdateManager>().indexUpdated +=
                    dictionary.UpdateProgramElement;
                ServiceLocator.RegisterInstance(dictionary);

                var reformer = new QueryReformerManager(dictionary);
                reformer.Initialize(null);
                ServiceLocator.RegisterInstance(reformer);

                var history = new SearchHistory();
                history.Initialize(PathManager.Instance.GetIndexPath
                                       (ServiceLocator.Resolve <SolutionKey>()));
                ServiceLocator.RegisterInstance(history);


                // End of code changes

                if (sandoOptions.AllowDataCollectionLogging)
                {
                    SandoLogManager.StartDataCollectionLogging(PathManager.Instance.GetExtensionRoot());
                }
                else
                {
                    SandoLogManager.StopDataCollectionLogging();
                }
                LogEvents.SolutionOpened(this, Path.GetFileName(solutionPath));

                if (isIndexRecreationRequired)
                {
                    //just recreate the whole index
                    var indexingTask = System.Threading.Tasks.Task.Factory.StartNew(() =>
                    {
                        Collection <string> files = null;
                        while (files == null)
                        {
                            try
                            {
                                files = srcMLService.GetSrcMLArchive().GetFiles();
                            }
                            catch (NullReferenceException ne)
                            {
                                System.Threading.Thread.Sleep(3000);
                            }
                        }
                        foreach (var file in srcMLService.GetSrcMLArchive().FileUnits)
                        {
                            var fileName = ABB.SrcML.SrcMLElement.GetFileNameForUnit(file);
                            srcMLArchiveEventsHandlers.SourceFileChanged(srcMLService, new FileEventRaisedArgs(FileEventType.FileAdded, fileName));
                        }
                        srcMLArchiveEventsHandlers.WaitForIndexing();
                    });
                }
                else
                {
                    //make sure you're not missing any files
                    var indexingTask = System.Threading.Tasks.Task.Factory.StartNew(() =>
                    {
                        Collection <string> files = null;
                        while (files == null)
                        {
                            try
                            {
                                files = srcMLService.GetSrcMLArchive().GetFiles();
                            }
                            catch (NullReferenceException ne)
                            {
                                System.Threading.Thread.Sleep(3000);
                            }
                        }
                        foreach (var fileName in srcMLService.GetSrcMLArchive().GetFiles())
                        {
                            srcMLArchiveEventsHandlers.SourceFileChanged(srcMLService, new FileEventRaisedArgs(FileEventType.FileRenamed, fileName));
                        }
                        srcMLArchiveEventsHandlers.WaitForIndexing();
                    });
                }
            }
            catch (Exception e)
            {
                LogEvents.UIRespondToSolutionOpeningError(this, e);
            }
            var updateListedFoldersTask = System.Threading.Tasks.Task.Factory.StartNew(() =>
            {
                bool done = false;
                while (!done)
                {
                    System.Threading.Thread.Sleep(2000);
                    if (srcMLService != null)
                    {
                        if (srcMLService.MonitoredDirectories != null)
                        {
                            UpdateIndexingFilesList();
                            done = true;
                        }
                    }
                }
            });
        }
        public void CreateIndexer()
        {
            ServiceLocator.Resolve<UIPackage>();

            ServiceLocator.RegisterInstance(new IndexFilterManager());

            Analyzer analyzer = SnowballAndWordSplittingAnalyzer.GetAnalyzer();
            ServiceLocator.RegisterInstance<Analyzer>(analyzer);

            var currentIndexer = new DocumentIndexer();
            ServiceLocator.RegisterInstance(currentIndexer);
            ServiceLocator.RegisterInstance(new IndexUpdateManager());
            currentIndexer.ClearIndex();
            ServiceLocator.Resolve<InitialIndexingWatcher>().SetInitialIndexingStarted();

            var dictionary = new DictionaryBasedSplitter();
            dictionary.Initialize(PathManager.Instance.GetIndexPath(ServiceLocator.Resolve<SolutionKey>()));
            ServiceLocator.RegisterInstance(dictionary);

            var reformer = new QueryReformerManager(dictionary);
            reformer.Initialize(null);
            ServiceLocator.RegisterInstance(reformer);

            var history = new SearchHistory();
            history.Initialize(PathManager.Instance.GetIndexPath
                (ServiceLocator.Resolve<SolutionKey>()));
            ServiceLocator.RegisterInstance(history);

            ServiceLocator.RegisterType<IIndexerSearcher<SimpleSearchCriteria>, SimpleIndexerSearcher>();
        }
        private static void ProcessFileEvent(ISrcMLGlobalService srcMLService, FileEventRaisedArgs args,
            bool commitImmediately, DocumentIndexer documentIndexer)
        {
            string sourceFilePath = args.FilePath;
            var fileExtension = Path.GetExtension(sourceFilePath);
            var parsableToXml = (ExtensionPointsRepository.Instance.GetParserImplementation(fileExtension) != null);
            if (ConcurrentIndexingMonitor.TryToLock(sourceFilePath)) return;
            XElement xelement = null;
            if (parsableToXml)
            {
                xelement = GetXElement(args, srcMLService);
                if (xelement == null && args.EventType != FileEventType.FileDeleted) return;
            }
            var indexUpdateManager = ServiceLocator.Resolve<IndexUpdateManager>();
            try
            {
                switch (args.EventType)
                {
                    case FileEventType.FileAdded:
                        documentIndexer.DeleteDocuments(sourceFilePath.ToLowerInvariant()); //"just to be safe!"
                        indexUpdateManager.Update(sourceFilePath.ToLowerInvariant(), xelement);
                        if (parsableToXml)
                        {
                            SwumManager.Instance.AddSourceFile(sourceFilePath.ToLowerInvariant(), xelement);
                        }
                        break;

                    case FileEventType.FileChanged:
                        documentIndexer.DeleteDocuments(sourceFilePath.ToLowerInvariant());
                        indexUpdateManager.Update(sourceFilePath.ToLowerInvariant(), xelement);
                        if (parsableToXml)
                        {
                            SwumManager.Instance.UpdateSourceFile(sourceFilePath.ToLowerInvariant(), xelement);
                        }
                        break;

                    case FileEventType.FileDeleted:
                        documentIndexer.DeleteDocuments(sourceFilePath.ToLowerInvariant(), commitImmediately);
                        if (parsableToXml)
                        {
                            SwumManager.Instance.RemoveSourceFile(sourceFilePath.ToLowerInvariant());
                        }
                        break;

                    case FileEventType.FileRenamed:
                        // FileRenamed is repurposed. Now means you may already know about it, so
                        // check and only parse if not existing
                        if (!SwumManager.Instance.ContainsFile(sourceFilePath.ToLowerInvariant()))
                        {
                            documentIndexer.DeleteDocuments(sourceFilePath.ToLowerInvariant()); //"just to be safe!"
                            indexUpdateManager.Update(sourceFilePath.ToLowerInvariant(), xelement);
                            if (parsableToXml)
                            {
                                SwumManager.Instance.AddSourceFile(sourceFilePath.ToLowerInvariant(), xelement);
                            }
                        }
                        break;

                    default:
                        // if we get here, a new event was probably added. for now, no-op
                        break;
                }
            }
            catch (AlreadyClosedException ace)
            {
                //ignore, index closed
            }
            ConcurrentIndexingMonitor.ReleaseLock(sourceFilePath);
        }
Exemplo n.º 22
0
 public IndexUpdateManager()
 {
     _currentIndexer = ServiceLocator.Resolve<DocumentIndexer>();
 }
Exemplo n.º 23
0
        private void ProcessDirectory(DocumentIndexer docIndexer, string directoryName)
        {
            try
            {
                docIndexer.IndexFolder(directoryName);
            }
            catch (Exception e)
            {
                logger.Error("Exception indexing folder {0}: {1}", directoryName, e);
            }

            try
            {
                foreach (var name in System.IO.Directory.GetDirectories(directoryName))
                {
                    queuedFolders.Enqueue(name);
                }
            }
            catch (Exception ex)
            {
                logger.Error("Error getting directories for {0}: {1}", directoryName, ex);
            }
        }
Exemplo n.º 24
0
        public void Execute(IJobExecutionContext context)
        {
            stop = false;
            running = true;

            try
            {
                using (var docIndexer = new DocumentIndexer())
                {
                    startTime = DateTime.Now;

                    var validFolders = new List<string>();
                    foreach (var folderName in Preferences.Instance.FoldersToWatch)
                    {
                        if (!System.IO.Directory.Exists(folderName))
                        {
                            logger.Warn("Folder does not exist: '{0}'", folderName);
                            continue;
                        }

                        validFolders.Add(folderName);
                    }

                    docIndexer.SetBaseFolders(validFolders);
                    foreach (var folderName in validFolders)
                    {
                        logger.Info("{1}: Scanning '{0}'", folderName, DateTime.Now.ToShortDateString());
                        queuedFolders.Enqueue(folderName);
                    }


                    var tasks = new List<Task>();
                    tasks.Add(Task.Run( () => DequeueFolders(docIndexer) ));
                    tasks.Add(Task.Run( () => DequeueFolders(docIndexer) ));
                    Task.WaitAll(tasks.ToArray());

                    docIndexer.FolderEnumerationCompleted();
                    var seconds = (DateTime.Now - startTime).TotalSeconds;
                    logger.Info("Processed {0} files in {1:N0} seconds ({2:N2} files/second); added {3} files", 
                        docIndexer.FileNumber,
                        seconds,
                        docIndexer.FileNumber / seconds,
                        docIndexer.FilesAdded);

                    docIndexer.WaitForCompletion(() => stop );

                    if (!stop)
                    {
                        startTime = DateTime.Now;

                        docIndexer.RemoveDeletedFiles();

                        seconds = (DateTime.Now - startTime).TotalSeconds;
                        logger.Info("Removed {0} files in {1:N0} seconds", docIndexer.FilesRemoved, seconds);
                    }

                }
            }
            catch (Exception ex)
            {
                logger.Error("Run error: {0}: {1}", ex.Message, ex);
            }
            finally
            {
                running = false;
            }
        }
Exemplo n.º 25
0
        private void DequeueFolders(DocumentIndexer indexer)
        {
            while (queuedFolders.Count > 0 && !stop)
            {
                string folderName;
                if (queuedFolders.TryDequeue(out folderName))
                {
                    ProcessDirectory(indexer, folderName);
                }
            }

            logger.Debug("Exiting DequeueFolders");
        }
Exemplo n.º 26
0
 public void GIVEN_DocumentIndexer_WHEN_IndexSearcherIsClosed_THEN_IndexSearcherIsRecreatedInBackgroundThread_AND_SearchReturnsResults()
 {
     try
     {
         TestUtils.ClearDirectory(PathManager.Instance.GetIndexPath(ServiceLocator.Resolve<SolutionKey>()));
         _documentIndexer = new DocumentIndexer();
         var sampleMethodElement = SampleProgramElementFactory.GetSampleMethodElement();
         _documentIndexer.AddDocument(DocumentFactory.Create(sampleMethodElement));
         const string searchQueryString = "body: sth";
         var query = _documentIndexer.QueryParser.Parse(searchQueryString);
         int hitsPerPage = SearchCriteria.DefaultNumberOfSearchResultsReturned;
         var collector = TopScoreDocCollector.create(hitsPerPage, true);
         _documentIndexer.NUnit_CloseIndexSearcher();
         Thread.Sleep(600);
         _documentIndexer.Search(query, collector);
     }
     catch (Exception ex)
     {
         Assert.Fail(ex.Message + ". " + ex.StackTrace);
     }
 }
Exemplo n.º 27
0
 public IndexUpdateManager()
 {
     _currentIndexer = ServiceLocator.Resolve <DocumentIndexer>();
 }
Exemplo n.º 28
0
        /// <summary>
        /// Respond to solution opening. Still use Sando's SolutionMonitorFactory because Sando's
        /// SolutionMonitorFactory has too much indexer code which is specific with Sando.
        /// </summary>
        private void RespondToSolutionOpened(object sender, DoWorkEventArgs ee)
        {
            try
            {
                SolutionKey key = SetupSolutionKey();

                bool isIndexRecreationRequired = IndexStateManager.IsIndexRecreationRequired();
                isIndexRecreationRequired = isIndexRecreationRequired || !PathManager.Instance.IndexPathExists(key);

                //Setup indexers
                ServiceLocator.RegisterInstance(new IndexFilterManager());
                ServiceLocator.RegisterInstance<Analyzer>(SnowballAndWordSplittingAnalyzer.GetAnalyzer());
                var srcMLArchiveEventsHandlers = ServiceLocator.Resolve<SrcMLArchiveEventsHandlers>();
                var currentIndexer = new DocumentIndexer(TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(5));
                ServiceLocator.RegisterInstance(currentIndexer);
                ServiceLocator.RegisterInstance(new IndexUpdateManager());

                if (isIndexRecreationRequired)
                {
                    currentIndexer.ClearIndex();
                }
                RegisterExtensionPoints();
                SwumManager.Instance.Initialize(PathManager.Instance.GetIndexPath(ServiceLocator.Resolve<SolutionKey>()), !isIndexRecreationRequired);
                SetupRecommenderSystem();
                SetupDataLogging();
                LogEvents.SolutionOpened(this, Path.GetFileName(key.GetSolutionPath()));

                GetSandoService(); // Ensure that the service exists and is resolvable (by SrcMLArchiveEventHandlers)
                if (isIndexRecreationRequired)
                {
                    RecreateEntireIndex();
                }
                else
                {
                    EnsureNoMissingFilesAndNoDeletedFiles();
                }

                RegisterSrcMLHandlers(ServiceLocator.Resolve<SrcMLArchiveEventsHandlers>());
            }
            catch (Exception e)
            {
                LogEvents.UIRespondToSolutionOpeningError(this, e);
            }
        }