Esempio n. 1
0
        public FlowLinkResult LinkTo(IFlowTargetDefinition <TOut> target, Func <TOut, bool> filterFunc = null)
        {
            FlowLinkDefinition <TOut> linkDefinition = new FlowLinkDefinition <TOut>(this, target, LocalLinkFactory.GetInstance(), filterFunc);

            OutboundLinks.Add(linkDefinition);

            target.LinkFrom(linkDefinition);
            return(new FlowLinkResult(linkDefinition));
        }
Esempio n. 2
0
 public LocalBlockLink(BlockingCollection <T> buffer, ISourceBlock <T> sourceBlock, ITargetBlock <T> targetBlock,
                       FlowLinkDefinition <T> linkDefinition)
     : base(sourceBlock, targetBlock, linkDefinition)
 {
     if (buffer == null)
     {
         throw new ArgumentNullException(nameof(buffer));
     }
     _buffer = buffer;
 }
Esempio n. 3
0
        private BlockingCollection <T> CreateBuffer <T>(FlowLinkDefinition <T> linkDefinition)
        {
            int  capacity = linkDefinition.Target.Settings.Capacity;
            Guid id       = linkDefinition.Target.BlockInfo.Id;

            BlockingCollection <T> blockingCollection;

            if (!_buffers.TryGetValue(id, out object buffer))
            {
                blockingCollection = new BlockingCollection <T>(capacity);
                _buffers.Add(id, blockingCollection);
            }
            else
            {
                blockingCollection = (BlockingCollection <T>)buffer;
            }

            return(blockingCollection);
        }
Esempio n. 4
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.");
        }
Esempio n. 5
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. 6
0
        protected virtual void Link <T>(ISourceBlock <T> from, ITargetBlock <T> to, FlowLinkDefinition <T> link)
        {
            IBlockLink <T> blockLink = link.LinkFactory.CreateLink(from, to, link);

            from.AddLink(blockLink);
        }
Esempio n. 7
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);
        }
Esempio n. 8
0
        public IBlockLinkReceiver <T> CreateReceiver <T>(FlowLinkDefinition <T> linkDefinition)
        {
            BlockingCollection <T> buffer = CreateBuffer(linkDefinition);

            return(new LocalLinkReceiver <T>(buffer));
        }
Esempio n. 9
0
        public IBlockLink <T> CreateLink <T>(ISourceBlock <T> source, ITargetBlock <T> target, FlowLinkDefinition <T> linkDefinition)
        {
            BlockingCollection <T> buffer = CreateBuffer(linkDefinition);

            return(new LocalBlockLink <T>(buffer, source, target, linkDefinition));
        }
Esempio n. 10
0
 public abstract void AddBatcher <T>(Guid parentId, FlowBatcherDefinition <T> definition, FlowLinkDefinition <T> link);
Esempio n. 11
0
 public abstract void AddWaiter <T>(Guid parentId, FlowWaiterDefinition <T> definition, FlowLinkDefinition <T> link)
     where T : IWaitable;
Esempio n. 12
0
 public abstract void AddTransformer <TIn, TOut>(Guid parentId,
                                                 FlowTransformerDefinition <TIn, TOut> definition, FlowLinkDefinition <TIn> link);
Esempio n. 13
0
 public abstract void AddConsumer <T>(Guid parentId, FlowConsumerDefinition <T> definition, FlowLinkDefinition <T> link);
Esempio n. 14
0
 protected BlockLinkBase(ISourceBlock <T> sourceBlock, ITargetBlock <T> targetBlock, FlowLinkDefinition <T> linkDefinition)
 {
     FuncFilter  = linkDefinition.FuncFilter;
     SourceBlock = sourceBlock;
     TargetBlock = targetBlock;
 }
Esempio n. 15
0
 public void LinkFrom(FlowLinkDefinition <TIn> link)
 {
     this.InboundLinks.Add(link);
 }
Esempio n. 16
0
 public abstract void GenerateFlowPlanItem(IFlowSourceDefinition <TIn> parent, IFlowPlan plan, FlowLinkDefinition <TIn> link);