Example #1
0
        public ViewModel()
        {
            _sync = new Progress <ImmutableArray <byte> >(m => Images.Add(m.ToBuilder().ToArray()));
            var linkOptions = new DataflowLinkOptions {
                PropagateCompletion = true
            };

            var toUI  = new ToUI(_sync);
            var merge = new Merge(2);

            merge.Block.LinkTo(toUI.Target, linkOptions);

            var grayscale = new Grayscale();
            var pixelate  = new Pixelate();

            grayscale.Source.LinkTo(merge.Block /*, linkOptions*/);
            pixelate.Source.LinkTo(merge.Block /*, linkOptions*/);

            Task _ = ForwardCompletionAsync(merge.Block,
                                            grayscale.Source, pixelate.Source);

            var dogs      = new Downloader();
            var toEffects = new BroadcastBlock <ImageState>(i => i);

            toEffects.LinkTo(grayscale.Target, linkOptions);
            toEffects.LinkTo(pixelate.Target, linkOptions);
            dogs.Source.LinkTo(toEffects, linkOptions);
        }
Example #2
0
        public ViewModel()
        {
            _sync = new Progress <ImmutableArray <byte> >(Images.Add);
            var linkOptions = new DataflowLinkOptions {
                PropagateCompletion = true
            };

            var storage       = new Storage();
            var toUI          = new ToUI(_sync);
            var grayscale     = new Grayscale();
            var fromGrayscale = new BroadcastBlock <(ImmutableArray <byte> data, string topic, int index)>(i => i);

            grayscale.Source.LinkTo(fromGrayscale, linkOptions);
            fromGrayscale.LinkTo(storage.Target, linkOptions);
            fromGrayscale.LinkTo(toUI.Target, linkOptions);

            var blur     = new GaussianBlur();
            var oilPaint = new OilPaint();
            var pixelate = new Pixelate();

            blur.Source.LinkTo(grayscale.Target /*, linkOptions*/);
            oilPaint.Source.LinkTo(grayscale.Target /*, linkOptions*/);
            pixelate.Source.LinkTo(grayscale.Target /*, linkOptions*/);

            Task.WhenAll(
                blur.Source.Completion,
                oilPaint.Source.Completion,
                pixelate.Source.Completion)
            .ContinueWith(c => grayscale.Target.Complete());
            //Task _ = ForwardCompletionAsync(grayscale.Target,
            //                blur.Source, oilPaint.Source /*oilPaint.Target*/, pixelate.Source);

            var cats      = new Downloader("cat");
            var dogs      = new Downloader("dog");
            var toEffects = new BroadcastBlock <(ImmutableArray <byte> data, string topic, int index)>(i => i);

            toEffects.LinkTo(blur.Target, linkOptions);
            toEffects.LinkTo(oilPaint.Target, linkOptions);
            toEffects.LinkTo(pixelate.Target, linkOptions, x => x.topic == "cat");
            dogs.Source.LinkTo(toEffects /*, linkOptions*/);
            cats.Source.LinkTo(toEffects /*, linkOptions*/);
            Task _ = ForwardCompletionAsync(toEffects,
                                            dogs.Source, cats.Source);
        }