public void Init()
        {
            if (_blockA != null)
            {
                _blockA.Complete();
            }

            Data = new DataflowVisitor();

            _blockA = new BufferBlock <int>(BLOCK_OPTIONS)
                      .Hook("Buffer", Data, 10, 10, Colors.SteelBlue);
            _blockA.AddCommand("Add Item", PostACommand);

            _blockB = new BufferBlock <int>(BLOCK_OPTIONS)
                      .Hook("Buffer", Data, 10, 400, Color.FromRgb(0x3D, 0x04, 0x60));
            _blockB.AddCommand("Add Item", PostBCommand);

            _block3 = new ActionBlock <int>(i =>
            {
                ReflectBlockExtensions.ProcessItem(i, _sync, _block3.BlockInfo);
            }, BLOCK_OPTIONS)
                      .Hook("Action", Data, 600, 200);
            _block3.AddCommand("Release One", ReleaseSingleProcessingTaskCommand);

            _blockA.LinkCandidate(_block3, LINK_OPTIONS);
            _blockB.LinkCandidate(_block3, LINK_OPTIONS);

            //_toolbar.DataContext = this;
        }
Ejemplo n.º 2
0
        public HookBase(
            string name,
            IDataflowBlock block,
            DataflowVisitor visitor,
            Color?color = null)
        {
            #region Validation

            if (visitor == null)
            {
                throw new ArgumentNullException("visitor cannot be null");
            }
            if (block == null)
            {
                throw new ArgumentNullException("_block cannot be null");
            }

            #endregion // Validation

            _block = block;
            color  = color ?? Colors.DarkGray;

            _visitor  = visitor;
            BlockInfo = new BlockInformation(name,
                                             _block.IsImplements(typeof(ISourceBlock <>)),
                                             _block.IsImplements(typeof(ITargetBlock <>)),
                                             color.ToString());

            _visitor.AddBlock(BlockInfo);
            LifeTimeWatcher();
        }
Ejemplo n.º 3
0
        private void Init()
        {
            if (_sourceBlock != null)
            {
                _sourceBlock.Complete();
            }

            Data = new DataflowVisitor();

            _sourceBlock = new BufferBlock <int>()
                           .Hook("Buffer", Data, 50, 300, Colors.SteelBlue);
            _sourceBlock.AddCommand("Add Item", PostCommand);

            _targetBlock = new ActionBlock <int>(i =>
            {
                ReflectBlockExtensions.ProcessItem(i, _sync, _targetBlock.BlockInfo);
            }, BLOCK_OPTIONS)
                           .Hook("Action", Data, 800, 10);
            _targetBlock.AddCommand("Release One", ReleaseSingleProcessingTaskCommand);

            var nullTarget = DataflowBlock.NullTarget <int>()
                             .Hook("NullTarget", Data, 500, 500);

            _sourceBlock.LinkTo(_targetBlock, LINK_OPTIONS);
            _unlinkGarbage = _sourceBlock.LinkTo(nullTarget, LINK_OPTIONS);

            //_toolbar.DataContext = this;
        }
Ejemplo n.º 4
0
        public void Init()
        {
            if (_sourceBlock != null)
            {
                _sourceBlock.Complete();
            }

            Data = new DataflowVisitor();

            _sourceBlock = new BufferBlock <int>()
                           .Hook("Buffer", Data, 10, 300, Colors.SteelBlue);
            _sourceBlock.AddCommand("Add Item", PostCommand);

            // TODO: know complete processing counter
            _block = new TransformBlock <int, string>(i =>
            {
                ReflectBlockExtensions.ProcessItem(i, _sync, _block.BlockInfo);
                return(new string('*', i));
            }, BLOCK_OPTIONS)
                     .Hook("Transform", Data, 500, 10);
            _block.AddCommand("Release One", ReleaseSingleProcessingTaskCommand);

            var nullTarget = DataflowBlock.NullTarget <int>()
                             .Hook("NullTarget", Data, 500, 500);

            _nullTarget = DataflowBlock.NullTarget <string>()
                          .Hook("NullTarget", Data, 900, 200);

            _sourceBlock.LinkTo(_block, LINK_OPTIONS);
            _unlinkGarbage = _sourceBlock.LinkTo(nullTarget, LINK_OPTIONS);

            _block.LinkCandidate(_nullTarget, LINK_OPTIONS);

            //_toolbar.DataContext = this;
        }
Ejemplo n.º 5
0
        // generic way to trigger refresh (can be block delegate wrapper or Observable.Interval + scheduler)

        #region Ctor

        #region Overloads

        /// <summary>
        /// Initializes a new instance of the <see cref="PropogateHook{TIn, TOut}"/> class.
        /// </summary>
        /// <param name="local">The local.</param>
        /// <param name="name">The name.</param>
        /// <param name="visitor">Central information repository</param>
        /// <param name="color"></param>
        public PropogateHook(
            IPropagatorBlock <TIn, TOut> local,
            string name,
            DataflowVisitor visitor,
            Color?color = null)
            : this(local, local, name, visitor, color)
        {
        }
Ejemplo n.º 6
0
        // generic way to trigger refresh (can be block delegate wrapper or Observable.Interval + scheduler)
        #region Ctor

        public SourceHook(
            ISourceBlock <T> source,
            string name,
            DataflowVisitor visitor,
            Color?color = null)
            : base(name, source, visitor, color)
        {
            TrackProperties(source);
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Prevents a default instance of the <see cref="PropogateHook{TIn, TOut}"/> class from being created.
 /// </summary>
 /// <param name="source">The source block.</param>
 /// <param name="target">The target block.</param>
 /// <param name="name">The name.</param>
 /// <param name="visitor">Central information repository</param>
 /// <param name="color"></param>
 private PropogateHook(
     ISourceBlock <TOut> source,
     ITargetBlock <TIn> target,
     string name,
     DataflowVisitor visitor,
     Color?color = null)
     : base(source, name, visitor, color)
 {
     _target = target;
 }
Ejemplo n.º 8
0
        // generic way to trigger refresh (can be block delegate wrapper or Observable.Interval + scheduler)

        #region Ctor

        public TargetHook(
            ITargetBlock <T> target,
            string name,
            DataflowVisitor visitor,
            Color?color = null)
            : base(name, target, visitor, color)
        {
            _target = target;
            TrackProperties(target);
        }
Ejemplo n.º 9
0
        public static ISourceHook <T> Hook <T>(
            this ISourceBlock <T> instance,
            string name,
            DataflowVisitor visitor,
            int left    = -1,
            int top     = -1,
            Color?color = null)
        {
            var hook = new SourceHook <T>(instance, name, visitor, color);

            Init(hook, left, top);
            return(hook);
        }
Ejemplo n.º 10
0
        public static IPropogateHook <TIn, TOut> Hook <TIn, TOut>(
            this IPropagatorBlock <TIn, TOut> instance,
            string name,
            DataflowVisitor visitor,
            int left    = -1,
            int top     = -1,
            Color?color = null)
        {
            var hook = new PropogateHook <TIn, TOut>(instance, name, visitor, color);

            Init(hook, left, top);
            return(hook);
        }
Ejemplo n.º 11
0
        private async void LifeTimeWatcher()
        {
            await _block.Completion;

            if (_block.Completion.IsCanceled)
            {
                BlockInfo.State = BlockState.Canceled;
            }
            else if (_block.Completion.IsFaulted)
            {
                BlockInfo.State = BlockState.Faulted;
            }
            else
            {
                BlockInfo.State = BlockState.Completed;
            }

            _visitor.RemoveBlock(BlockInfo);
            _visitor = null;
        }
Ejemplo n.º 12
0
        public void Init()
        {
            Data = new DataflowVisitor();

            _blockFull = new BufferBlock <int>(BLOCK_OPTIONS)
                         .Hook("Full", Data, 10, 10, Colors.SteelBlue);

            _blockEmpty = new BufferBlock <int>(BLOCK_OPTIONS)
                          .Hook("Empty", Data, 10, 450, Color.FromRgb(0x3D, 0x04, 0x60));

            _blockTarget = new ActionBlock <int>(i =>
            {
                ReflectBlockExtensions.ProcessItem(i, _sync, _blockTarget.BlockInfo);
            }, BLOCK_OPTIONS)
                           .Hook("Target", Data, 400, 200);

            _blockEmpty.AddCommand("Offer Empty", OfferEmptyCommand);
            _blockFull.AddCommand("Offer Full", OfferFullCommand);
            _blockTarget.AddCommand("Release One", ReleaseSingleProcessingTaskCommand);

            //_toolbar.DataContext = this;
        }
Ejemplo n.º 13
0
        public void Init()
        {
            if (_source != null)
            {
                _source.Complete();
            }

            Data = new DataflowVisitor();

            _source = new BufferBlock <int>(BLOCK_OPTIONS)
                      .Hook("Buffer", Data, 100, 10, Colors.SteelBlue);
            _source.AddCommand("Add Item", PostCommand);

            _target = new ActionBlock <int>(i =>
            {
                ReflectBlockExtensions.ProcessItem(i, _sync, _target.BlockInfo);
            }, BLOCK_OPTIONS)
                      .Hook("Action", Data, 600, 200);
            _target.AddCommand("Release One", ReleaseSingleProcessingTaskCommand);

            _source.LinkCandidate(_target, LINK_OPTIONS);

            //_toolbar.DataContext = this;
        }
Ejemplo n.º 14
0
        public LinkHook(
            ISourceHook <T> source,
            ITargetBlock <T> target,
            DataflowLinkOptions linkOptions,
            DataflowVisitor visitor,
            Predicate <T> predicate = null,
            LinkCandidateInformation <T> candidate = null)
        {
            _target = target;
            var targetHook = target as ITargetHook <T>;

            if (targetHook != null)
            {
                _targetName = targetHook.BlockInfo.Name;
                _targetInfo = targetHook.BlockInfo;
            }
            _source = source;

            _candidate = candidate;
            if (candidate != null)
            {
                LinkInfo = new LinkToInformation(candidate.Connector, linkOptions, UnLink);
            }

            if (predicate == null)
            {
                _disposal = _source.InternalSource.LinkTo(this, linkOptions);
            }
            else
            {
                _disposal = DataflowBlock.LinkTo(_source.InternalSource, this, linkOptions, predicate);
            }


            _visitor = visitor;
        }