示例#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>
        /// Handle project addition/deletion cases. The way these parameters work is:
        /// pHierarchy: Pointer to the IVsHierarchy interface of the project being loaded or closed.
        /// fAddedRemoved: For addition, true if the project is added to the solution after the
        ///                solution is opened, false if the project is added to the solution while
        ///                the solution is being opened. For deletion, true if the project was
        ///                removed from the solution before the solution was closed, false if the
        ///                project was removed from the solution while the solution was being
        ///                closed.
        /// type: FileEventType.FileAdded - project addition, FileEventType.FileDeleted - project
        ///       deletion.
        /// TODO: may process files in parallel
        /// </summary>
        /// <param name="pHierarchy"></param>
        /// <param name="fAddedRemoved"></param>
        /// <param name="type"></param>
        public void NotifyProjectAddRemove(IVsHierarchy pHierarchy, int fAddedRemoved, FileEventType type)
        {
            List <string> fileList = new List <string>();
            string        projectName;

            pHierarchy.GetCanonicalName(VSConstants.VSITEMID_ROOT, out projectName);
            //SrcMLFileLogger.DefaultLogger.Info("Project Name: [" + projectName + "]");

            // Find out this project in the solution tree
            var allProjects = OpenSolution.getProjects();
            var enumerator  = allProjects.GetEnumerator();

            while (enumerator.MoveNext())
            {
                Project project  = enumerator.Current as Project;
                string  fullName = null;
                try {
                    //SrcMLFileLogger.DefaultLogger.Info("FileName: [" + project.FileName + "]");
                    fullName = project.FileName;
                } catch (Exception e) {
                    // Ignore unloaded project. It would cause a Not Implemented Exception for an
                    // unloaded project.
                    //SrcMLFileLogger.DefaultLogger.Error(SrcMLExceptionFormatter.CreateMessage(e, "Exception in SolutionMonitor.NotifyProjectAddRemove() - "));
                    continue;
                }
                if (fullName != null && (fullName.Equals(projectName) || fullName.ToLower().Contains(projectName.ToLower())))
                {
                    SrcMLFileLogger.DefaultLogger.Info("Project: [" + projectName + "]");
                    ProcessProject(project, null, fileList);
                    break;
                }
            }

            // Generate or delete srcML files for the source files in this project
            try {
                foreach (var filePath in fileList)
                {
                    if (FileEventType.FileAdded.Equals(type))
                    {
                        //SrcMLFileLogger.DefaultLogger.Info(">>> AddFile(" + filePath + ")");
                        AddFile(filePath);
                    }
                    else if (FileEventType.FileDeleted.Equals(type))
                    {
                        //SrcMLFileLogger.DefaultLogger.Info(">>> DeleteFile(" + filePath + ")");
                        DeleteFile(filePath);
                    }
                }
            } catch (Exception e) {
                SrcMLFileLogger.DefaultLogger.Error(SrcMLExceptionFormatter.CreateMessage(e, "Exception when batch adding or deleting srcML files for a specified project."));
            }
        }
示例#3
0
 private void RespondToMonitoringStopped(object sender, EventArgs e)
 {
     try {
         if (null != CurrentWorkingSet)
         {
             IsMonitoring = false;
             CurrentWorkingSet.StopMonitoring();
             _srcMonitor.StopMonitoring();
             CurrentWorkingSet.Dispose();
             _srcMonitor.Dispose();
             CurrentWorkingSet  = null;
             CurrentDataArchive = null;
             _srcMonitor        = null;
         }
     } catch (Exception ex) {
         SrcMLFileLogger.DefaultLogger.Error(SrcMLExceptionFormatter.CreateMessage(ex, "Exception in SrcMLDataService.RespondToMonitoringStopped"));
     }
 }
 /// <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();
             CurrentProject.StopMonitoring();
             CurrentMonitor.FileChanged      -= RespondToFileChangedEvent;
             CurrentMonitor.DirectoryAdded   -= RespondToDirectoryAddedEvent;
             CurrentMonitor.DirectoryRemoved -= RespondToDirectoryRemovedEvent;
             CurrentProject.Dispose();
             CurrentProject = null;
             CurrentMonitor = null;
         }
     } catch (Exception e) {
         SrcMLFileLogger.DefaultLogger.Error(SrcMLExceptionFormatter.CreateMessage(e, "Exception in SrcMLGlobalService.StopMonitoring()"));
     }
 }