Пример #1
0
        /// <summary>
        /// Links this block to a next one.
        /// If this block is an action block, it acts as a BroadcastBlock to all linked children.
        /// </summary>
        /// <param name="target"></param>
        /// <param name="linkOptions"></param>
        /// <returns></returns>
        public IFlowBlock LinkTo(IFlowBlock <TOut, TOut> target, DataflowLinkOptions linkOptions = null)
        {
            var targetBuffer = target.GetInputBlock();

            if (!string.IsNullOrEmpty(AppId))
            {
                target.AppId = AppId;
            }
            //var targetAction = target.GetProcessingBlock();
            if (this.ProcType == BlockType.Action)
            {
                BroadcastTo(targetBuffer, false);
            }
            else if (this.ProcType == BlockType.Transform)
            {
                linkOptions = new DataflowLinkOptions()
                {
                    PropagateCompletion = true
                };
                if (_transformer != null)
                {
                    if (linkOptions != null)
                    {
                        _transformer.LinkTo(targetBuffer, linkOptions);
                    }
                    else
                    {
                        _transformer.LinkTo(targetBuffer, linkOptions);
                    }
                }
                else
                {
                    throw new Exception("Can't link blocks which don`t produce data!");
                }
            }
            var actionBlock = this.GetProcessingBlock();

            actionBlock.Completion.ContinueWith(t =>
            {
                if (t.IsFaulted)
                {
                    target.Fault(t.Exception);
                }
                else
                {
                    target.Complete();
                }
            });
            //_lastLinkedBlock = targetAction;
            AddCompletionTask(target.FlowCompletion());

            return(this);
        }
Пример #2
0
 /// <summary>
 /// Set the destination to which to push all data.
 /// </summary>
 /// <param name="dest">A destination/block in your integration flow</param>
 /// <returns></returns>
 public IHarvester <TDocument> SetDestination(IFlowBlock <TDocument> dest)
 {
     Destination = dest;
     return(this);
 }