Esempio n. 1
0
        public override void AddConsumer <T>(Guid parentId, FlowConsumerDefinition <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.TryGetConsumer(definition.BlockInfo.Id, out ConsumerBlock <T> consumer))
            {
                BlockHeader header = new BlockHeader(definition.BlockInfo, Definition.ServiceInfo);
                ConsumerBlockActionBase <T> action = _actionFactory.CreateConsumerAction <T>(definition.ActionType);

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

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

                action.Logger ??= Logger;

                IBlockLinkReceiver <T> receiver = link.LinkFactory.CreateReceiver(link);
                consumer = new ConsumerBlock <T>(header, receiver, action, definition);

                AssignLoggers(consumer);

                _blockContainer.AddBlock(consumer);
            }

            Link(parentBlock, consumer, link);
        }
Esempio n. 2
0
 public ConsumerBlock(BlockHeader header, IBlockLinkReceiver <T> receiver, ConsumerBlockActionBase <T> action, FlowConsumerDefinition <T> definition) :
     base(header, definition.Settings)
 {
     Receiver = receiver;
     _action  = action;
 }