Ejemplo n.º 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()"));
            }
        }
 /// <summary>
 /// Starts monitoring
 /// </summary>
 public virtual void StartMonitoring()
 {
     GlobalTaskFactory.StartNew(Setup)
     .ContinueWith((t) => Update())
     .ContinueWith((t) => Save()).ContinueWith((t) => {
         IsMonitoring = true;
         SaveTimer.Start();
         StartMonitoringImpl();
     });
 }
 /// <summary>
 /// Start scanning <see cref="MonitoredDirectories">monitored directories</see> every
 /// <see cref="ScanInterval"/> seconds.
 /// </summary>
 /// <remarks>
 /// Has no effect if the monitor is already running.
 /// </remarks>
 public override void StartMonitoring()
 {
     ScanTimer.Start();
 }