Esempio n. 1
0
 public PredicateBlock(ISourceBlock <T> actualSource,
                       ITargetBlock <T> actualTarget, Predicate <T> predicate)
 {
     this.actualTarget = actualTarget;
     this.predicate    = predicate;
     sourceBlock       = new SourceBlock(actualSource, this);
 }
        public void LinkTo_Calls_Underlying_Target_Block_Method()
        {
            _sourceBlock = new SourceBlockImpl(_options);
            _sourceBlock.LinkTo(_outputBlock, new DataflowLinkOptions());

            _fakeBlock.Verify(b => b.LinkTo(It.IsAny <ITargetBlock <int> >(), It.IsAny <DataflowLinkOptions>()), Times.Once());
        }
Esempio n. 3
0
        public async Task <EnumCollection> GetListedValuesAsync()
        {
            using (JoinableCollection.Join())
            {
                EnumCollectionProjectValue snapshot = await SourceBlock.ReceiveAsync();

                return(snapshot.Value);
            }
        }
Esempio n. 4
0
 public IDataFlowLinkSource <TConvert> LinkTo <TConvert>(IDataFlowLinkTarget <TOutput> target, Predicate <TOutput> predicate)
 {
     SourceBlock.LinkTo(target.TargetBlock, predicate);
     target.AddPredecessorCompletion(SourceBlock.Completion);
     if (!DisableLogging)
     {
         NLogger.Debug(CallingTask.TaskName + $" was linked to (with predicate): {((ITask)target).TaskName}!", CallingTask.TaskType, "LOG", CallingTask.TaskHash, ControlFlow.ControlFlow.STAGE, ControlFlow.ControlFlow.CurrentLoadProcess?.Id);
     }
     return(target as IDataFlowLinkSource <TConvert>);
 }
Esempio n. 5
0
        public void SingleLineOfCodeIsSingleBlock()
        {
            var blocks = SourceBlock.GetBlocks(new List <SourceLine> {
                new SourceLine("    [csharp]", 0),
                new SourceLine("    var a = 5;", 1)
            });

            Assert.True(blocks.Count == 1);
            Assert.True(blocks[0].Code);
            Assert.True(blocks[0].Lines[0].Line == "var a = 5;");
        }
Esempio n. 6
0
 public IDataFlowLinkSource <TConvert> LinkTo <TConvert>(IDataFlowLinkTarget <TOutput> target, Predicate <TOutput> predicate)
 {
     SourceBlock.LinkTo(target.TargetBlock, new DataflowLinkOptions()
     {
         PropagateCompletion = true
     }, predicate);
     if (!DisableLogging)
     {
         NLogger.Debug(CallingTask.TaskName + " was linked to Target (with predicate)!", CallingTask.TaskType, "LOG", CallingTask.TaskHash, ControlFlow.ControlFlow.STAGE, ControlFlow.ControlFlow.CurrentLoadProcess?.LoadProcessKey);
     }
     return(target as IDataFlowLinkSource <TConvert>);
 }
        public virtual SourceBlock <TOutput, TOutputMsg> SourceFor <TOutput, TOutputMsg>(IDataflowNetworkTask <TOutput, TOutputMsg, TOutput, TOutputMsg> source)
            where TOutputMsg : IDataflowMessage <TOutput>
        {
            var task = DecorateTaskWithDefaults(source);

            var options = CreateDefaultExecutionBlockOptions();

            var block = new SourceBlock <TOutput, TOutputMsg>(this, options, task);

            m_CreatedBlocks.Add(block);

            return(block);
        }
Esempio n. 8
0
        public Parser(string language, IEnumerable <IFortranBlock> blockParsers)
        {
            _language = language;

            // Add the text factory for the passed text.
            var textFactory = new SourceBlock(_language);

            _blockParsers.Add(textFactory.Name, textFactory);

            foreach (var bp in blockParsers)
            {
                _blockParsers.Add(bp.Name, bp);
            }
        }
Esempio n. 9
0
        private void computeEndPoints(SingleColourLookup[][] lookups)
        {
            //
            // check each index combination (endpoint or intermediate)
            //
            error = Int32.MaxValue;

            for (int i = 0; i < 2; ++i)
            {
                //
                // check the error for this codebook index
                //
                SourceBlock[] sources = new SourceBlock[3];

                int err = 0;

                for (int channel = 0; channel < 3; ++channel)
                {
                    //
                    // grab the lookup table and index for this channel
                    //
                    SingleColourLookup[] lookup = lookups[channel];

                    int target = colour[channel];
                    //
                    // store a pointer to the source for this channel
                    //
                    sources[channel] = lookup[target].sources[i];
                    //
                    // accumulate the error
                    //
                    int diff = sources[channel].error;

                    err += diff * diff;
                }
                //
                // keep it if the error is lower
                //
                if (err < error)
                {
                    start = new Vec3(sources[0].start / 31.0f, sources[1].start / 63.0f, sources[2].start / 31.0f);

                    end = new Vec3(sources[0].end / 31.0f, sources[1].end / 63.0f, sources[2].end / 31.0f);

                    index = (byte)(2 * i);

                    error = err;
                }
            }
        }
Esempio n. 10
0
        public void MultipleLinesOfCodeIsSingleBlock()
        {
            var blocks = SourceBlock.GetBlocks(new List <SourceLine> {
                new SourceLine("    [csharp]", 0),
                new SourceLine("    var a = 5;", 1),
                new SourceLine("    var b = 6;", 2),
                new SourceLine("    var c = 7;", 3),
                new SourceLine("    var d = 8;", 4)
            });

            Assert.True(blocks.Count == 1);
            Assert.True(blocks[0].Code);
            Assert.True(blocks[0].Lines.Count == 4);
        }
Esempio n. 11
0
        public void EmptyLineDoesNotBreakBlock()
        {
            var blocks = SourceBlock.GetBlocks(new List <SourceLine> {
                new SourceLine("    [csharp]", 0),
                new SourceLine("    var a = 5;", 1),
                new SourceLine("    var b = 6;", 2),
                new SourceLine("", 3),
                new SourceLine("    var c = 7;", 4),
                new SourceLine("    var d = 8;", 5)
            });

            Assert.True(blocks.Count == 1);
            Assert.True(blocks[0].Code);
            Assert.True(blocks[0].Lines.Count == 4); // todo
        }
        public void SetUp()
        {
            _items = new List <int>();

            _options = new ExecutionDataflowBlockOptions {
                BoundedCapacity = 1
            };
            _linkOptions = new DataflowLinkOptions {
                PropagateCompletion = true
            };

            _outputBlock = new ActionBlock <int>(i => _items.Add(i), _options);

            _fakeBlock   = MakeFakePropogatorBlock();
            _sourceBlock = new SourceBlockImpl(_fakeBlock.Object);
            _sourceBlock.LinkTo(_outputBlock, _linkOptions);
        }
Esempio n. 13
0
        public async Task <EnumCollection> GetListedValuesAsync()
        {
            if (!IsReadyToBuild())
            {
                throw new InvalidOperationException("This configuration is not set to build");
            }

            // NOTE: This has a race, if called off the UI thread, the configuration could become
            // inactive underneath us and hence not ready for build, causing below to block forever.

            using (JoinableCollection.Join())
            {
                EnumCollectionProjectValue snapshot = await SourceBlock.ReceiveAsync();

                return(snapshot.Value);
            }
        }
        public async Task <EnumCollection> GetListedValuesAsync()
        {
            if (!IsReadyToBuild())
            {
                throw new InvalidOperationException("This configuration is not set to build");
            }

            // NOTE: This has a race, if called off the UI thread, the configuration could become
            // inactive underneath us and hence not ready for build, causing below to block forever.

            using (JoinableCollection.Join())
            {
                EnumCollectionProjectValue snapshot = await SourceBlock.ReceiveAsync();

                // TODO: This is a hotfix for item ordering. Remove this OrderBy when completing: https://github.com/dotnet/project-system/issues/7025
                return(snapshot.Value.OrderBy(e => e.DisplayName).ToArray());
            }
        }
Esempio n. 15
0
        public IDataFlowLinkSource <TConvert> LinkTo <TConvert>(IDataFlowLinkTarget <TOutput> target, Predicate <TOutput> rowsToKeep, Predicate <TOutput> rowsIntoVoid)
        {
            SourceBlock.LinkTo(target.TargetBlock, new DataflowLinkOptions()
            {
                PropagateCompletion = true
            }, rowsToKeep);
            if (!DisableLogging)
            {
                NLogger.Debug(CallingTask.TaskName + " was linked to Target (with predicate)!", CallingTask.TaskType, "LOG", CallingTask.TaskHash, ControlFlow.ControlFlow.STAGE, ControlFlow.ControlFlow.CurrentLoadProcess?.LoadProcessKey);
            }

            SourceBlock.LinkTo <TOutput>(new VoidDestination <TOutput>().TargetBlock, rowsIntoVoid);
            if (!DisableLogging)
            {
                NLogger.Debug(CallingTask.TaskName + " was also linked to VoidDestination to ignore certain rows!", CallingTask.TaskType, "LOG", CallingTask.TaskHash, ControlFlow.ControlFlow.STAGE, ControlFlow.ControlFlow.CurrentLoadProcess?.LoadProcessKey);
            }

            return(target as IDataFlowLinkSource <TConvert>);
        }
        public void Can_Complete_Source()
        {
            _sourceBlock = new SourceBlockImpl(_options);
            _sourceBlock.LinkTo(_outputBlock, _linkOptions);

            for (var i = 0; i < 5; i++)
            {
                if (_items.Count > 0)
                {
                    break;
                }

                _sourceBlock.Completion.Wait(TimeSpan.FromMilliseconds(10));
            }

            _sourceBlock.Complete();
            _outputBlock.Completion.Wait();

            Assert.That(_outputBlock.Completion.Status, Is.EqualTo(TaskStatus.RanToCompletion));
        }
Esempio n. 17
0
        public IDataFlowLinkSource <TConvert> LinkTo <TConvert>(IDataFlowLinkTarget <TOutput> target, Predicate <TOutput> rowsToKeep, Predicate <TOutput> rowsIntoVoid)
        {
            SourceBlock.LinkTo(target.TargetBlock, rowsToKeep);
            target.AddPredecessorCompletion(SourceBlock.Completion);
            if (!DisableLogging)
            {
                NLogger.Debug(CallingTask.TaskName + $" was linked to (with predicate): {((ITask)target).TaskName}!", CallingTask.TaskType, "LOG", CallingTask.TaskHash, ControlFlow.ControlFlow.STAGE, ControlFlow.ControlFlow.CurrentLoadProcess?.Id);
            }

            VoidDestination <TOutput> voidTarget = new VoidDestination <TOutput>();

            SourceBlock.LinkTo <TOutput>(voidTarget.TargetBlock, rowsIntoVoid);
            voidTarget.AddPredecessorCompletion(SourceBlock.Completion);
            if (!DisableLogging)
            {
                NLogger.Debug(CallingTask.TaskName + $" was also linked to: VoidDestination to ignore certain rows!", CallingTask.TaskType, "LOG", CallingTask.TaskHash, ControlFlow.ControlFlow.STAGE, ControlFlow.ControlFlow.CurrentLoadProcess?.Id);
            }

            return(target as IDataFlowLinkSource <TConvert>);
        }
Esempio n. 18
0
        private void ComputeEndPoints(SingleColourLookup[][] lookups)
        {
            // check each index combination (endpoint or intermediate)
            m_error = int.MaxValue;
            for (int index = 0; index < 2; ++index)
            {
                // check the error for this codebook index
                var sources = new SourceBlock[3];
                int error   = 0;
                for (int channel = 0; channel < 3; ++channel)
                {
                    // grab the lookup table and index for this channel
                    var lookup = lookups[channel];
                    int target = m_colour[channel];

                    // store a pointer to the source for this channel
                    sources[channel] = lookup[target].sources[index];

                    // accumulate the error
                    int diff = sources[channel].error;
                    error += diff * diff;
                }

                // keep it if the error is lower
                if (error < m_error)
                {
                    m_start = new Vec3(
                        (float)sources[0].start / 31.0f,
                        (float)sources[1].start / 63.0f,
                        (float)sources[2].start / 31.0f
                        );
                    m_end = new Vec3(
                        (float)sources[0].end / 31.0f,
                        (float)sources[1].end / 63.0f,
                        (float)sources[2].end / 31.0f
                        );
                    m_index = (Byte)(2 * index);
                    m_error = error;
                }
            }
        }
        public void Can_Process()
        {
            _sourceBlock = new SourceBlockImpl(_options);
            _sourceBlock.LinkTo(_outputBlock, _linkOptions);

            for (var i = 0; i < 5; i++)
            {
                if (_items.Count > 0)
                {
                    break;
                }

                // wait while block is initialized
                _sourceBlock.Completion.Wait(TimeSpan.FromMilliseconds(50));
            }

            _sourceBlock.Complete();
            _outputBlock.Completion.Wait();

            Assert.That(_items.Count, Is.GreaterThan(0));
        }
        public MainWindow()
        {
            this.InitializeComponent();

            RuntimeComponent1.UserControl userControl = new RuntimeComponent1.UserControl();

            Binding testBlockBinding = new Binding()
            {
                Path = new PropertyPath("Text")
            };

            TestBlock.DataContext = MyControl;
            TestBlock.SetBinding(TextBlock.TextProperty, testBlockBinding);

            Binding textBoxBinding = new Binding()
            {
                Path = new PropertyPath("Text"), Mode = BindingMode.TwoWay, Converter = new StringToStringConverter()
            };

            TestBox.DataContext = MyControl;
            TestBox.SetBinding(TextBox.TextProperty, textBoxBinding);

            Binding sourceBlockBinding = new Binding()
            {
                Path = new PropertyPath("Source"), Converter = new UriToStringConverter()
            };

            SourceBlock.DataContext = MyControl;
            SourceBlock.SetBinding(TextBlock.TextProperty, sourceBlockBinding);

            Binding sourceBoxBinding = new Binding()
            {
                Path = new PropertyPath("Source"), Mode = BindingMode.TwoWay, Converter = new UriToStringConverter()
            };

            SourceBox.DataContext = MyControl;
            SourceBox.SetBinding(TextBox.TextProperty, sourceBoxBinding);
        }
Esempio n. 21
0
 public SingleColourLookup(SourceBlock a, SourceBlock b)
 {
     Sources = new[] { a, b };
 }
Esempio n. 22
0
 public SingleColourLookup(SourceBlock one, SourceBlock two)
 {
     Sources    = new SourceBlock[2];
     Sources[0] = one;
     Sources[1] = two;
 }
Esempio n. 23
0
 internal override void CompleteBufferOnPredecessorCompletion() => SourceBlock.Complete();
Esempio n. 24
0
 internal override void FaultBufferOnPredecessorCompletion(Exception e) => SourceBlock.Fault(e);
Esempio n. 25
0
 public SingleColourLookup(SourceBlock a, SourceBlock b)
     : this(new SourceBlock[] { a, b })
 {
 }
Esempio n. 26
0
 public SingleColourLookup(SourceBlock[] _sources)
 {
     sources = _sources;
 }
Esempio n. 27
0
        private void ComputeEndPoints(SingleColourLookup[][] lookups)
        {
            // check each index combination (endpoint or intermediate)
            m_error = int.MaxValue;
            for (int index = 0; index < 2; ++index)
            {
                // check the error for this codebook index
		        SourceBlock[] sources = new SourceBlock[3];
		        int error = 0;
		        for( int channel = 0; channel < 3; ++channel )
		        {
                    // grab the lookup table and index for this channel
			        SingleColourLookup[] lookup = lookups[channel];
			        int target = m_colour[channel];
                    // store a pointer to the source for this channel
                    sources[channel] = lookup[target].sources[index]/* + index*/;
                    
                    // accumulate the error
                    int diff = sources[channel].error;
                    error += diff * diff;	
                }

                // keep it if the error is lower
                if (error < m_error)
                {
                    m_start = new Vec3(
                        (float)sources[0].start / 31.0f,
                        (float)sources[1].start / 63.0f,
                        (float)sources[2].start / 31.0f
                    );
                    m_end = new Vec3(
                        (float)sources[0].end / 31.0f,
                        (float)sources[1].end / 63.0f,
                        (float)sources[2].end / 31.0f
                    );
                    m_index = (byte)(2 * index);
                    m_error = error;
                }
            }
        }
Esempio n. 28
0
 public IDisposable LinkTo(ITargetBlock <TOutput> target, DataflowLinkOptions linkOptions)
 {
     return(SourceBlock.LinkTo(target, linkOptions));
 }
Esempio n. 29
0
 public SingleColourLookup(SourceBlock sources0, SourceBlock sources1)
 {
     Sources0 = sources0;
     Sources1 = sources1;
 }
 public SingleColourLookup(byte[] a,byte[] b)
 {
     sources[0] = new SourceBlock(a);
     sources[1] = new SourceBlock(b);
 }