예제 #1
0
        public void Open_With_ValidPathAndFilter()
        {
            Mock <IFileSystemWatcher> watcher = new Mock <IFileSystemWatcher>();
            FileDirectoryWatcher      w       = new FileDirectoryWatcher(_settings, watcher.Object);

            w.Open(new FilterAndCallbackArgument("*.log"));
        }
예제 #2
0
        public void Open_With_ValidPath()
        {
            Mock <IFileSystemWatcher> watcher = new Mock <IFileSystemWatcher>();
            FileDirectoryWatcher      w       = new FileDirectoryWatcher(_settings, watcher.Object);

            w.Open();
        }
예제 #3
0
        public void Open_Dispose()
        {
            Mock <IFileSystemWatcher> watcher = new Mock <IFileSystemWatcher>();
            FileDirectoryWatcher      w       = new FileDirectoryWatcher(_settings, watcher.Object);

            w.Open();
            w.Dispose();
        }
예제 #4
0
        public void CreateFileDirectoryWatcher()
        {
            Mock <IFileSystemWatcher> watcher = new Mock <IFileSystemWatcher>();
            var settings = new FileDirectoryWatcherSettings();

            _ = new FileDirectoryWatcher(settings);
            _ = new FileDirectoryWatcher(settings, watcher.Object);
        }
예제 #5
0
 public void Start(string fileFilter, Action <ReadOnlyCollection <FileEntry> > fileListChangeCallback)
 {
     DiscardOldWatcher();
     _watcher = new FileDirectoryWatcher(_fileDirectoryWatcherSettings, _watcherInterface);
     _watcher.Open(new FilterAndCallbackArgument(fileFilter, Callback));
     _fileListChangeCallback = fileListChangeCallback;
     _throttleCalls          = new ThrottleCalls(CallAfterChange, _updateRatioInMilliseconds);
 }
예제 #6
0
        public void Second_Open_AfterDispose()
        {
            Mock <IFileSystemWatcher> watcher = new Mock <IFileSystemWatcher>();
            FileDirectoryWatcher      w       = new FileDirectoryWatcher(_settings, watcher.Object);

            w.Open();
            w.Dispose();
            Assert.Throws <System.NullReferenceException>(() => w.Open());
        }
예제 #7
0
 void DiscardOldWatcher()
 {
     lock (_syncListAccess)
     {
         _throttleCalls?.Dispose();
         _watcher?.Dispose();
         _watcher     = null;
         _currentList = new List <FileEntry>();
     }
 }
예제 #8
0
        static void Main(string[] args)
        {
            //var dir = @"/mnt/c/test/deleteme/xwatchertest/";
            var dir = @"/home/dev/log";
            //var dir = @"/tmp/log";

            //string directory = (args.Length > 0 && args[0] != String.Empty) ? args[0] : @"C:\test\deleteme\xwatchertest";
            string directory = (args.Length > 0 && args[0] != String.Empty) ? args[0] : dir;

            Console.WriteLine($"Watching now directory: {directory}");

            Task.Run(() =>
            {
                int n       = 0;
                string ldir = "/tmp/log/";
                for (; ;)
                {
                    Task.Delay(1000).Wait();
                    File.WriteAllText($"{ldir}linkhard.txt", $"hello{++n}");
                    File.WriteAllText($"{ldir}linksoft.txt", $"hello{++n}");
                    Console.Write('.');
                    //File.WriteAllText($"{dir}linkhard.txt", $"hello{++n}");
                }
            });

            FileDirectoryWatcher w = new FileDirectoryWatcher(new FileDirectoryWatcherSettings(directory));

            w.Open(new FilterAndCallbackArgument(String.Empty,
                                                 (object sender, WatcherCallbackArgs args) =>
            {
                Console.WriteLine($"{args.ChangeType} {args.FileName}");
            }
                                                 ));


            //FileSystemWatcher watcher = new FileSystemWatcher(@"C:\test\deleteme\xwatchertest", "*.txt");


            //watcher.Changed += Watcher_Callback;
            //watcher.Created += Watcher_Callback;
            //watcher.Deleted += Watcher_Callback; ;
            //watcher.Renamed += Watcher_Callback;
            //watcher.Error += Watcher_Error; ;
            //watcher.Disposed += Watcher_Disposed;
            //watcher.IncludeSubdirectories = false;
            //watcher.InternalBufferSize = 65536; // Reserve for a larger number of containers running


            //watcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.Size | NotifyFilters.FileName | NotifyFilters.DirectoryName;
            //watcher.EnableRaisingEvents = true; // Must be set always
            Console.ReadLine();
        }