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); }
/// <summary> /// Constructs a new instance /// </summary> /// <param name="context">The <see cref="FileProcessorFactoryContext"/></param> public FileProcessor(FileProcessorFactoryContext context) { if (context == null) { throw new ArgumentNullException("context"); } _config = context.Config; _attribute = context.Attribute; _executor = context.Executor; string attributePath = _attribute.GetNormalizedPath(); _filePath = Path.Combine(_config.RootPath, attributePath); JsonSerializerSettings settings = new JsonSerializerSettings { DateFormatHandling = DateFormatHandling.IsoDateFormat, }; _serializer = JsonSerializer.Create(settings); }
/// <summary> /// Constructs a new instance /// </summary> /// <param name="context">The <see cref="FileProcessorFactoryContext"/></param> public FileProcessor(FileProcessorFactoryContext context) { if (context == null) { throw new ArgumentNullException("context"); } _config = context.Config; _attribute = context.Attribute; _executor = context.Executor; string attributePath = _attribute.GetNormalizedPath(); _filePath = Path.Combine(_config.RootPath, attributePath); JsonSerializerSettings settings = new JsonSerializerSettings { DateFormatHandling = DateFormatHandling.IsoDateFormat, }; _serializer = JsonSerializer.Create(settings); }
private FileProcessor CreateTestProcessor(FileTriggerAttribute attribute) { mockExecutor = new Mock<ITriggeredFunctionExecutor>(MockBehavior.Strict); FileProcessorFactoryContext context = new FileProcessorFactoryContext(config, attribute, mockExecutor.Object, new TestTraceWriter()); return new FileProcessor(context); }
public FileProcessor CreateFileProcessor(FileProcessorFactoryContext context) { return new FileProcessor(context); }
public FileProcessor CreateFileProcessor(FileProcessorFactoryContext context) { return(new FileProcessor(context)); }