コード例 #1
0
        public void Start()
        {
            var filter = "*";
            var delay = 0;
            var fileSystem = Substitute.For<IFileSystem>();
            var fileSystemFilter = Substitute.For<IMsBuildFileSystemFilter>();

            MsBuildFileSystemWatcher watcher = new MsBuildFileSystemWatcher(ProjectDirectory, filter, delay, fileSystem, fileSystemFilter, log: NullLog.Instance); 
            fileSystemFilter.Received().Seal();

            var fileSystemWatchers = new List<IFileSystemWatcher>();
            fileSystem.CreateFileSystemWatcher(ProjectDirectory, filter)
                .Returns(ci =>
                {
                    var w = Substitute.For<IFileSystemWatcher>();
                    fileSystemWatchers.Add(w);
                    return w;
                });

            watcher.Start();
            watcher.Dispose();

            foreach (var fileSystemWatcher in fileSystemWatchers)
            {
                fileSystemWatcher.Received().Dispose();
            }
        }
        public static void WatcherChangesetSent(this IActionLog log, MsBuildFileSystemWatcher.Changeset changeset) {
            var sb = new StringBuilder();
            sb.AppendLine("MsBuildFileSystemWatcher changeset sent.")
                .AppendWatcherChangesetPart(changeset.AddedFiles, "Added Files:")
                .AppendWatcherChangesetPart(changeset.RenamedFiles, "Renamed Files:")
                .AppendWatcherChangesetPart(changeset.RemovedFiles, "Removed Files:")
                .AppendWatcherChangesetPart(changeset.AddedDirectories, "Added Directories:")
                .AppendWatcherChangesetPart(changeset.RenamedDirectories, "Renamed Directories:")
                .AppendWatcherChangesetPart(changeset.RemovedDirectories, "Removed Directories:");

            log.WriteAsync(MessageCategory.General, sb.ToString());
        }
コード例 #3
0
ファイル: RProjectLoadHooks.cs プロジェクト: int19h/RTVS-OLD
        public RProjectLoadHooks(UnconfiguredProject unconfiguredProject, IProjectLockService projectLockService, IRInteractiveWorkflowProvider workflowProvider, IInteractiveWindowComponentContainerFactory componentContainerFactory, IRToolsSettings toolsSettings, IFileSystem fileSystem, IThreadHandling threadHandling) {
            _unconfiguredProject = unconfiguredProject;
            _workflowProvider = workflowProvider;
            _componentContainerFactory = componentContainerFactory;

            _toolsSettings = toolsSettings;
            _fileSystem = fileSystem;
            _threadHandling = threadHandling;
            _projectDirectory = unconfiguredProject.GetProjectDirectory();

            unconfiguredProject.ProjectUnloading += ProjectUnloading;
            _fileWatcher = new MsBuildFileSystemWatcher(_projectDirectory, "*", 25, fileSystem, new RMsBuildFileSystemFilter());
            Project = new FileSystemMirroringProject(unconfiguredProject, projectLockService, _fileWatcher);
        }
コード例 #4
0
        public FileSystemMirroringProject(UnconfiguredProject unconfiguredProject, IProjectLockService projectLockService, MsBuildFileSystemWatcher fileSystemWatcher, IActionLog log = null) {
            _unconfiguredProject = unconfiguredProject;
            _projectLockService = projectLockService;
            _fileSystemWatcher = fileSystemWatcher;
            _log = log ?? ProjectSystemActionLog.Default;
            _unloadCancellationToken = _unconfiguredProject.Services.ProjectAsynchronousTasks.UnloadCancellationToken;
            _projectDirectory = _unconfiguredProject.GetProjectDirectory();
            _inMemoryImportFullPath = _unconfiguredProject.GetInMemoryTargetsFileFullPath();
            _fileItems = new Dictionary<string, ProjectItemElement>(StringComparer.OrdinalIgnoreCase);
            _directoryItems = new Dictionary<string, ProjectItemElement>(StringComparer.OrdinalIgnoreCase);

            var changesHandler = new Func<MsBuildFileSystemWatcher.Changeset, Task>(FileSystemChanged);
            _fileSystemWatcher.SourceBlock.LinkTo(new ActionBlock<MsBuildFileSystemWatcher.Changeset>(changesHandler));
        }
            public Delay50MsNoFiltering() {
                _fileSystem = Substitute.For<IFileSystem>();
                var watchers = GetWatchersFromMsBuildFileSystemWatcher(_fileSystem);

                _fileSystemFilter = Substitute.For<IMsBuildFileSystemFilter>();
                _fileSystemFilter.IsFileAllowed(Arg.Any<string>(), Arg.Any<FileAttributes>()).ReturnsForAnyArgs(true);
                _fileSystemFilter.IsDirectoryAllowed(Arg.Any<string>(), Arg.Any<FileAttributes>()).ReturnsForAnyArgs(true);

                _taskScheduler = new ControlledTaskScheduler(SynchronizationContext.Current);

                _fileSystemWatcher = new MsBuildFileSystemWatcher(ProjectDirectory, "*", 50, 50, _fileSystem, _fileSystemFilter, Substitute.For<IActionLog>(), _taskScheduler);
                _taskScheduler.Link(_fileSystemWatcher.SourceBlock, c => { _changeset = c; });

                _fileSystemWatcher.Start();
                _fileWatcher = watchers.FileWatcher;
                _directoryWatcher = watchers.DirectoryWatcher;
                _attributesWatcher = watchers.AttributesWatcher;
            }
            public NoDelayNoFiltering()
            {
                _fileSystem = Substitute.For<IFileSystem>();
                _fileSystem.GetFileAttributes(Arg.Any<string>()).Throws<FileNotFoundException>();
                var watchers = GetWatchersFromMsBuildFileSystemWatcher(_fileSystem);

                var fileSystemFilter = Substitute.For<IMsBuildFileSystemFilter>();
                fileSystemFilter.IsFileAllowed(Arg.Any<string>(), Arg.Any<FileAttributes>()).ReturnsForAnyArgs(true);
                fileSystemFilter.IsDirectoryAllowed(Arg.Any<string>(), Arg.Any<FileAttributes>()).ReturnsForAnyArgs(true);

                _taskScheduler = new ControlledTaskScheduler(SynchronizationContext.Current);

                _fileSystemWatcher = new MsBuildFileSystemWatcher(ProjectDirectory, "*", 0, _fileSystem, fileSystemFilter, _taskScheduler, NullLog.Instance);
                _fileSystemWatcher.Start();

                _fileWatcher = watchers.FileWatcher;
                _directoryWatcher = watchers.DirectoryWatcher;
                _attributesWatcher = watchers.AttributesWatcher;
            }
            public NoDelayNoFiltering() {
                _fileSystem = Substitute.For<IFileSystem>();
                _fileSystem.GetFileAttributes(Arg.Any<string>()).Throws<FileNotFoundException>();
                _fileSystem.ToLongPath(Arg.Any<string>()).Returns(ci => ci[0]);
                _fileSystem.ToShortPath(Arg.Any<string>()).Returns(ci => ci[0]);
                var watchers = GetWatchersFromMsBuildFileSystemWatcher(_fileSystem);

                var fileSystemFilter = Substitute.For<IMsBuildFileSystemFilter>();
                fileSystemFilter.IsFileAllowed(Arg.Any<string>(), Arg.Any<FileAttributes>()).ReturnsForAnyArgs(true);
                fileSystemFilter.IsDirectoryAllowed(Arg.Any<string>(), Arg.Any<FileAttributes>()).ReturnsForAnyArgs(true);

                _taskScheduler = new ControlledTaskScheduler(SynchronizationContext.Current);

                DirectoryInfoStubFactory.Create(_fileSystem, ProjectDirectory);
                _fileSystemWatcher = new MsBuildFileSystemWatcher(ProjectDirectory, "*", 0, 0, _fileSystem, fileSystemFilter, Substitute.For<IActionLog>(), _taskScheduler);
                _fileSystemWatcher.Start();

                _fileWatcher = watchers.FileWatcher;
                _directoryWatcher = watchers.DirectoryWatcher;
                _attributesWatcher = watchers.AttributesWatcher;
            }
コード例 #8
0
ファイル: RProjectLoadHooks.cs プロジェクト: Microsoft/RTVS
        public RProjectLoadHooks(UnconfiguredProject unconfiguredProject
            , [ImportMany("Microsoft.VisualStudio.ProjectSystem.Microsoft.VisualStudio.Shell.Interop.IVsProject")] IEnumerable<Lazy<IVsProject>> cpsIVsProjects
            , IProjectLockService projectLockService
            , IRInteractiveWorkflowProvider workflowProvider
            , IInteractiveWindowComponentContainerFactory componentContainerFactory
            , IRToolsSettings toolsSettings
            , IThreadHandling threadHandling
            , ISurveyNewsService surveyNews
            , [Import(AllowDefault = true)] IProjectItemDependencyProvider dependencyProvider
            , ICoreShell coreShell) {

            _unconfiguredProject = unconfiguredProject;
            _cpsIVsProjects = cpsIVsProjects;
            _projectLockService = projectLockService;
            _workflowProvider = workflowProvider;

            _toolsSettings = toolsSettings;
            _threadHandling = threadHandling;
            _surveyNews = surveyNews;
            _dependencyProvider = dependencyProvider;
            _coreShell = coreShell;

            _projectDirectory = unconfiguredProject.GetProjectDirectory();

            unconfiguredProject.ProjectRenamedOnWriter += ProjectRenamedOnWriter;
            unconfiguredProject.ProjectUnloading += ProjectUnloading;
            _fileWatcher = new MsBuildFileSystemWatcher(_projectDirectory, "*", 25, 1000, _coreShell.Services.FileSystem, new RMsBuildFileSystemFilter(), coreShell.Services.Log);
            _fileWatcher.Error += FileWatcherError;
            Project = new FileSystemMirroringProject(unconfiguredProject, projectLockService, _fileWatcher, _dependencyProvider, coreShell.Services.Log);
        }
コード例 #9
0
        private async Task FileSystemChanged(MsBuildFileSystemWatcher.Changeset changeset) {
            _log.ApplyProjectChangesStarted();

            if (_unloadCancellationToken.IsCancellationRequested) {
                return;
            }

            try {
                using (var access = await _projectLockService.WriteLockAsync(_unloadCancellationToken)) {
                    await access.CheckoutAsync(_inMemoryImportFullPath);

                    _temporaryAddedItemGroup.RemoveAllChildren();

                    await RemoveFiles(changeset.RemovedFiles, access);
                    await RemoveDirectories(changeset.RemovedDirectories, access);

                    await RenameFiles(changeset.RenamedFiles, access);
                    await RenameDirectories(changeset.RenamedDirectories, access);

                    AddDirectories(changeset.AddedDirectories);
                    AddFiles(changeset.AddedFiles);

                    _log.MsBuildAfterChangesApplied(_inMemoryImport);

                    foreach (var configuredProject in _unconfiguredProject.LoadedConfiguredProjects) {
                        try {
                            var project =
                                await access.GetProjectAsync(configuredProject, _unloadCancellationToken);
                            project.ReevaluateIfNecessary();
                        } catch (Exception ex) {
                            Trace.Fail("Unable to mark a configuration as dirty" + ex.Message, ex.StackTrace);
                        }
                    }
                }
            } catch (Exception ex) {
                Trace.Fail("Unable to handle file system change:" + ex.Message, ex.StackTrace);
            }

            _log.ApplyProjectChangesFinished();
        }