Example #1
0
        public void FileList_StartWatching()
        {
            var             callback = new Action <FileListType>((FileListType list) => { });
            WatcherFileList w        = new WatcherFileList(new FileDirectoryWatcherSettings());

            w.Start(_ => callback(_));
        }
Example #2
0
        static void Main(string[] args)
        {
            var consoleTracer = new ConsoleTraceListener(true);

            Trace.Listeners.Add(consoleTracer);
            consoleTracer.Name = "ManualFileSystemWatcherTrace";



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

            CurrentFileListTest(directory); return;

            WatcherFileList w = new WatcherFileList(new FileDirectoryWatcherSettings {
            }, null, 15000);

            w.Start((list) =>
            {
                foreach (var e in list)
                {
                    Console.WriteLine($"{e.FileName} : {e.LastChanges}");
                }
            });

            Console.WriteLine("Waiting");
            Console.ReadLine();
        }
Example #3
0
        public void FileList_StartWatching_ThenDispose()
        {
            var             callback = new Action <FileListType>(list => { });
            WatcherFileList w        = new WatcherFileList(new FileDirectoryWatcherSettings());

            w.Start(_ => callback(_));
            w.Dispose();
        }
        public void Start(IFileSystemWatcher watcherInterface = null, int updateRatioInMilliseconds = 0)
        {
            Stop();
            _watcher  = new WatcherFileList(_settingsFileWatcher, watcherInterface, updateRatioInMilliseconds);
            _source   = new CancellationTokenSource();
            _fileList = new WatcherCurrentFileList();

            _channel          = Channel.CreateBounded <FileTask>(MaxFileChanges);
            _channelNewOutput = Channel.CreateBounded <NewOutput>(MaxFileChanges);

            _current = Task.Run(async() => await this.ReadChannel(_source.Token));
            _watcher.Start(HandleFileChanges);
        }
Example #5
0
        public void FileList_StartWatching_ChangeFilesCheckState()
        {
            FilterAndCallbackArgument local = null;
            var a = new Action <FilterAndCallbackArgument>(arg =>
            {
                local = arg;
            });

            FileEntry lastEntry = new FileEntry();

            var lc = new Action <FileListType>(list =>
            {
                foreach (var e in list)
                {
                    lastEntry = e;
                    Debug.WriteLine($"{e.FileName}: {e.LastChanges}");
                }
            });


            Mock <IFileSystemWatcher> m = new Mock <IFileSystemWatcher>();

            m.Setup(x => x.Open(It.IsAny <FilterAndCallbackArgument>())).Callback((FilterAndCallbackArgument arg) =>
            {
                if (arg == null)
                {
                    throw new ArgumentNullException(nameof(arg));
                }
                a(arg);
            }).Returns(true);
            WatcherFileList w = new WatcherFileList(new FileDirectoryWatcherSettings(), m.Object);

            w.Start(_ => lc(_));

            CheckHelper(local, "f1.txt", ref lastEntry, FileSystemWatcherChangeType.Created);
            CheckHelper(local, "f2.txt", ref lastEntry, FileSystemWatcherChangeType.Changed);
            CheckHelper(local, "f3.txt", ref lastEntry, FileSystemWatcherChangeType.Deleted);
            CheckHelper(local, "f4.txt", ref lastEntry, FileSystemWatcherChangeType.Dispose);
            CheckHelper(local, "f5.txt", ref lastEntry, FileSystemWatcherChangeType.Error);
            CheckHelper(local, "f6.txt", ref lastEntry, FileSystemWatcherChangeType.Rename);
            CheckHelper(local, "f7.txt", ref lastEntry, FileSystemWatcherChangeType.All); // Shouldn't occur in productive environments

            w.Dispose();
        }