Beispiel #1
0
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (watcher != null)
         {
             watcher.Dispose();
             watcher = null;
         }
     }
 }
Beispiel #2
0
        /// <summary>
        /// Sets up filesystem watches to watch directories for each solution for changes.
        /// </summary>
        private void SetupWatchers()
        {
            if (watcher != null)
            {
                watcher.Dispose();
            }

            watcher              = new MultiFileSystemWatcher();
            watcher.FileChanged += TestContainerUpdated;

            // Subscribe to the solution directory, which should pick up most changes
            string solutionDirectory, solutionFile, userOptionsFile;

            if (solutionService.GetSolutionInfo(out solutionDirectory, out solutionFile, out userOptionsFile) == VSConstants.S_OK)
            {
                if (!string.IsNullOrEmpty(solutionDirectory))
                {
                    // Ensure the solution dir ends with \ so we can compare when looking for subfolders
                    if (!solutionDirectory.EndsWith("\\"))
                    {
                        solutionDirectory = solutionDirectory + "\\";
                    }

                    foreach (var filePattern in this.WatchedFilePatterns)
                    {
                        watcher.AddWatcher(solutionDirectory, filePattern);
                    }

                    // Get all directories that had test containers that are not already children of the solution dir (it's already being watched)
                    var dirs = cachedTestContainers
                               .Select(tc => Path.GetDirectoryName(tc.Source) + "\\")
                               .Distinct(StringComparer.OrdinalIgnoreCase)
                               .Where(tc => !tc.StartsWith(solutionDirectory, StringComparison.OrdinalIgnoreCase));

                    foreach (var dir in dirs)
                    {
                        foreach (var filePattern in this.WatchedFilePatterns)
                        {
                            watcher.AddWatcher(dir, filePattern);
                        }
                    }
                }
            }

            // Also subscribe to the projects own changes to deal with new items being added outside of the solution directory
            uint pdwCookie;

            foreach (var p in solutionService.GetProjects())
            {
                p.AdviseHierarchyEvents(this, out pdwCookie);
            }
        }