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);
            }
        }
Example #2
0
        public TelemetryService(Func <TelemetryMessage, TelemetryMessage> transform)
        {
            transform.Verify(nameof(transform)).IsNotNull();

            _pipeline = new PipelineBlock <TelemetryMessage>()
                        .Select(transform)
                        .Broadcast();
        }
        /// <summary>
        /// Add pipeline block to pipeline
        /// </summary>
        /// <param name="source">pipeline</param>
        /// <returns>this</returns>
        public IPipelineBlock <T> Add(IPipelineBlock <T> source)
        {
            source.Verify(nameof(source)).IsNotNull();

            lock (_lock)
            {
                _register.Add(source);
            }

            return(this);
        }
Example #4
0
        public StreamRouter(IOption option)
        {
            _option = option;

            _createBlockChainRoute = new PipelineBlock <RouteMessage>()
                                     .DoAction(x => CreateBlockChainRoute(x));

            _pipelineBlock = new PipelineBlock <RouteMessage>()
                             .Register(_createBlockChainRoute)
                             .Broadcast()
                             .DoAction(x => _createBlockChainRoute.Post(x));
        }
 internal static string GetDisplayName(this IPipelineBlock pipelineBlock)
 {
     // it's pipeline block, not pipeline
     if (!(pipelineBlock is IPipeline))
     {
         return(pipelineBlock.GetType().FullName);
     }
     // here is pipeline
     return(pipelineBlock.GetType().GetInterfaces().FirstOrDefault(inter =>
                                                                   !inter.IsGenericType && typeof(IPipelineBlock) != inter && typeof(IPipeline) != inter && typeof(IPipeline).IsAssignableFrom(inter))
            ?.FullName);
 }
Example #6
0
 public void OnBlockStarted(IPipelineBlock block, int itemNumber, object item, ITaskStep step, TaskDefinition task)
 {
     _blockStarted?.Invoke(new BlockStartedEvent
     {
         Block      = block,
         ItemNumber = itemNumber,
         Item       = item,
         Step       = step,
         Task       = task,
         Timestamp  = DateTimeUtils.Now
     });
 }
        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);
        }
        public virtual bool Register(IPipelineBlock output)
        {
            var task = new Task <object>(
                () => output.Process(_source.Token), _source.Token
                );

            if (_queue.TryEnqueue(task))
            {
                task.Start();
                return(true);
            }

            return(false);
        }
Example #12
0
        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);
        }
 internal static Type[] GetPipelineBlockGenericArguments(this IPipelineBlock pipelineBlock)
 {
     return(pipelineBlock.GetType().GetPipelineBlockGenericArguments());
 }
 public static IPipelineBlock <T> Register <T>(this IPipelineBlock <T> block, IPipelineBlock <T> blockToRegister)
 {
     block.Add(blockToRegister);
     return(block);
 }
Example #15
0
 public TelemetryService()
 {
     _pipeline = new PipelineBlock <TelemetryMessage>()
                 .Broadcast();
 }
Example #16
0
 public PipelineBlockJsonModel(IPipelineBlock pipeline)
 {
     Name    = pipeline.GetDisplayName();
     Receive = pipeline.GetPipelineBlockGenericArguments()[0].FullName;
     Return  = pipeline.GetPipelineBlockGenericArguments()[1].FullName;
 }