public IDuplicationHandler Create(FileSystemChange modification)
        {
            if (IsFileChange(modification)) return FileHandler(modification);
            if (IsDirectoryChange(modification)) return DirectoryHandler(modification);

            throw new NotSupportedException();
        }
 public static FileSystemChange ShouldEqual(this FileSystemChange actual, FileSystemChange expected)
 {
     actual.Change.ShouldEqual(expected.Change);
     actual.Source.ShouldEqual(expected.Source);
     actual.FileOrDirectoryPath.ShouldEqual(expected.FileOrDirectoryPath);
     return actual;
 }
        /// <summary>
        /// Should the given change be filtered out given the configured .gitignore rules?
        /// </summary>
        /// <returns>true to exclude/ignore the change, otherwise false.</returns>
        public bool Filter(FileSystemChange change)
        {
            if (_included.Count == 0 && _excluded.Count == 0) return false;

            if (ShouldBeIncluded(change)) return false;

            return ShouldBeExcluded(change);
        }
Example #4
0
        private void FileSystemChange(FileSystemChange fileSystemChange)
        {
            var visitor = new Visitor(this);

            foreach (var fileSystemChangeDelta in fileSystemChange.Deltas)
            {
                fileSystemChangeDelta.Accept(visitor);
            }
        }
        public bool IsMatch(FileSystemChange change)
        {
            if (change.Source != FileSystemSource.Directory) return false;

            _matcher.Reset();
            _matcher.Append(change.FileOrDirectoryPath);

            return _matcher.IsMatch();
        }
        private IDuplicationHandler DirectoryHandler(FileSystemChange modification)
        {
            switch (modification.Change)
            {
                case WatcherChangeTypes.Created:
                    return _directoryCreatedHandler;

                case WatcherChangeTypes.Deleted:
                    return _directoryDeletedHandler;
            }

            throw new InvalidOperationException();
        }
Example #7
0
        private static string ExtractFileOrDirectoryNameOnly(FileSystemChange change)
        {
            switch (change.Source)
            {
                case FileSystemSource.Directory:
                    return GetDirectoryName(change.FileOrDirectoryPath);

                case FileSystemSource.File:
                    return Path.GetFileName(change.FileOrDirectoryPath);

                default:
                    throw new InvalidOperationException();
            }
        }
Example #8
0
        public bool IsMatch(FileSystemChange change)
        {
            var path = change.FileOrDirectoryPath;
            if (IsMatch(path)) return true;

            // Go up the directory tree looking for any matches
            while (path.IndexOf(Path.DirectorySeparatorChar) > 0)
            {
                path = path.Substring(0, path.LastIndexOf(Path.DirectorySeparatorChar));

                if (IsMatch(path)) return true;
            }

            return false;
        }
Example #9
0
        void HandleOnChangeEvent(object sender, FileSystemChange fileSystemChange)
        {
            var relativePath = fileSystemChange.GetRelativePath();

            _logger.Log(LogLevel.DEBUG, $"Worker received {fileSystemChange.FileSystemEntityType} {fileSystemChange.FileSystemChangeType} event for {relativePath}");

            if (fileSystemChange.FileSystemEntityType == FileSystemEntityType.File)
            {
                if (fileSystemChange.FileSystemChangeType == FileSystemChangeType.Deleted)
                {
                    DeleteFile(relativePath);
                }
                else
                {
                    PutFile(relativePath);
                }
            }
            else if (fileSystemChange.FileSystemEntityType == FileSystemEntityType.Directory)
            {
                if (fileSystemChange.FileSystemChangeType == FileSystemChangeType.Deleted)
                {
                    DeleteDirectory(relativePath);
                }
                else if (fileSystemChange.FileSystemChangeType == FileSystemChangeType.Created)
                {
                    CreateDirectory(relativePath);
                }
                else
                {
                    _logger.Log(LogLevel.DEBUG, $"No need to process {fileSystemChange.FileSystemEntityType} {fileSystemChange.FileSystemChangeType} for {relativePath}");
                }
            }
            else
            {
                if (fileSystemChange.FileSystemChangeType == FileSystemChangeType.Deleted)
                {
                    DeleteFile(relativePath);
                    DeleteDirectory(relativePath);
                }
                else
                {
                    _logger.Log(LogLevel.WARN, $"Cannot to process {fileSystemChange.FileSystemEntityType} {fileSystemChange.FileSystemChangeType} for {relativePath}");
                }
            }
        }
Example #10
0
        static FileSystemChange CreateSystemFileChange(FileSystemChangeType fileChangeType, string relativePath, string absolutePath)
        {
            var fileSystemChange = new FileSystemChange
            {
                FileSystemChangeType   = fileChangeType,
                RelativePathComponents = relativePath.Split(Path.DirectorySeparatorChar),
                FileSystemEntityType   = FileSystemEntityType.Unknown
            };

            try
            {
                fileSystemChange.FileSystemEntityType = File.GetAttributes(absolutePath).HasFlag(FileAttributes.Directory)
                    ? FileSystemEntityType.Directory : FileSystemEntityType.File;
            }
            catch (Exception)
            {
                // Not enough info to set the FileSystemEntityType to something known
            }

            return(fileSystemChange);
        }
 private static bool IsFileChange(FileSystemChange modification)
 {
     return modification.Source == FileSystemSource.File;
 }
 private static bool IsDirectoryChange(FileSystemChange modification)
 {
     return modification.Source == FileSystemSource.Directory;
 }
Example #13
0
 private bool ShouldBeIncluded(FileSystemChange change)
 {
     return _included.Any(inclusion => inclusion.IsMatch(change));
 }
Example #14
0
 void RaiseRenamed(FileSystemPath oldPath, FileSystemPath newPath)
 {
     Changed?.Invoke(this, FileSystemChange.FromRenamed(oldPath, newPath));
 }
Example #15
0
 void RaiseDeleted(FileSystemPath path)
 {
     Changed?.Invoke(this, FileSystemChange.FromDeleted(path));
 }
Example #16
0
 void RaiseCreated(FileSystemPath path)
 {
     Changed?.Invoke(this, FileSystemChange.FromCreated(path));
 }