public void GIVEN_FileLoggerNotInitialize_WHEN_SetupDefautlFileLoggerMethodIsCalled_AND_DefaultLoggerIsUsed_THEN_LogFileShouldBeCreatedAndContainLoggedMessage() { SandoLogManager.StartDefaultLogging(_directoryPath); LogEvents.TestLogging(this); var logFiles = Directory.GetFiles(_directoryPath).AsEnumerable().Where(f => f.Contains("Sando") && f.EndsWith(".log")).ToList(); Assert.IsTrue(logFiles.Any(), "There should be log file created!"); var content = File.ReadAllText(logFiles.First()); Assert.IsTrue(content.Contains("Message from the logger"), "Invalid log file content"); }
/// <summary> /// Default constructor of the package. /// Inside this method you can place any initialization code that does not require /// any Visual Studio service because at this point the package object is created but /// not sited yet inside Visual Studio environment. The place to do all the other /// initialization is the Initialize method. /// </summary> public UIPackage() { PathManager.Create(Assembly.GetAssembly(typeof(UIPackage)).Location); SandoLogManager.StartDefaultLogging(PathManager.Instance.GetExtensionRoot()); // Add callback methods to the service container to create the services. // Here we update the list of the provided services with the ones specific for this package. // Notice that we set to true the boolean flag about the service promotion for the global: // to promote the service is actually to proffer it globally using the SProfferService service. // For performance reasons we don’t want to instantiate the services now, but only when and // if some client asks for them, so we here define only the type of the service and a function // that will be called the first time the package will receive a request for the service. // This callback function is the one responsible for creating the instance of the service // object. IServiceContainer serviceContainer = this as IServiceContainer; ServiceCreatorCallback callback = new ServiceCreatorCallback(CreateService); serviceContainer.AddService(typeof(SSandoGlobalService), callback, true); serviceContainer.AddService(typeof(SSandoLocalService), callback); }
/// <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; } } } }); }