public FileSystemSnapshotManager( IFileSystemNameFactory fileSystemNameFactory, IFileSystem fileSystem, IFileRegistrationTracker fileRegistrationTracker, IFileSystemSnapshotBuilder fileSystemSnapshotBuilder, IOperationProcessor operationProcessor, IProjectDiscovery projectDiscovery, IDirectoryChangeWatcherFactory directoryChangeWatcherFactory, ITaskQueueFactory taskQueueFactory, ILongRunningFileSystemTaskQueue longRunningFileSystemTaskQueue) { _fileSystemNameFactory = fileSystemNameFactory; _fileSystem = fileSystem; _fileSystemSnapshotBuilder = fileSystemSnapshotBuilder; _operationProcessor = operationProcessor; _projectDiscovery = projectDiscovery; _longRunningFileSystemTaskQueue = longRunningFileSystemTaskQueue; _fileRegistrationTracker = fileRegistrationTracker; _flushPathChangesTaskQueue = taskQueueFactory.CreateQueue("FileSystemSnapshotManager Path Changes Task Queue"); _taskExecutor = taskQueueFactory.CreateQueue("FileSystemSnapshotManager State Change Task Queue"); _fileRegistrationTracker.ProjectListChanged += FileRegistrationTrackerOnProjectListChanged; _currentSnapshot = FileSystemSnapshot.Empty; _directoryChangeWatcher = directoryChangeWatcherFactory.CreateWatcher(TimeSpan.FromSeconds(60)); _directoryChangeWatcher.PathsChanged += DirectoryChangeWatcherOnPathsChanged; _directoryChangeWatcher.Error += DirectoryChangeWatcherOnError; _directoryChangeWatcher.Paused += DirectoryChangeWatcherOnPaused; _directoryChangeWatcher.Resumed += DirectoryChangeWatcherOnResumed; }
public FileSystemSnapshotManager( IFileSystemNameFactory fileSystemNameFactory, IFileSystem fileSystem, IFileRegistrationTracker fileRegistrationTracker, IFileSystemSnapshotBuilder fileSystemSnapshotBuilder, IOperationProcessor operationProcessor, IProjectDiscovery projectDiscovery, IDirectoryChangeWatcherFactory directoryChangeWatcherFactory, ITaskQueueFactory taskQueueFactory, ILongRunningFileSystemTaskQueue longRunningFileSystemTaskQueue) { _fileSystemNameFactory = fileSystemNameFactory; _fileSystem = fileSystem; _fileSystemSnapshotBuilder = fileSystemSnapshotBuilder; _operationProcessor = operationProcessor; _projectDiscovery = projectDiscovery; _longRunningFileSystemTaskQueue = longRunningFileSystemTaskQueue; _fileRegistrationTracker = fileRegistrationTracker; _flushPathChangesTaskQueue = taskQueueFactory.CreateQueue("FileSystemSnapshotManager Path Changes Task Queue"); _fileRegistrationTracker.ProjectListChanged += FileRegistrationTrackerOnProjectListChanged; _fileRegistrationTracker.ProjectListRefreshed += FileRegistrationTrackerOnProjectListRefreshed; _fileSystemSnapshot = FileSystemSnapshot.Empty; _directoryChangeWatcher = directoryChangeWatcherFactory.CreateWatcher(); _directoryChangeWatcher.PathsChanged += DirectoryChangeWatcherOnPathsChanged; _directoryChangeWatcher.Error += DirectoryChangeWatcherOnError; }
private FileSystemSnapshot BuildNewFileSystemSnapshot(IList <IProject> projects, FileSystemSnapshot oldSnapshot, FullPathChanges pathChanges, CancellationToken cancellationToken) { using (new TimeElapsedLogger("Computing snapshot delta from list of file changes")) { // file name factory var fileNameFactory = _fileSystemNameFactory; if (ReuseFileNameInstances) { if (oldSnapshot.ProjectRoots.Count > 0) { fileNameFactory = new FileSystemTreeSnapshotNameFactory(oldSnapshot, fileNameFactory); } } // Compute new snapshot var newSnapshot = _fileSystemSnapshotBuilder.Compute( fileNameFactory, oldSnapshot, pathChanges, projects, Interlocked.Increment(ref _version), cancellationToken); // Monitor all project roots for file changes. var newRoots = newSnapshot.ProjectRoots .Select(entry => entry.Directory.DirectoryName.FullPath); _directoryChangeWatcher.WatchDirectories(newRoots); return(newSnapshot); } }
private void RescanFileSystem(IList <IProject> projects, FullPathChanges pathChanges /* may be null */, CancellationToken cancellationToken) { _registeredProjects = projects; _operationProcessor.Execute(new OperationHandlers { OnBeforeExecute = info => OnSnapshotScanStarted(info), OnError = (info, error) => { if (!error.IsCanceled()) { Logger.LogError(error, "File system rescan error"); } OnSnapshotScanFinished(new SnapshotScanResult { OperationInfo = info, Error = error }); }, Execute = info => { // Compute and assign new snapshot var oldSnapshot = _currentSnapshot; var newSnapshot = BuildNewFileSystemSnapshot(projects, oldSnapshot, pathChanges, cancellationToken); // Update of new tree (assert calls are serialized). Invariants.Assert(ReferenceEquals(oldSnapshot, _currentSnapshot)); _currentSnapshot = newSnapshot; if (Logger.IsInfoEnabled) { Logger.LogInfo("FileSystemSnapshotManager: New snapshot contains {0:n0} files in {1:n0} directories", newSnapshot.ProjectRoots.Aggregate(0, (acc, x) => acc + CountFileEntries(x.Directory)), newSnapshot.ProjectRoots.Aggregate(0, (acc, x) => acc + CountDirectoryEntries(x.Directory))); } // Post event OnSnapshotScanFinished(new SnapshotScanResult { OperationInfo = info, PreviousSnapshot = oldSnapshot, FullPathChanges = pathChanges, NewSnapshot = newSnapshot }); } }); }
private FileSystemSnapshot BuildNewFileSystemSnapshot(IList <IProject> projects, FileSystemSnapshot oldSnapshot, FullPathChanges pathChanges, CancellationToken cancellationToken) { using (new TimeElapsedLogger("FileSystemSnapshotManager: Computing snapshot delta from list of file changes", cancellationToken, InfoLogger.Instance)) { // Compute new snapshot var newSnapshot = _fileSystemSnapshotBuilder.Compute( _fileSystemNameFactory, oldSnapshot, pathChanges, projects, Interlocked.Increment(ref _version), cancellationToken); // Monitor all project roots for file changes. var newRoots = newSnapshot.ProjectRoots .Select(entry => entry.Directory.DirectoryName.FullPath); _directoryChangeWatcher.WatchDirectories(newRoots); return(newSnapshot); } }