G2Development.FileWatcher 2.0.1.3

A File System Watcher similar to FileSystemWatcher of Microsoft that will run on Docker Containers when files are changed by the host.

Install-Package G2Development.FileWatcher -Version 2.0.1.3
dotnet add package G2Development.FileWatcher --version 2.0.1.3
<PackageReference Include="G2Development.FileWatcher" Version="2.0.1.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add G2Development.FileWatcher --version 2.0.1.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

File Watcher

A File Watching module similar to FileSystemWatcher from Microsoft. The need arose to find a Watching module to monitor file changes inside of a Docker container where the files might be changed by the Host computer. It seems as if these changes is not monitored by FileSystemWatcher.

An attempt was made to keep the naming conventions very close to that of the FileSystemWatcher where possible. The usage will also be similar. Have a look at Diferences and Official Page

Examples

The following example creates a FileWatcher to watch the directory specified at run time. The component is set to watch for changes of any Notification type in the directory. This is similare to FileSystemWatcher.

public class Watcher
{
    public static void Main()
    {
        Run();
    }

    private static void Run()
    {
        string path = "../../../test";

        // Create a new FileWatcher and set its properties.
        using FileWatcher watcher = new FileWatcher
        {
            Path = path,

            // Watch for changes in LastAccess and LastWrite times, and
            // the renaming of files or directories.
            NotifyFilter = NotifyFilters.LastAccess
                                | NotifyFilters.LastWrite
                                | NotifyFilters.FileName
                                | NotifyFilters.DirectoryName,

            IncludeSubdirectories = true,

            // Only watch text files.
            Filter = "*.txt"
        };

        // Add event handlers.
        watcher.Changed += OnChanged;
        watcher.Created += OnChanged;
        watcher.Deleted += OnChanged;
        watcher.Renamed += OnRenamed;

        // Begin watching.
        watcher.EnableRaisingEvents = true;

        // Wait for the user to quit the program.
        Console.WriteLine("Press 'q' to quit the sample.");
        while (Console.Read() != 'q') ;
    }

    // Define the event handlers.
    private static void OnChanged(object source, FileSystemEventArgs e) =>
        // Specify what is done when a file is changed, created, or deleted.
        Console.WriteLine($"File: {e.FullPath} {e.ChangeType}");

    private static void OnRenamed(object source, RenamedEventArgs e) =>
        // Specify what is done when a file is renamed.
        Console.WriteLine($"File: {e.OldFullPath} renamed to {e.FullPath}");
}

Note the above example has been taken from Microsoft's site to illustrate similarities.

Refer to Project Page for more information.

Versioning

2.0.1

  • Add Error event.
  • Improved Error handling.
2.0.1.2 & 2.0.1.3
  • Fixing CancellationToken disposal (Re-usability of watcher)
  • Fixing Interfaces for Error handling.
  • Introduce lock for thread safety starting and ending watcher.

2.0.0

  • Brought more in line with FileSystemWatcher
  • Added a Wrapper Class.
  • Some breaking Changes between version 1 and 2 to bring it in line with FileSystemWatcher and Wrapper Usage.

1.0.0

  • Initial Release.

File Watcher

A File Watching module similar to FileSystemWatcher from Microsoft. The need arose to find a Watching module to monitor file changes inside of a Docker container where the files might be changed by the Host computer. It seems as if these changes is not monitored by FileSystemWatcher.

An attempt was made to keep the naming conventions very close to that of the FileSystemWatcher where possible. The usage will also be similar. Have a look at Diferences and Official Page

Examples

The following example creates a FileWatcher to watch the directory specified at run time. The component is set to watch for changes of any Notification type in the directory. This is similare to FileSystemWatcher.

public class Watcher
{
    public static void Main()
    {
        Run();
    }

    private static void Run()
    {
        string path = "../../../test";

        // Create a new FileWatcher and set its properties.
        using FileWatcher watcher = new FileWatcher
        {
            Path = path,

            // Watch for changes in LastAccess and LastWrite times, and
            // the renaming of files or directories.
            NotifyFilter = NotifyFilters.LastAccess
                                | NotifyFilters.LastWrite
                                | NotifyFilters.FileName
                                | NotifyFilters.DirectoryName,

            IncludeSubdirectories = true,

            // Only watch text files.
            Filter = "*.txt"
        };

        // Add event handlers.
        watcher.Changed += OnChanged;
        watcher.Created += OnChanged;
        watcher.Deleted += OnChanged;
        watcher.Renamed += OnRenamed;

        // Begin watching.
        watcher.EnableRaisingEvents = true;

        // Wait for the user to quit the program.
        Console.WriteLine("Press 'q' to quit the sample.");
        while (Console.Read() != 'q') ;
    }

    // Define the event handlers.
    private static void OnChanged(object source, FileSystemEventArgs e) =>
        // Specify what is done when a file is changed, created, or deleted.
        Console.WriteLine($"File: {e.FullPath} {e.ChangeType}");

    private static void OnRenamed(object source, RenamedEventArgs e) =>
        // Specify what is done when a file is renamed.
        Console.WriteLine($"File: {e.OldFullPath} renamed to {e.FullPath}");
}

Note the above example has been taken from Microsoft's site to illustrate similarities.

Refer to Project Page for more information.

Versioning

2.0.1

  • Add Error event.
  • Improved Error handling.
2.0.1.2 & 2.0.1.3
  • Fixing CancellationToken disposal (Re-usability of watcher)
  • Fixing Interfaces for Error handling.
  • Introduce lock for thread safety starting and ending watcher.

2.0.0

  • Brought more in line with FileSystemWatcher
  • Added a Wrapper Class.
  • Some breaking Changes between version 1 and 2 to bring it in line with FileSystemWatcher and Wrapper Usage.

1.0.0

  • Initial Release.

Release Notes

FileWatcher brought more in line with FileSystemWatcher and added an additional FileWatcherWrapper class.

  • .NETCoreApp 3.1

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
2.0.1.3 107 9/29/2020
2.0.1.2 124 9/29/2020
2.0.1.1 124 9/29/2020
2.0.1 78 9/29/2020
2.0.0 53 9/28/2020
1.0.1 128 9/25/2020
1.0.0 145 9/25/2020