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.º 2
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>();
        }
Exemplo n.º 4
0
 public void ShutdownIndexer()
 {
     _indexer.ClearIndex();
     _indexer.Dispose(true);
 }
Exemplo n.º 5
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);
            }
        }