public DirectoryRenamed(string rootDirectory, IFileSystem fileSystem, IMsBuildFileSystemFilter fileSystemFilter, string oldFullPath, string fullPath) {
     _rootDirectory = rootDirectory;
     _fileSystem = fileSystem;
     _fileSystemFilter = fileSystemFilter;
     _oldFullPath = oldFullPath;
     _fullPath = fullPath;
 }
Beispiel #2
0
        public MsBuildFileSystemWatcher(string directory, string filter, int delayMilliseconds, int recoveryDelayMilliseconds, IFileSystem fileSystem, IMsBuildFileSystemFilter fileSystemFilter, IActionLog log, TaskScheduler taskScheduler = null)
        {
            Requires.NotNullOrWhiteSpace(directory, nameof(directory));
            Requires.NotNullOrWhiteSpace(filter, nameof(filter));
            Requires.Range(delayMilliseconds >= 0, nameof(delayMilliseconds));
            Requires.Range(recoveryDelayMilliseconds >= 0, nameof(recoveryDelayMilliseconds));
            Requires.NotNull(fileSystem, nameof(fileSystem));
            Requires.NotNull(fileSystemFilter, nameof(fileSystemFilter));

            _directory                 = directory;
            _filter                    = filter;
            _delayMilliseconds         = delayMilliseconds;
            _recoveryDelayMilliseconds = recoveryDelayMilliseconds;
            _fileSystem                = fileSystem;
            _fileSystemFilter          = fileSystemFilter;
            _taskScheduler             = taskScheduler ?? TaskScheduler.Default;
            _log = log;

            _entries        = new MsBuildFileSystemWatcherEntries();
            _queue          = new ConcurrentQueue <IFileSystemChange>();
            _broadcastBlock = new BroadcastBlock <Changeset>(b => b, new DataflowBlockOptions {
                TaskScheduler = _taskScheduler
            });
            SourceBlock = _broadcastBlock.SafePublicize();
            _fileSystemFilter.Seal();
        }
 public DirectoryCreated(MsBuildFileSystemWatcherEntries entries, string rootDirectory, IFileSystem fileSystem, IMsBuildFileSystemFilter fileSystemFilter, string directoryFullPath) {
     _entries = entries;
     _rootDirectory = rootDirectory;
     _fileSystem = fileSystem;
     _fileSystemFilter = fileSystemFilter;
     _directoryFullPath = directoryFullPath;
 }
Beispiel #4
0
 public DirectoryCreated(MsBuildFileSystemWatcherEntries entries, string rootDirectory, IFileSystem fileSystem, IMsBuildFileSystemFilter fileSystemFilter, string directoryFullPath)
 {
     _entries           = entries;
     _rootDirectory     = rootDirectory;
     _fileSystem        = fileSystem;
     _fileSystemFilter  = fileSystemFilter;
     _directoryFullPath = directoryFullPath;
 }
 public DirectoryRenamed(MsBuildFileSystemWatcherEntries entries, string rootDirectory, IFileSystem fileSystem, IMsBuildFileSystemFilter fileSystemFilter, string oldFullPath, string fullPath) {
     _entries = entries;
     _rootDirectory = rootDirectory;
     _fileSystem = fileSystem;
     _fileSystemFilter = fileSystemFilter;
     _oldFullPath = oldFullPath;
     _fullPath = fullPath;
 }
Beispiel #6
0
 public DirectoryRenamed(MsBuildFileSystemWatcherEntries entries, string rootDirectory, IFileSystem fileSystem, IMsBuildFileSystemFilter fileSystemFilter, string oldFullPath, string fullPath)
 {
     _entries          = entries;
     _rootDirectory    = rootDirectory;
     _fileSystem       = fileSystem;
     _fileSystemFilter = fileSystemFilter;
     _oldFullPath      = oldFullPath;
     _fullPath         = fullPath;
 }
Beispiel #7
0
 private static bool IsFileAllowed(string rootDirectory, string fullPath,
                                   IFileSystem fileSystem, IMsBuildFileSystemFilter filter,
                                   out string relativePath, out string shortRelativePath)
 {
     relativePath      = null;
     shortRelativePath = null;
     if (fullPath.StartsWithIgnoreCase(rootDirectory))
     {
         relativePath = PathHelper.MakeRelative(rootDirectory, fullPath);
         try {
             shortRelativePath = fileSystem.ToShortRelativePath(fullPath, rootDirectory);
             return(!string.IsNullOrEmpty(shortRelativePath) && filter.IsFileAllowed(relativePath, fileSystem.GetFileAttributes(fullPath)));
         } catch (IOException) { } catch (UnauthorizedAccessException) { } // File isn't allowed if it isn't accessible
     }
     return(false);
 }
            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;
            }
Beispiel #9
0
            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 MsBuildFileSystemWatcher(string directory, string filter, int delayMilliseconds, IFileSystem fileSystem, IMsBuildFileSystemFilter fileSystemFilter, TaskScheduler taskScheduler = null, IActionLog log = null) {
            Requires.NotNullOrWhiteSpace(directory, nameof(directory));
            Requires.NotNullOrWhiteSpace(filter, nameof(filter));
            Requires.Range(delayMilliseconds >= 0, nameof(delayMilliseconds));
            Requires.NotNull(fileSystem, nameof(fileSystem));
            Requires.NotNull(fileSystemFilter, nameof(fileSystemFilter));

            _directory = directory;
            _filter = filter;
            _delayMilliseconds = delayMilliseconds;
            _fileSystem = fileSystem;
            _fileSystemFilter = fileSystemFilter;
            _taskScheduler = taskScheduler ?? TaskScheduler.Default;
            _log = log ?? ProjectSystemActionLog.Default;

            _queue = new ConcurrentQueue<IFileSystemChange>();
            _broadcastBlock = new BroadcastBlock<Changeset>(b => b, new DataflowBlockOptions { TaskScheduler = _taskScheduler });
            SourceBlock = _broadcastBlock.SafePublicize();
            _fileSystemFilter.Seal();
        }
 public FileCreated(string rootDirectory, IFileSystem fileSystem, IMsBuildFileSystemFilter fileSystemFilter, string fullPath) {
     _rootDirectory = rootDirectory;
     _fileSystem = fileSystem;
     _fileSystemFilter = fileSystemFilter;
     _fullPath = fullPath;
 }
Beispiel #12
0
        private static bool IsFileAllowed(string rootDirectory, string fullPath, IFileSystem fileSystem, IMsBuildFileSystemFilter filter, out string relativePath)
        {
            if (!fullPath.StartsWithIgnoreCase(rootDirectory))
            {
                relativePath = null;
                return(false);
            }

            relativePath = PathHelper.MakeRelative(rootDirectory, fullPath);
            try {
                return(filter.IsFileAllowed(relativePath, fileSystem.GetFileAttributes(fullPath)));
            } catch (IOException) {
                // File isn't allowed if it isn't accessable
                return(false);
            }
        }
        private static bool IsFileAllowed(string rootDirectory, string fullPath, IFileSystem fileSystem, IMsBuildFileSystemFilter filter, out string relativePath) {
            if (!fullPath.StartsWithIgnoreCase(rootDirectory)) {
                relativePath = null;
                return false;
            }

            relativePath = PathHelper.MakeRelative(rootDirectory, fullPath);
            try {
                return filter.IsFileAllowed(relativePath, fileSystem.GetFileAttributes(fullPath));
            } catch (IOException) {
                // File isn't allowed if it isn't accessable
                return false;
            }
        }
 private static bool IsFileAllowed(string rootDirectory, string fullPath,
     IFileSystem fileSystem, IMsBuildFileSystemFilter filter,
     out string relativePath, out string shortRelativePath) {
     relativePath = null;
     shortRelativePath = null;
     if (fullPath.StartsWithIgnoreCase(rootDirectory)) {
         relativePath = PathHelper.MakeRelative(rootDirectory, fullPath);
          try {
             shortRelativePath = fileSystem.ToShortRelativePath(fullPath, rootDirectory);
             return !string.IsNullOrEmpty(shortRelativePath) && filter.IsFileAllowed(relativePath, fileSystem.GetFileAttributes(fullPath));
         } catch (IOException) { } catch (UnauthorizedAccessException) { } // File isn't allowed if it isn't accessible
     }
     return false;
 }