Beispiel #1
0
        public override void AddTransformer <TIn, TOut>(Guid parentId, FlowTransformerDefinition <TIn, TOut> definition, FlowLinkDefinition <TIn> link)
        {
            FlowTransformerSettings settings = (FlowTransformerSettings)definition.Settings;
            LinkRouterBase <TOut>   router   = GetLinkFromProducerType <TOut>(settings.ProducerType);

            if (!_blockContainer.TryGetTransformer(definition.BlockInfo.Id, out TransformerBlock <TIn, TOut> transformer))
            {
                BlockHeader header = new BlockHeader(definition.BlockInfo, Definition.ServiceInfo);
                TransformerBlockActionBase <TIn, TOut> action = _actionFactory.CreateTransformerAction <TIn, TOut>(definition.ActionType);

                action.Header  = header;
                action.Context = definition.Settings.Context;

                definition.Settings.Type       = _flowType;
                definition.Settings.Iterations = _iterations;

                action.Logger ??= Logger;

                IBlockLinkReceiver <TIn> receiver = link.LinkFactory.CreateReceiver(link);
                transformer = new TransformerBlock <TIn, TOut>(header, receiver, router, action, definition);

                AssignLoggers(transformer);
                _blockContainer.AddBlock(transformer);
            }

            if (_blockContainer.TryGetSourceBlock(parentId, out SourceBlockBase <TIn> parentBlock))
            {
                Link(parentBlock, transformer, link);
                return;
            }

            throw new Exception($"Cannot link block {definition.BlockInfo.Name} with id {definition.BlockInfo.Id} to parent block. " +
                                "Either the parent block or the child block was not found.");
        }
Beispiel #2
0
        public override void AddBatcher <T>(Guid parentId, FlowBatcherDefinition <T> definition, FlowLinkDefinition <T> link)
        {
            if (!_blockContainer.TryGetSourceBlock(parentId, out SourceBlockBase <T> parentBlock))
            {
                throw new Exception($"Cannot link block {definition.BlockInfo.Name} with id {definition.BlockInfo.Id} to parent block. " +
                                    "Parent block not found.");
            }

            if (!_blockContainer.TryGetBlock(definition.BlockInfo.Id, out BatcherBlock <T> batcher))
            {
                BlockHeader         header   = new BlockHeader(definition.BlockInfo, Definition.ServiceInfo);
                FlowBatcherSettings settings = (FlowBatcherSettings)definition.Settings;

                definition.Settings.Type       = _flowType;
                definition.Settings.Iterations = _iterations;

                LinkRouterBase <List <T> > router   = GetLinkFromProducerType <List <T> >(settings.ProducerType);
                IBlockLinkReceiver <T>     receiver = link.LinkFactory.CreateReceiver(link);

                batcher = new BatcherBlock <T>(header, receiver, router, definition);

                AssignLoggers(batcher);
                _blockContainer.AddBlock(batcher);
            }

            Link(parentBlock, batcher, link);
        }
Beispiel #3
0
 public ProducerBlock(
     BlockHeader header,
     LinkRouterBase <T> router,
     ProducerBlockActionBase <T> action,
     FlowProducerDefinition <T> definition) : base(header, definition.Settings, router)
 {
     _action = action;
 }
Beispiel #4
0
        public BatcherBlock(BlockHeader header, IBlockLinkReceiver <T> receiver,
                            LinkRouterBase <List <T> > router, FlowBatcherDefinition <T> definition) : base(header, definition.Settings, router)
        {
            Receiver = receiver;

            FlowBatcherSettings settings = (FlowBatcherSettings)definition.Settings;

            _maxBatchSize    = settings.MaxBatchSize;
            _maxBatchTimeout = settings.MaxBatchTimeout;

            _batch    = new List <T>();
            _syncRoot = new object();
            _toggled  = false;
        }
Beispiel #5
0
        protected void AddProducer <T>(FlowProducerDefinition <T> definition, ProducerBlockActionBase <T> action)
        {
            BlockHeader header = new BlockHeader(definition.BlockInfo, Definition.ServiceInfo);

            action.Header  = header;
            action.Context = definition.Settings.Context;

            definition.Settings.Type       = _flowType;
            definition.Settings.Iterations = _iterations;

            if (action.Logger == null)
            {
                action.Logger = Logger;
            }

            LinkRouterBase <T> router = GetLinkFromProducerType <T>(definition.Settings.ProducerType);
            ProducerBlock <T>  block  = new ProducerBlock <T>(header, router, action, definition);

            AssignLoggers(block);
            _blockContainer.AddProducer(block);
        }
Beispiel #6
0
 public WaiterBlock(BlockHeader header, IBlockLinkReceiver <T> receiver, LinkRouterBase <T> router, FlowWaiterDefinition <T> definition)
     : base(header, definition.Settings, router)
 {
     Receiver = receiver;
 }
 protected SourceBlockBase(BlockHeader header, FlowSettings settings, LinkRouterBase <T> router) : base(header, settings)
 {
     Router   = router;
     Children = new List <ITargetBlock <T> >();
 }
Beispiel #8
0
 public TransformerBlock(BlockHeader header, IBlockLinkReceiver <TIn> receiver, LinkRouterBase <TOut> router,
                         TransformerBlockActionBase <TIn, TOut> action, FlowTransformerDefinition <TIn, TOut> definition) : base(header, definition.Settings, router)
 {
     Receiver = receiver;
     _action  = action;
 }