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)); }
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; }
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); }
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."); }
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); }
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); }
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); }
public IBlockLinkReceiver <T> CreateReceiver <T>(FlowLinkDefinition <T> linkDefinition) { BlockingCollection <T> buffer = CreateBuffer(linkDefinition); return(new LocalLinkReceiver <T>(buffer)); }
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)); }
public abstract void AddBatcher <T>(Guid parentId, FlowBatcherDefinition <T> definition, FlowLinkDefinition <T> link);
public abstract void AddWaiter <T>(Guid parentId, FlowWaiterDefinition <T> definition, FlowLinkDefinition <T> link) where T : IWaitable;
public abstract void AddTransformer <TIn, TOut>(Guid parentId, FlowTransformerDefinition <TIn, TOut> definition, FlowLinkDefinition <TIn> link);
public abstract void AddConsumer <T>(Guid parentId, FlowConsumerDefinition <T> definition, FlowLinkDefinition <T> link);
protected BlockLinkBase(ISourceBlock <T> sourceBlock, ITargetBlock <T> targetBlock, FlowLinkDefinition <T> linkDefinition) { FuncFilter = linkDefinition.FuncFilter; SourceBlock = sourceBlock; TargetBlock = targetBlock; }
public void LinkFrom(FlowLinkDefinition <TIn> link) { this.InboundLinks.Add(link); }
public abstract void GenerateFlowPlanItem(IFlowSourceDefinition <TIn> parent, IFlowPlan plan, FlowLinkDefinition <TIn> link);