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();
        }
Exemplo n.º 2
0
        public void Start()
        {
            // file system watcher will fail if directory isn't there, ensure it is
            if (!System.IO.Directory.Exists(_baseDir))
                System.IO.Directory.CreateDirectory(_baseDir);

            _channel = new ChannelAdapter();
            FiberFactory fiberFactory = () => new SynchronousFiber();
            _scheduler = new TimerScheduler(fiberFactory());
            _producer = new PollingFileSystemEventProducer(_baseDir, _channel, _scheduler, fiberFactory(),
                                                           2.Minutes());

            _channel.Connect(config => config
                                           .AddConsumerOf<FileSystemEvent>()
                                           .BufferFor(3.Seconds())
                                           .Distinct(fsEvent => GetChangedDirectory(fsEvent.Path))
                                           .UsingConsumer(fsEvents => fsEvents.Keys.ToList().ForEach(key =>
                                               {
                                                   if (key == _baseDir)
                                                       return;

                                                   _hostChannel.Send(new FileSystemChange
                                                       {
                                                           ShelfName = key
                                                       });
                                               })));
        }
Exemplo n.º 3
0
        public void Start()
        {
            // file system watcher will fail if directory isn't there, ensure it is
            if (!Directory.Exists(_baseDirectory))
                Directory.CreateDirectory(_baseDirectory);

            _scheduler = new TimerScheduler(new ThreadPoolFiber());
            _channel = new ChannelAdapter();

            _producer = new PollingFileSystemEventProducer(_baseDirectory, _channel, _scheduler, new ThreadPoolFiber(),
                                                           2.Minutes());

            _connection = _channel.Connect(config =>
                {
                    config
                        .AddConsumerOf<FileSystemEvent>()
                        .BufferFor(3.Seconds())
                        .UseScheduler(_scheduler)
                        .Distinct(fsEvent => GetChangedDirectory(fsEvent.Path))
                        .UsingConsumer(fsEvents =>
                            {
                                fsEvents.Keys.Distinct().Each(key =>
                                    {
                                        if (key == _baseDirectory)
                                            return;

                                        _coordinatorChannel.Send(new ServiceFolderChanged(key));
                                    });
                            })
                        .HandleOnFiber(_fiber);
                });
        }
        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();
        }
Exemplo n.º 5
0
        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;
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
0
        public void Stop()
        {
            if (_producer != null)
            {
                _producer.Dispose();
                _producer = null;
            }

            if (_scheduler != null)
            {
                _scheduler.Stop();
                _scheduler = null;
            }
        }
Exemplo n.º 9
0
        public void Stop()
        {
            if (_producer != null)
            {
                _producer.Dispose();
                _producer = null;
            }

            if (_scheduler != null)
            {
                _scheduler.Stop();
                _scheduler = null;
            }

            if (_connection != null)
            {
                _connection.Dispose();
                _connection = null;
            }

            _channel = null;
        }