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); }
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(); }
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(); } }
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; }
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}"); } } }
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; }
private bool ShouldBeIncluded(FileSystemChange change) { return _included.Any(inclusion => inclusion.IsMatch(change)); }
void RaiseRenamed(FileSystemPath oldPath, FileSystemPath newPath) { Changed?.Invoke(this, FileSystemChange.FromRenamed(oldPath, newPath)); }
void RaiseDeleted(FileSystemPath path) { Changed?.Invoke(this, FileSystemChange.FromDeleted(path)); }
void RaiseCreated(FileSystemPath path) { Changed?.Invoke(this, FileSystemChange.FromCreated(path)); }