示例#1
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);
        }
        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;
        }
        public void A_file_is_created()
        {
            _baseDirectory = AppDomain.CurrentDomain.BaseDirectory;

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

            System.IO.File.Delete(_path);

            _listener = new Future<FileCreated>();

            _channel = new ChannelAdapter();
            _producer = new FileSystemEventProducer(_baseDirectory, _channel);

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

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

            _producer.Dispose();
        }
        /// <summary>
        /// Creates a PollingFileSystemEventProducer
        /// </summary>
        /// <param name="directory">The directory to watch</param>
        /// <param name="channel">The channel where events should be sent</param>
        /// <param name="scheduler">Event scheduler</param>
        /// <param name="fiber">Fiber to schedule on</param>
        /// <param name="checkInterval">The maximal time between events or polls on a given file</param>
        /// <param name="checkSubDirectory">Indicates if subdirectorys will be checked or ignored</param>
        public PollingFileSystemEventProducer(string directory, UntypedChannel channel, Scheduler scheduler, Fiber fiber,
                                              TimeSpan checkInterval, bool checkSubDirectory)
        {
            _directory     = directory;
            _channel       = channel;
            _fiber         = fiber;
            _hashes        = new Dictionary <string, Guid>();
            _scheduler     = scheduler;
            _checkInterval = checkInterval;

            _scheduledAction = scheduler.Schedule(3.Seconds(), _fiber, HashFileSystem);

            ChannelAdapter myChannel = new ChannelAdapter();

            _connection = myChannel.Connect(connectionConfigurator =>
            {
                connectionConfigurator.AddConsumerOf <FileSystemChanged>().UsingConsumer(HandleFileSystemChangedAndCreated);
                connectionConfigurator.AddConsumerOf <FileSystemCreated>().UsingConsumer(HandleFileSystemChangedAndCreated);
                connectionConfigurator.AddConsumerOf <FileSystemRenamed>().UsingConsumer(HandleFileSystemRenamed);
                connectionConfigurator.AddConsumerOf <FileSystemDeleted>().UsingConsumer(HandleFileSystemDeleted);
            });

            _fileSystemEventProducer = new FileSystemEventProducer(directory, myChannel, checkSubDirectory);
        }
        /// <summary>
        /// Creates a PollingFileSystemEventProducer
        /// </summary>		
        /// <param name="directory">The directory to watch</param>
        /// <param name="channel">The channel where events should be sent</param>
        /// <param name="scheduler">Event scheduler</param>
        /// <param name="fiber">Fiber to schedule on</param>
        /// <param name="checkInterval">The maximal time between events or polls on a given file</param>
        /// <param name="checkSubDirectory">Indicates if subdirectorys will be checked or ignored</param>
        public PollingFileSystemEventProducer(string directory, UntypedChannel channel, Scheduler scheduler, Fiber fiber,
            TimeSpan checkInterval, bool checkSubDirectory)
        {
            _directory = directory;
            _channel = channel;
            _fiber = fiber;
            _hashes = new Dictionary<string, Guid>();
            _scheduler = scheduler;
            _checkInterval = checkInterval;

            _scheduledAction = scheduler.Schedule(3.Seconds(), _fiber, HashFileSystem);

            ChannelAdapter myChannel = new ChannelAdapter();

            _connection = myChannel.Connect(connectionConfigurator =>
            {
                connectionConfigurator.AddConsumerOf<FileSystemChanged>().UsingConsumer(HandleFileSystemChangedAndCreated);
                connectionConfigurator.AddConsumerOf<FileSystemCreated>().UsingConsumer(HandleFileSystemChangedAndCreated);
                connectionConfigurator.AddConsumerOf<FileSystemRenamed>().UsingConsumer(HandleFileSystemRenamed);
                connectionConfigurator.AddConsumerOf<FileSystemDeleted>().UsingConsumer(HandleFileSystemDeleted);
            });

            _fileSystemEventProducer = new FileSystemEventProducer(directory, myChannel, checkSubDirectory);
        }