public void A_file_is_created()
        {
            _baseDirectory = AppDomain.CurrentDomain.BaseDirectory;

            _filename = "test2.dat";
            _path = Path.Combine(_baseDirectory, _filename);

            System.IO.File.Delete(_path);

            _listener = new Future<FileCreated>();

            _channel = new ChannelAdapter();
            FiberFactory fiberFactory = () => new SynchronousFiber();
            _scheduler = new TimerScheduler(fiberFactory());
            _producer = new PollingFileSystemEventProducer(_baseDirectory, _channel, _scheduler, fiberFactory(),
                                                           20.Seconds());

            Thread.Sleep(5.Seconds());

            using (_channel.Connect(x => x.AddConsumerOf<FileCreated>().UsingConsumer(m => _listener.Complete(m))))
            {
                System.IO.File.Create(_path);

                _listener.WaitUntilCompleted(25.Seconds());
            }

            _producer.Dispose();
        }
        public List<IDisposable> CreateFileSystemEventProducers(string directory, bool usePolling, bool useFileSystemWatcher, UntypedChannel eventChannel, TimeSpan pollingInterval)
        {
            if (string.IsNullOrEmpty(directory))
            {
                throw new ArgumentException("Directory must not be null or empty.", "directory");
            }

            if (eventChannel != null)
            {
                throw new ArgumentException("A channel must be provided.", "eventChannel");
            }

            List<IDisposable> producers = new List<IDisposable>();

            FiberFactory fiberFactory = () => new SynchronousFiber();

            if (usePolling)
            {

                Scheduler scheduler = new TimerScheduler(fiberFactory());
                IDisposable poller = new PollingFileSystemEventProducer(directory, eventChannel,
                                                                        scheduler, fiberFactory(), pollingInterval);
                producers.Add(poller);
            }

            if (useFileSystemWatcher)
            {
                IDisposable watcher = new FileSystemEventProducer(directory, eventChannel);
            }

            return producers;
        }
Exemple #3
0
        public List <IDisposable> CreateFileSystemEventProducers(string directory, bool usePolling, bool useFileSystemWatcher, UntypedChannel eventChannel, TimeSpan pollingInterval)
        {
            if (string.IsNullOrEmpty(directory))
            {
                throw new ArgumentException("Directory must not be null or empty.", "directory");
            }

            if (eventChannel != null)
            {
                throw new ArgumentException("A channel must be provided.", "eventChannel");
            }

            List <IDisposable> producers = new List <IDisposable>();

            FiberFactory fiberFactory = () => new SynchronousFiber();

            if (usePolling)
            {
                Scheduler   scheduler = new TimerScheduler(fiberFactory());
                IDisposable poller    = new PollingFileSystemEventProducer(directory, eventChannel,
                                                                           scheduler, fiberFactory(), pollingInterval);
                producers.Add(poller);
            }

            if (useFileSystemWatcher)
            {
                IDisposable watcher = new FileSystemEventProducer(directory, eventChannel);
            }

            return(producers);
        }
Exemple #4
0
        public IDisposable Watch(string directoryToWatch, Action<Directory> actionToTake)
        {
            if (!System.IO.Directory.Exists(directoryToWatch))
                System.IO.Directory.CreateDirectory(directoryToWatch);

            _actionToTake = actionToTake;
            _eventChannel = new ChannelAdapter();
            _eventChannel.Connect(x => x.AddConsumerOf<FileCreated>().UsingConsumer(ProcessNewFile));

            _scheduler = new TimerScheduler(_fiberFactory());
            _watcher = new PollingFileSystemEventProducer(directoryToWatch, _eventChannel, _scheduler, _fiberFactory(), 1.Seconds());

            return _watcher;
        }
Exemple #5
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 void A_file_is_created()
        {
            _baseDirectory = AppDomain.CurrentDomain.BaseDirectory;

            string dir1 = Path.Combine(_baseDirectory, "dir1");
            string dir2 = Path.Combine(_baseDirectory, "dir2");

            if (System.IO.Directory.Exists(dir1))
                System.IO.Directory.Delete(dir1, true);

            if (System.IO.Directory.Exists(dir2))
                System.IO.Directory.Delete(dir2, true);

            System.IO.Directory.CreateDirectory(dir1);

            _createdListener = new Future<FileCreated>();
            _deletedListener = new Future<FileSystemDeleted>();

            _channel = new ChannelAdapter();
            FiberFactory fiberFactory = () => new SynchronousFiber();
            _scheduler = new TimerScheduler(fiberFactory());
            _producer = new PollingFileSystemEventProducer(_baseDirectory, _channel, _scheduler, fiberFactory(),
                                                           20.Seconds());

            Thread.Sleep(5.Seconds());

            using (_channel.Connect(x =>
                {
                    x.AddConsumerOf<FileCreated>().UsingConsumer(m => _createdListener.Complete(m));
                    x.AddConsumerOf<FileSystemDeleted>().UsingConsumer(m => _deletedListener.Complete(m));
                }))
            {
                System.IO.Directory.Move(dir1, dir2);

                _createdListener.WaitUntilCompleted(10.Seconds());
                _deletedListener.WaitUntilCompleted(10.Seconds());
            }

            _producer.Dispose();
        }