Example #1
0
        private void LoadArchive(BackgroundWorker worker, string pathToMappingFile, out ISrcMLArchive archive, out IDataRepository data, out string projectName)
        {
            string pathToArchive        = FilePath.GetDirectoryName(pathToMappingFile);
            string archiveDirectoryName = FilePath.GetFileName(pathToArchive);
            string baseDirectory        = FilePath.GetFullPath(FilePath.GetDirectoryName(pathToArchive));

            projectName = FilePath.GetFileName(baseDirectory);
            worker.ReportProgress(0, String.Format("Loading {0}", projectName));
            archive = new SrcMLArchive(baseDirectory, archiveDirectoryName);
            int numberOfFiles = archive.FileUnits.Count();

            worker.ReportProgress(0, String.Format("Loading {0} ({1} files)", projectName, numberOfFiles));

            data = new DataRepository(archive);
            int i = 0;

            foreach (var unit in archive.FileUnits)
            {
                try {
                    data.AddFile(unit);
                } catch (Exception) {
                }

                if (++i % 25 == 0)
                {
                    int percentComplete = (int)(100 * (double)i / (double)numberOfFiles);
                    worker.ReportProgress(percentComplete, String.Format("Loading {0} ({1} / {2} files)", projectName, i, numberOfFiles));
                }
            }
            worker.ReportProgress(100, String.Format("Loaded {0} ({1} files)", baseDirectory, i));
        }
Example #2
0
        /// <summary>
        /// Counts the number of occurrences of words within the identifiers in the given srcml files.
        /// </summary>
        /// <param name="archive">An archive containing the srcml files to analyze.</param>
        /// <returns>A dictionary mapping words to the number of occurrences within identifiers.</returns>
        public static Dictionary <string, int> CountProgramWords(ISrcMLArchive archive)
        {
            if (archive == null)
            {
                throw new ArgumentNullException("archive");
            }

            var splitter     = new ConservativeIdSplitter();
            var observations = new Dictionary <string, int>();

            foreach (var fileUnit in archive.FileUnits)
            {
                //query for all the identifiers
                var identifiers = from id in fileUnit.Descendants(SRC.Name)
                                  where !id.Elements().Any()
                                  select id.Value;

                foreach (var id in identifiers)
                {
                    string[] words = splitter.Split(id);
                    foreach (string word in words)
                    {
                        int    obs;
                        string lowWord = word.ToLower();
                        observations.TryGetValue(lowWord, out obs); //gets the number of observations for the word. If it is new, obs is set to 0
                        observations[lowWord] = obs + 1;
                    }
                }
            }

            return(observations);
        }
Example #3
0
 /// <summary>
 /// Creates a new source monitor
 /// </summary>
 /// <param name="solution">The solution to monitor</param>
 /// <param name="foldersToMonitor">A list of folders to monitor</param>
 /// <param name="scanInterval">The interval at which to scan the folders (in
 /// seconds) </param>
 /// <param name="baseDirectory">The base directory for this monitor</param>
 /// <param name="defaultArchive">The default archive to route files to</param>
 /// <param name="otherArchives">Other archives to route files to</param>
 public SourceMonitor(Solution solution, double scanInterval, TaskScheduler scheduler, string baseDirectory, IArchive defaultArchive, ISrcMLArchive sourceArchive, params IArchive[] otherArchives)
     : base(DirectoryScanningMonitor.MONITOR_LIST_FILENAME, scanInterval, scheduler, baseDirectory, defaultArchive, otherArchives)
 {
     RegisterArchive(sourceArchive, false);
     this.sourceArchive     = sourceArchive;
     this.MonitoredSolution = solution;
 }
Example #4
0
        private void SolutionAboutToClose()
        {
            try
            {
                // JZ: SrcMLService Integration
                //srcMLService.StopMonitoring();
                // TODO: DocumentIndexer.CommitChanges(); DocumentIndexer.Dispose(false);
                // End of code changes



                if (_srcMLArchive != null)
                {
                    _srcMLArchive.Dispose();
                    _srcMLArchive = null;
                    ServiceLocator.Resolve <IndexFilterManager>().Dispose();
                    ServiceLocator.Resolve <DocumentIndexer>().Dispose();
                }
                // XiGe: dispose the dictionary.
                ServiceLocator.Resolve <DictionaryBasedSplitter>().Dispose();
                ServiceLocator.Resolve <SearchHistory>().Dispose();
                var control = ServiceLocator.Resolve <SearchViewControl>();
                control.Dispatcher.Invoke((Action)(() => UpdateDirectory(SearchViewControl.DefaultOpenSolutionMessage, control)));
            }
            catch (Exception e)
            {
                LogEvents.UISolutionClosingError(this, e);
            }
        }
Example #5
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 #6
0
 /// <summary>
 /// Create a data archive for the given srcML archive and binary file. It will load data
 /// from the binary archive and then subscribe to the srcML archive.
 /// </summary>
 /// <param name="archive">The srcML archive to monitor for changes. If null, no archive
 /// monitoring will be done.</param>
 /// <param name="fileName">The file to read data from. If null, no previously saved data
 /// will be loaded.</param>
 public DataRepository(ISrcMLArchive archive, string fileName, TaskScheduler scheduler)
 {
     SetupParsers();
     scopeLock         = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
     this.ReadyState   = new ReadyNotifier(this);
     this.Archive      = archive;
     this.FileName     = fileName;
     this._taskFactory = new TaskFactory(scheduler);
 }
Example #7
0
        public static XElement GetElement(ISrcMLArchive archive, SrcMLLocation location)
        {
            string fileName = location.SourceFileName;
            string query    = location.XPath;

            var unit = archive.GetXElementForSourceFile(fileName);

            var startingLength = fileName.Length + 23;
            var path           = query.Substring(startingLength);
            var element        = unit.XPathSelectElement(path, SrcMLNamespaces.Manager);

            return(element);
        }
Example #8
0
        public MethodDefinition(ISrcMLArchive archive, MethodData data, MethodCall fromCall)
        {
            this.Archive    = archive;
            this.SourceCall = fromCall;
            this.Data       = data;

            this.isValid = false;

            this.Location = data.PrimaryLocation;
            this.FullName = Data.GetFullName();
            this.Id       = DataHelpers.GetLocation(Location);
            this.Path     = Location.SourceFileName;

            this.Signature = GetMethodSignature();
        }
Example #9
0
        /// <summary>
        /// Gets the XElement referred to by <see cref="XPath"/>.
        /// </summary>
        /// <param name="archive">The archive for this location</param>
        /// <returns>The XElement referred to by <see cref="XPath"/></returns>
        public XElement GetXElement(ISrcMLArchive archive)
        {
            if (null == archive)
            {
                throw new ArgumentNullException("archive");
            }

            var unit = archive.GetXElementForSourceFile(this.SourceFileName);

            if (unit != null)
            {
                return(unit.XPathSelectElement(this.XPath, SrcMLNamespaces.Manager));
            }

            return(null);
        }
Example #10
0
        public MethodCallSample(ISrcMLArchive archive, IDataRepository data, int sampleSize)
        {
            this.Archive      = archive;
            this.Data         = data;
            this.Date         = DateTime.Now;
            this._projectName = string.Empty;
            this.SampleSize   = sampleSize;

            FirstMatchIsValid = new Statistic("FirstMatchIsValid", SampleSize);
            HasMatches        = new Statistic("HasMatches", SampleSize);
            HasNoMatches      = new Statistic("HasNoMatches", SampleSize);
            IsExternal        = new Statistic("IsExternal", SampleSize);

            FirstMatchIsValid.PropertyChanged += StatisticChanged;
            HasMatches.PropertyChanged        += StatisticChanged;
            HasNoMatches.PropertyChanged      += StatisticChanged;
            IsExternal.PropertyChanged        += StatisticChanged;
        }
Example #11
0
        public MethodCall(ISrcMLArchive archive, CallData data)
        {
            this.Archive = archive;
            this.Data    = data;

            this.firstMatchIsValid = false;
            this.hasMatches        = false;
            this.hasNoMatches      = false;
            this.isExternal        = false;

            this.Location = data.Location;
            this.FullName = data.ParentScope.GetParentScopesAndSelf <INamedScope>().First().GetFullName();
            this.Id       = DataHelpers.GetLocation(data.Location);
            this.Path     = this.Location.SourceFileName;

            this.numberOfValidMatches = 0;
            this.SourceCode           = GetSourceCode();
            PossibleMatches           = new ObservableCollection <MethodDefinition>(GetMatches());
            StartMonitoringDefinitions();
        }
Example #12
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()"));
            }
        }
Example #13
0
        /// <summary>
        /// Counts the number of occurrences of words within the identifiers in the given srcml files.
        /// </summary>
        /// <param name="archive">An archive containing the srcml files to analyze.</param>
        /// <returns>A dictionary mapping words to the number of occurrences within identifiers.</returns>
        public static Dictionary<string,int> CountProgramWords(ISrcMLArchive archive)
        {
            if(archive == null) {
                throw new ArgumentNullException("archive");
            }
            
            var splitter = new ConservativeIdSplitter();
            var observations = new Dictionary<string, int>();
            foreach (var fileUnit in archive.FileUnits)
            {
                //query for all the identifiers
                var identifiers = from id in fileUnit.Descendants(SRC.Name)
                                  where !id.Elements().Any()
                                  select id.Value;

                foreach (var id in identifiers)
                {
                    string[] words = splitter.Split(id);
                    foreach (string word in words)
                    {
                        int obs;
                        string lowWord = word.ToLower();
                        observations.TryGetValue(lowWord, out obs); //gets the number of observations for the word. If it is new, obs is set to 0
                        observations[lowWord] = obs + 1;
                    }
                }
            }

            return observations;
        }
Example #14
0
 public SourceFolder(string path, ISrcMLArchive archive)
 {
     this.Info = new DirectoryInfo(path);
     Archive   = archive;
 }
Example #15
0
        /// <summary>
        /// SrcML service starts to monitor the opened solution.
        /// </summary>
        /// <param name="srcMLArchiveDirectory"></param>
        /// <param name="useExistingSrcML"></param>
        public void StartMonitoring(bool useExistingSrcML, string srcMLBinaryDirectory) {
            // Get the path of the folder that storing the srcML archives
            string srcMLArchiveDirectory = GetSrcMLArchiveFolder(SolutionMonitorFactory.GetOpenSolution());
            SrcMLFileLogger.DefaultLogger.Info("SrcMLGlobalService.StartMonitoring( " + srcMLArchiveDirectory + " )");
            try {
                // Create a new instance of SrcML.NET's LastModifiedArchive
                LastModifiedArchive lastModifiedArchive = new LastModifiedArchive(srcMLArchiveDirectory);

                // Create a new instance of SrcML.NET's SrcMLArchive
                SrcMLArchive sourceArchive = new SrcMLArchive(srcMLArchiveDirectory, useExistingSrcML, new SrcMLGenerator(srcMLBinaryDirectory));
                CurrentSrcMLArchive = sourceArchive;

                // Create a new instance of SrcML.NET's solution monitor
                CurrentMonitor = SolutionMonitorFactory.CreateMonitor(srcMLArchiveDirectory, lastModifiedArchive, sourceArchive);

                // Subscribe events from Solution Monitor
                CurrentMonitor.FileChanged += RespondToFileChangedEvent;
                CurrentMonitor.IsReadyChanged += RespondToIsReadyChangedEvent;

                CurrentMonitor.MonitoringStopped += RespondToMonitoringStoppedEvent;

                // Initialize the progress bar.
                if(statusBar != null) {
                    statusBar.Progress(ref cookie, 1, "", 0, 0);
                }

                // Start monitoring
                duringStartup = true;
                CurrentMonitor.StartMonitoring();
            } catch(Exception e) {
                SrcMLFileLogger.DefaultLogger.Error(SrcMLExceptionFormatter.CreateMessage(e, "Exception in SrcMLGlobalService.StartMonitoring()"));
            }
        }
Example #16
0
 public SrcMLCSharpParser(ISrcMLArchive archive)
 {
     this.Archive = archive;
 }
Example #17
0
 /// <summary>
 /// SrcML service stops monitoring the opened solution.
 /// </summary>
 public void StopMonitoring() {
     SrcMLFileLogger.DefaultLogger.Info("SrcMLGlobalService.StopMonitoring()");
     try {
         if(CurrentMonitor != null && CurrentSrcMLArchive != null) {
             CurrentMonitor.StopMonitoring();
             CurrentSrcMLArchive = null;
             CurrentMonitor = null;
         }
     } catch(Exception e) {
         SrcMLFileLogger.DefaultLogger.Error(SrcMLExceptionFormatter.CreateMessage(e, "Exception in SrcMLGlobalService.StopMonitoring()"));
     }
 }
Example #18
0
 /// <summary>
 /// Creates a new source monitor
 /// </summary>
 /// <param name="solution">The solution to monitor</param>
 /// <param name="foldersToMonitor">A list of folders to monitor</param>
 /// <param name="baseDirectory">The base directory for this monitor</param>
 /// <param name="defaultArchive">The default archive to route files to</param>
 /// <param name="otherArchives">Other archives to route files to</param>
 public SourceMonitor(Solution solution, string baseDirectory, IArchive defaultArchive, ISrcMLArchive sourceArchive, params IArchive[] otherArchives)
     : this(solution, DEFAULT_SCAN_INTERVAL, TaskScheduler.Default, baseDirectory, defaultArchive, sourceArchive, otherArchives)
 {
 }
Example #19
0
 public DataRepository(ISrcMLArchive archive, TaskScheduler scheduler)
     : this(archive, null, scheduler)
 {
 }
Example #20
0
 public DataRepository(ISrcMLArchive archive, string fileName)
     : this(archive, fileName, TaskScheduler.Default)
 {
 }
Example #21
0
 /// <summary>
 /// Create a data archive for the given srcML archive. It will subscribe to the
 /// <see cref="AbstractArchive.FileChanged"/> event.
 /// </summary>
 /// <param name="archive">The archive to monitor for changes.</param>
 public DataRepository(ISrcMLArchive archive)
     : this(archive, null, TaskScheduler.Default)
 {
 }