コード例 #1
0
            private void AnalyzerFileReference_AssemblyLoad(object sender, InMemoryAssemblyProvider.AssemblyLoadEventArgs e)
            {
                lock (_fileSystemWatcherLock)
                {
                    var directoryPath = Path.GetDirectoryName(e.Path);
                    var fileName = Path.GetFileName(e.Path);

                    FileSystemWatcher watcher;
                    if (!_fileSystemWatchers.TryGetValue(directoryPath, out watcher))
                    {
                        watcher = new FileSystemWatcher(directoryPath);
                        watcher.Changed += Watcher_Changed;
                        watcher.EnableRaisingEvents = true;

                        _fileSystemWatchers.Add(directoryPath, watcher);
                    }

                    HashSet<string> watchedFilesInDirectory;
                    if (!_watchedFiles.TryGetValue(directoryPath, out watchedFilesInDirectory))
                    {
                        watchedFilesInDirectory = new HashSet<string>(StringComparer.OrdinalIgnoreCase);

                        _watchedFiles.Add(directoryPath, watchedFilesInDirectory);
                    }

                    watchedFilesInDirectory.Add(fileName);
                }
            }
コード例 #2
0
        private void AnalyzerFileReference_AssemblyLoad(object sender, InMemoryAssemblyProvider.AssemblyLoadEventArgs e)
        {
            lock (_guard)
            {
                FileChangeTracker tracker;
                if (!_fileChangeTrackers.TryGetValue(e.Path, out tracker))
                {
                    tracker = new FileChangeTracker(_fileChangeService, e.Path);
                    tracker.UpdatedOnDisk += Tracker_UpdatedOnDisk;
                    tracker.StartFileChangeListeningAsync();

                    _fileChangeTrackers.Add(e.Path, tracker);
                }

                DateTime? fileUpdateTime = GetLastUpdateTimeUtc(e.Path);

                if (fileUpdateTime.HasValue)
                {
                    _assemblyUpdatedTimesUtc[e.Path] = fileUpdateTime.Value;
                }
            }
        }