private void ProcessFlowFile(FileInfo flowFile) { if (FlowFileController == null) { throw new InvalidOperationException("Flow file controller not been configured or assigned."); } try { // create a new flow batch - will create the flow entry if it does not exit var flowBatch = _flowService.GetNewFlowBatch(FlowFileController.Flow.Code); if (_logger.IsInfoEnabled) { _logger.Info( $"New flow file {flowFile.Name} detected. Processing batch {flowBatch.BatchId} in flow {FlowFileController.Flow} by batch controller {FlowFileController.ControllerName}."); } // run processor FlowSnapshot result = null; try { result = FlowFileController.Process(flowFile, flowBatch); if (result == null) { return; // no work to do } } finally { // update transaction log - always to ensure we are not re-processing the data UpdateTransactionLog(flowFile.FullName, result); } if (_logger.IsInfoEnabled) { _logger.Info( $"Flow file {flowFile.Name} processed in batch {flowBatch.BatchId} in flow {FlowFileController.Flow}."); } if (_logger.IsInfoEnabled) { _logger.Info($"Flow {FlowFileController.Flow} transaction log updated."); } } catch (Exception ex) { var msg = $"Failed to process flow file {flowFile.Name}. Flow file controller is {FlowFileController.GetType().Name}. Error: is {ex.Message}"; throw new Exception(msg, ex); } finally { FlowFileProcessed?.Invoke(this, EventArgs.Empty); } }
void UpdateTransactionLog(string sourceFilePath, FlowSnapshot result) { // update flow transaction log var flowFileLogEntry = new FlowFileLogEntry { AddressId = sourceFilePath, TargetAddressId = result.TargetAddressId, // the output file path BatchId = result.Batch.BatchId, DateLastUpdated = DateTime.UtcNow }; _dataFileTranRepo.Add(result.SourceType, result.Batch.Flow, flowFileLogEntry); }