Exemple #1
0
        public IDisposable Watch(string directoryToWatch, Action<Directory> actionToTake)
        {
            _actionToTake = actionToTake;

            Func<Fiber> fiberFactory = () => new SynchronousFiber();

            if (!System.IO.Directory.Exists(directoryToWatch))
                System.IO.Directory.CreateDirectory(directoryToWatch);

            var eventChannel = new ChannelAdapter();
            eventChannel.Connect(x => x.AddConsumerOf<FileCreated>().UsingConsumer(ProcessNewFile));

            Scheduler scheduler = new TimerScheduler(fiberFactory());
            var watcher = new PollingFileSystemEventProducer(directoryToWatch, eventChannel, scheduler, fiberFactory(),
                                                          1.Seconds());

            return watcher;
        }
        public IDisposable Watch(string directoryToWatch, Action<Directory> actionToTake)
        {
            if (actionToTake == null) throw new ArgumentNullException("actionToTake");

            _actionToTake = actionToTake;

            if (!_fileSystem.DirectoryExists(directoryToWatch))
                _fileSystem.CreateDirectory(directoryToWatch);

            Func<Fiber> fiberFactory = () => new SynchronousFiber();
            UntypedChannel eventChannel = new ChannelAdapter();
            eventChannel.Connect(x => x.AddConsumerOf<FileCreated>().UsingConsumer(ProcessNewFile));

            Scheduler scheduler = new TimerScheduler(fiberFactory());
            var watcher = new PollingFileSystemEventProducer(directoryToWatch, eventChannel, scheduler, fiberFactory(), 1.Seconds());

            return watcher;
        }