private async Task Render(IPipelineBlock block,
                                  ImageContainer container = ImageContainer.Destination,
                                  UndoRedoAction action    = UndoRedoAction.Undo)
        {
            View.SetCursor(CursorType.Wait);

            if (
                !_pipeline
                .Register(block
                          .Add <Bitmap>(
                              (bmp) => RenderBlock(bmp, container, action)
                              )
                          )
                )
            {
                throw new InvalidOperationException(Errors.Pipeline);
            }

            await _pipeline.AwaitResult().ConfigureAwait(true);

            if (container == ImageContainer.Source)
            {
                _cache.Reset();
            }

            if (!_pipeline.Any())
            {
                View.SetCursor(CursorType.Default);
            }
        }
        public static IPipelineBlock <T> Broadcast <T>(this IPipelineBlock <T> block, Predicate <T>?predicate = null)
        {
            var broadcastBlock = new BroadcastBlock <T>(x => x);

            if (block.Count > 0)
            {
                block.Current.LinkToWithPredicate(broadcastBlock, predicate);
            }

            block.Add(broadcastBlock);
            return(block);
        }
        public static IPipelineBlock <T> Select <T>(this IPipelineBlock <T> block, Func <T, T> action, Predicate <T>?predicate = null)
        {
            var transformBlock = new TransformBlock <T, T>(action);

            if (block.Count > 0)
            {
                block.Current.LinkToWithPredicate(transformBlock, predicate);
            }

            block.Add(transformBlock);
            return(block);
        }
        public static IPipelineBlock <T> DoAction <T>(this IPipelineBlock <T> block, Action <T> action, Predicate <T>?predicate = null)
        {
            var actionBlock = new ActionBlock <T>(action);

            if (block.Count > 0)
            {
                block.Current.LinkToWithPredicate(actionBlock, predicate);
            }

            block.Add(actionBlock);
            return(block);
        }
        public static IPipelineBlock <T> DoAction <T>(this IPipelineBlock <T> block, Action <T> action, out IDisposable?disposable, Predicate <T>?predicate = null)
        {
            var actionBlock = new ActionBlock <T>(action);

            disposable = default;
            if (block.Count > 0)
            {
                disposable = block.Current.LinkToWithPredicate(actionBlock, predicate);
            }

            block.Add(actionBlock);
            return(block);
        }
        private async Task Paint(IPipelineBlock block,
                                 ImageContainer container = ImageContainer.Destination)
        {
            if (
                !_pipeline
                .Register(block
                          .Add <Bitmap>(
                              (bmp) => PaintBlock(bmp, container)
                              )
                          )
                )
            {
                throw new InvalidOperationException(Errors.Pipeline);
            }

            await _pipeline.AwaitResult().ConfigureAwait(true);
        }
 public static IPipelineBlock <T> Register <T>(this IPipelineBlock <T> block, IPipelineBlock <T> blockToRegister)
 {
     block.Add(blockToRegister);
     return(block);
 }