Пример #1
0
        FlowFileControllerService GetControllerService(IFlowFileController flowController)
        {
            // resolve repository to store flow file process details
            var logRepository = _flowFileLogFactory.Get();

            // set base path for the flow
            logRepository.DataDir = _config.BasePath;

            FlowFileControllerService processor = _flowControllerServiceFactory.Get(logRepository, flowController);

            return(processor);
        }
Пример #2
0
        /// <summary>
        ///     Creates a new instance.
        /// </summary>
        /// <param name="logRepository">The repositoro to update transaction log details to.</param>
        /// <param name="flowFileRepo">The flow file log repository.</param>
        /// <param name="flowFileController">The batch processor implementation.</param>
        public FlowFileControllerService(
            IFlowService flowService,
            IFlowFileLogRepo flowFileRepo,
            IFlowFileController flowFileController)
        {
            Guard.ArgumentNotNull(flowService, nameof(flowService));
            Guard.ArgumentNotNull(flowFileController, nameof(flowFileController));

            _flowService = flowService;

            FlowFileController = flowFileController;
            Interval           = TimeSpan.FromSeconds(30);

            _dataFileTranRepo = flowFileRepo;

            // the time to poll for incoming data
            _timer          = new Timer();
            _timer.Elapsed += TryProcessNewFlowFiles;
        }
Пример #3
0
 public FlowFileControllerService Get(IFlowFileLogRepo repository, IFlowFileController controller)
 {
     return(_context.Resolve <FlowFileControllerService>(
                new TypedParameter(typeof(IFlowFileLogRepo), repository),
                new TypedParameter(typeof(IFlowFileController), controller)));
 }
Пример #4
0
        /// <summary>
        ///     Starts a controller.
        /// </summary>
        /// <param name="definition">Definition to configure the controller.</param>
        protected void StartController(FlowControllerDefinition definition)
        {
            Guard.ArgumentNotNull(definition, nameof(definition));

            if (_logger.IsDebugEnabled)
            {
                _logger.Debug($"Starting controller {definition.ControllerName}.");
            }

            //flow controller type
            Type flowControllerType;

            // resolve from precompiled list of well known processors
            // or assembly resolve
            if (_dictOfControllerTypes.ContainsKey(definition.ControllerName))
            {
                flowControllerType = _dictOfControllerTypes[definition.ControllerName];
            }
            else
            {
                flowControllerType = Type.GetType(definition.TypeName);
            }

            // ReSharper disable once UsePatternMatching
            IFlowFileController flowController = _flowControllerFactory
                                                 .Create(flowControllerType);

            // flow controller
            if (flowController == null)
            {
                throw new InvalidOperationException(
                          $"Controller type does not implement {typeof(IFlowFileController).Name}.");
            }

            // build rules that will be used to validate outgoing entitities
            var specProviderBuilder = new SpecProviderBuilder(_specProviderFactory);

            // spec providers expected to be single instance in
            // the application's scope
            if (definition.FieldValidationRules != null)
            {
                Type type = null;

                if (_logger.IsTraceEnabled)
                {
                    _logger.Trace($"Activating controller type {flowController?.TargetEntityType?.AssemblyQualifiedTypeName}.");
                }

                try
                {
                    type = Type.GetType(flowController.TargetEntityType.AssemblyQualifiedTypeName);
                }
                catch (Exception ex)
                {
                    throw new ApplicationException($"Can't load type {flowController.TargetEntityType.AssemblyQualifiedTypeName}.", ex);
                }

                specProviderBuilder.Build(
                    type,
                    definition.FieldValidationRules.ToList());
            }

            // configure data source log
            flowController.Config.InDirectory  = definition.Input;
            flowController.Config.OutDirectory = definition.Output;

            flowController.Flow           = _config.Flow;
            flowController.ControllerName = definition.ControllerName;

            // apply controller configuration details
            if (definition.ConfigurationDetails != null)
            {
                var type = flowController.GetType();

                if (_logger.IsDebugEnabled)
                {
                    _logger.Debug($"Configuring properties of controller type {type.Name} has been initialized.");
                }

                foreach (var configDetail in definition.ConfigurationDetails)
                {
                    var property = type.GetProperty(configDetail.Key);
                    if (property != null)
                    {
                        if (property.GetSetMethod() != null)
                        {
                            property.SetValue(flowController, configDetail.Value);
                        }
                    }
                }
            }

            // complete initialization
            flowController.Initialize();

            if (_logger.IsDebugEnabled)
            {
                _logger.Debug($"Flow controller {definition.ControllerName} has been initialized.");
            }


            FlowFileControllerService processor = GetControllerService(flowController);

            // configure polling internval
            processor.Interval = TimeSpan.FromSeconds(definition.PollInterval);

            // log how many files were processed
            processor.FlowFileProcessed += (o, e) => { Processed++; };

            // start reading from incoming data source
            processor.Start();

            if (_logger.IsDebugEnabled)
            {
                _logger.Debug($"Flow controller {definition.ControllerName} has started.");
            }

            // active processor
            _processor = processor;

            // add to collection of initialized controllers
            _flowControllers.Add(flowController);
        }