Beispiel #1
0
 void RespondToMonitoringStarted(object sender, EventArgs e)
 {
     CurrentDataRepository = new DataRepository(_srcMLService.GetSrcMLArchive(), Scheduler);
     CurrentDataRepository.FileProcessed += RespondToFileProcessed;
     if (_srcMLService.IsUpdating)
     {
         _srcMLService.UpdateArchivesCompleted += GenerateDataAfterUpdate;
     }
     else
     {
         GenerateDataAfterUpdate(this, e);
     }
     OnMonitoringStarted(e);
 }
        public void CheckCSharpSolutionStartup()
        {
            SrcMLArchive archive = srcMLService.GetSrcMLArchive();

            Assert.IsNotNull(archive, "GetSrcMLArchive returned null.");
            string sourcePath = Path.Combine(testCSharpProjectFolder, "Class1.cs");
            string srcMLPath  = archive.GetXmlPathForSourcePath(sourcePath);

            Assert.IsTrue(File.Exists(sourcePath), "The source file [" + sourcePath + "] does not exist.");
            Assert.IsTrue(File.Exists(srcMLPath), "The srcML file [" + srcMLPath + "] does not exist.");
            Assert.AreEqual(new FileInfo(sourcePath).LastWriteTime, new FileInfo(srcMLPath).LastWriteTime);
            XElement xelement = srcMLService.GetXElementForSourceFile(sourcePath);

            Assert.IsNotNull(xelement, "GetXElementForSourceFile returned null.");
            string   sourcePathX = Path.Combine(testCSharpProjectFolder, "AlreadyDeletedClass1.cs");
            XElement xelementX   = srcMLService.GetXElementForSourceFile(sourcePathX);

            Assert.IsNull(xelementX, "GetXElementForSourceFile returned not null.");
        }
        /// <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;
                        }
                    }
                }
            });
        }