private FileProcessor CreateTestProcessor(FileTriggerAttribute attribute) { mockExecutor = new Mock <ITriggeredFunctionExecutor>(MockBehavior.Strict); FileProcessorFactoryContext context = new FileProcessorFactoryContext(config, attribute, mockExecutor.Object); return(new FileProcessor(context)); }
public async Task StartAsync(CancellationToken cancellationToken) { ThrowIfDisposed(); if (_watcher != null && _watcher.EnableRaisingEvents) { throw new InvalidOperationException("The listener has already been started."); } if (string.IsNullOrEmpty(_config.RootPath) || !Directory.Exists(_config.RootPath)) { throw new InvalidOperationException(string.Format("Path '{0}' is invalid. FilesConfiguration.RootPath must be set to a valid directory location.", _config.RootPath)); } CreateFileWatcher(); FileProcessorFactoryContext context = new FileProcessorFactoryContext(_config, _attribute, _triggerExecutor, _trace); _processor = _config.ProcessorFactory.CreateFileProcessor(context); ExecutionDataflowBlockOptions options = new ExecutionDataflowBlockOptions { BoundedCapacity = _processor.MaxQueueSize, MaxDegreeOfParallelism = _processor.MaxDegreeOfParallelism, }; _workQueue = new ActionBlock <FileSystemEventArgs>(async(e) => await ProcessWorkItem(e), options); // on startup, process any preexisting files that haven't been processed yet ProcessFiles(); // Create a timer to cleanup processed files. // The timer doesn't auto-reset. It will reset itself // when we receive more file events _cleanupTimer = new System.Timers.Timer() { AutoReset = false, Interval = _rand.Next(5 * 1000, 8 * 1000) }; _cleanupTimer.Elapsed += OnCleanupTimer; _cleanupTimer.Start(); await Task.FromResult <bool>(true); }
public async Task StartAsync(CancellationToken cancellationToken) { ThrowIfDisposed(); if (_watcher != null && _watcher.EnableRaisingEvents) { throw new InvalidOperationException("The listener has already been started."); } CreateFileWatcher(); FileProcessorFactoryContext context = new FileProcessorFactoryContext(_options.Value, _attribute, _triggerExecutor, _logger); _processor = _fileProcessorFactory.CreateFileProcessor(context); ExecutionDataflowBlockOptions options = new ExecutionDataflowBlockOptions { BoundedCapacity = _processor.MaxQueueSize, MaxDegreeOfParallelism = _processor.MaxDegreeOfParallelism, }; _workQueue = new ActionBlock <FileSystemEventArgs>(async(e) => await ProcessWorkItem(e), options); // on startup, process any preexisting files that haven't been processed yet ProcessFiles(); // Create a timer to cleanup processed files. // The timer doesn't auto-reset. It resets itself as files // are completed. // We start the timer on startup so we have at least one // cleanup pass _cleanupTimer = new System.Timers.Timer() { AutoReset = false, Interval = _rand.Next(5 * 1000, 8 * 1000) }; _cleanupTimer.Elapsed += OnCleanupTimer; _cleanupTimer.Start(); await Task.FromResult <bool>(true); }
public FileProcessor CreateFileProcessor(FileProcessorFactoryContext context) { return(new FileProcessor(context)); }