public void InitializeFileTracking(FileChangeWatcher fileChangeWatcher)
            {
                lock (_gate)
                {
                    if (_fileChangeContext == null)
                    {
                        ImmutableArray <string> includes;

                        try
                        {
                            includes = RuleSet.GetEffectiveIncludesFromFile(FilePath);
                        }
                        catch (Exception e)
                        {
                            // We couldn't read the rule set for whatever reason. Capture the exception
                            // so we can surface the error later, and subscribe to file change notifications
                            // so that we'll automatically reload the file if the user can fix the issue.
                            _optionsRead = true;
                            _specificDiagnosticOptions = ImmutableDictionary <string, ReportDiagnostic> .Empty;
                            _exception = e;

                            includes = ImmutableArray.Create(FilePath);
                        }

                        _fileChangeContext              = fileChangeWatcher.CreateContext();
                        _fileChangeContext.FileChanged += IncludeUpdated;

                        foreach (var include in includes)
                        {
                            _fileChangeContext.EnqueueWatchingFile(include);
                        }
                    }
                }
            }
예제 #2
0
        public FileWatchedPortableExecutableReferenceFactory(
            Lazy <VisualStudioWorkspace> visualStudioWorkspace,
            FileChangeWatcherProvider fileChangeWatcherProvider)
        {
            _visualStudioWorkspace = visualStudioWorkspace;

            // TODO: set this to watch the NuGet directory or the reference assemblies directory; since those change rarely and most references
            // will come from them, we can avoid creating a bunch of explicit file watchers.
            _fileReferenceChangeContext              = fileChangeWatcherProvider.Watcher.CreateContext();
            _fileReferenceChangeContext.FileChanged += FileReferenceChangeContext_FileChanged;
        }
        public FileWatchedPortableExecutableReferenceFactory(
            Lazy <VisualStudioWorkspace> visualStudioWorkspace,
            FileChangeWatcherProvider fileChangeWatcherProvider)
        {
            _visualStudioWorkspace = visualStudioWorkspace;

            // We will do a single directory watch on the Reference Assemblies folder to avoid having to create separate file
            // watches on individual .dlls that effectively never change.
            var referenceAssembliesPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), "Reference Assemblies", "Microsoft", "Framework");
            var referenceAssemblies     = new FileChangeWatcher.WatchedDirectory(referenceAssembliesPath, ".dll");

            // TODO: set this to watch the NuGet directory as well; there's some concern that watching the entire directory
            // might make restores take longer because we'll be watching changes that may not impact your project.

            _fileReferenceChangeContext              = fileChangeWatcherProvider.Watcher.CreateContext(referenceAssemblies);
            _fileReferenceChangeContext.FileChanged += FileReferenceChangeContext_FileChanged;
        }