/// <summary> /// Constructs a new instance. /// </summary> /// <param name="context">The <see cref="SimpleMessageBusFileProcessorFactoryContext"/> to use.</param> public SimpleMessageBusFileProcessor(SimpleMessageBusFileProcessorFactoryContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } _options = context.Options; _attribute = context.Attribute; _executor = context.Executor; _logger = context.Logger; //RWM: Use reflection because _attribute.GetRootPath() is internal. var dynMethod = _attribute.GetType().GetMethod("GetRootPath", BindingFlags.NonPublic | BindingFlags.Instance); var attributePath = dynMethod.Invoke(_attribute, null); _filePath = Path.Combine(_options.RootFolder, attributePath.ToString()); var settings = new JsonSerializerSettings { DateFormatHandling = DateFormatHandling.IsoDateFormat, }; _serializer = JsonSerializer.Create(settings); }
public SimpleMessageBusFileListener(IOptions <FileSystemOptions> options, SimpleMessageBusFileTriggerAttribute attribute, ITriggeredFunctionExecutor triggerExecutor, ILogger logger, ISimpleMessageBusFileProcessorFactory fileProcessorFactory) { _options = options ?? throw new ArgumentNullException(nameof(options)); _attribute = attribute ?? throw new ArgumentNullException(nameof(attribute)); _triggerExecutor = triggerExecutor ?? throw new ArgumentNullException(nameof(triggerExecutor)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _fileProcessorFactory = fileProcessorFactory ?? throw new ArgumentNullException(nameof(fileProcessorFactory)); _cancellationTokenSource = new CancellationTokenSource(); if (string.IsNullOrEmpty(_options.Value.RootFolder) || !Directory.Exists(_options.Value.RootFolder)) { throw new InvalidOperationException(string.Format("Path '{0}' is invalid. FilesConfiguration.RootPath must be set to a valid directory location.", _options.Value.RootFolder)); } //RWM: Use reflection because _attribute.GetRootPath() is internal. var dynMethod = _attribute.GetType().GetMethod("GetRootPath", BindingFlags.NonPublic | BindingFlags.Instance); var attributePath = dynMethod.Invoke(_attribute, null); _watchPath = Path.Combine(_options.Value.RootFolder, attributePath.ToString()); }