Example #1
0
        /// <summary>
        /// SrcML service starts to monitor the opened solution.
        /// </summary>
        /// <param name="srcMLArchiveDirectory"></param>
        /// <param name="shouldReset"></param>
        public void StartMonitoring(bool shouldReset, string srcMLBinaryDirectory)
        {
            // Get the path of the folder that storing the srcML archives
            var    openSolution  = GetOpenSolution();
            string baseDirectory = GetSrcMLArchiveFolder(openSolution);

            SrcMLFileLogger.DefaultLogger.Info("SrcMLGlobalService.StartMonitoring( " + baseDirectory + " )");
            try {
                if (shouldReset)
                {
                    SrcMLFileLogger.DefaultLogger.Info("Reset flag is set - Removing " + baseDirectory);
                    Directory.Delete(baseDirectory, true);
                }

                // Create a new instance of SrcML.NET's LastModifiedArchive
                LastModifiedArchive lastModifiedArchive = new LastModifiedArchive(baseDirectory, LastModifiedArchive.DEFAULT_FILENAME,
                                                                                  _taskManager.GlobalScheduler);

                // Create a new instance of SrcML.NET's SrcMLArchive
                SrcMLArchive sourceArchive = new SrcMLArchive(baseDirectory, SrcMLArchive.DEFAULT_ARCHIVE_DIRECTORY, true,
                                                              new SrcMLGenerator(srcMLBinaryDirectory),
                                                              new ShortXmlFileNameMapping(Path.Combine(baseDirectory, SrcMLArchive.DEFAULT_ARCHIVE_DIRECTORY)),
                                                              _taskManager.GlobalScheduler);
                CurrentSrcMLArchive = sourceArchive;

                // Create a new instance of SrcML.NET's solution monitor
                if (openSolution != null)
                {
                    CurrentMonitor = new SourceMonitor(openSolution, DirectoryScanningMonitor.DEFAULT_SCAN_INTERVAL,
                                                       _taskManager.GlobalScheduler, baseDirectory, lastModifiedArchive, sourceArchive);
                    CurrentMonitor.DirectoryAdded          += RespondToDirectoryAddedEvent;
                    CurrentMonitor.DirectoryRemoved        += RespondToDirectoryRemovedEvent;
                    CurrentMonitor.UpdateArchivesStarted   += CurrentMonitor_UpdateArchivesStarted;
                    CurrentMonitor.UpdateArchivesCompleted += CurrentMonitor_UpdateArchivesCompleted;
                    CurrentMonitor.AddDirectoriesFromSaveFile();
                    CurrentMonitor.AddSolutionDirectory();
                }

                // Subscribe events from Solution Monitor
                if (CurrentMonitor != null)
                {
                    CurrentMonitor.FileChanged += RespondToFileChangedEvent;

                    // Initialize the progress bar.
                    if (statusBar != null)
                    {
                        statusBar.Progress(ref cookie, 1, "", 0, 0);
                    }
                    // Start monitoring
                    var updateTask = CurrentMonitor.UpdateArchivesAsync();

                    CurrentMonitor.StartMonitoring();
                    OnMonitoringStarted(new EventArgs());
                    SaveTimer.Start();
                }
            } catch (Exception e) {
                SrcMLFileLogger.DefaultLogger.Error(SrcMLExceptionFormatter.CreateMessage(e, "Exception in SrcMLGlobalService.StartMonitoring()"));
            }
        }
Example #2
0
        /// <summary>
        /// SrcML service stops monitoring the opened solution.
        /// </summary>
        public void StopMonitoring()
        {
            SrcMLFileLogger.DefaultLogger.Info("SrcMLGlobalService.StopMonitoring()");
            try {
                if (CurrentMonitor != null && CurrentSrcMLArchive != null)
                {
                    OnMonitoringStopped(new EventArgs());
                    SaveTimer.Stop();
                    CurrentMonitor.StopMonitoring();
                    CurrentMonitor.FileChanged      -= RespondToFileChangedEvent;
                    CurrentMonitor.DirectoryAdded   -= RespondToDirectoryAddedEvent;
                    CurrentMonitor.DirectoryRemoved -= RespondToDirectoryRemovedEvent;
                    CurrentMonitor.Dispose();

                    CurrentSrcMLArchive = null;
                    CurrentMonitor      = null;
                }
            } catch (Exception e) {
                SrcMLFileLogger.DefaultLogger.Error(SrcMLExceptionFormatter.CreateMessage(e, "Exception in SrcMLGlobalService.StopMonitoring()"));
            }
        }