Esempio n. 1
0
        public void QueueUpdateLinked(Activation activation, IEnumerable <KeyValuePair <object, object> > keyedFacts)
        {
            var toUpdate    = new List <Tuple <object, Fact, object> >();
            var toPropagate = new List <Fact>();

            foreach (var keyedFact in keyedFacts)
            {
                var key         = keyedFact.Key;
                var factWrapper = _workingMemory.GetLinkedFact(activation, key);
                if (factWrapper == null)
                {
                    throw new ArgumentException($"Linked fact does not exist. Key={key}");
                }
                factWrapper.Source = new LinkedFactSource(activation);
                toUpdate.Add(System.Tuple.Create(key, factWrapper, keyedFact.Value));
                toPropagate.Add(factWrapper);
            }
            foreach (var item in toUpdate)
            {
                _workingMemory.UpdateLinkedFact(activation, item.Item1, item.Item2, item.Item3);
            }

            LinkedFactSet current;

            if (_linkedFacts.Count == 0 || (current = _linkedFacts.Peek()).Action != LinkedFactAction.Update)
            {
                current = new LinkedFactSet(LinkedFactAction.Update);
                _linkedFacts.Enqueue(current);
            }
            current.Facts.AddRange(toPropagate);
        }
Esempio n. 2
0
        public void UpdateLinked(Activation activation, object key, object fact)
        {
            if (key == null)
            {
                throw new ArgumentNullException(nameof(key));
            }
            if (fact == null)
            {
                throw new ArgumentNullException(nameof(fact));
            }
            var factWrapper = _workingMemory.GetLinkedFact(activation, key);

            if (factWrapper == null)
            {
                throw new ArgumentException($"Linked fact does not exist. Key={key}", nameof(fact));
            }
            _workingMemory.UpdateLinkedFact(activation, key, factWrapper, fact);
            _network.PropagateUpdate(_executionContext, new List <Fact> {
                factWrapper
            });
        }
Esempio n. 3
0
        public void UpdateLinked(Activation activation, IEnumerable <KeyValuePair <object, object> > keyedFacts)
        {
            var toUpdate    = new List <Tuple <object, Fact, object> >();
            var toPropagate = new List <Fact>();

            foreach (var keyedFact in keyedFacts)
            {
                var key         = keyedFact.Key;
                var factWrapper = _workingMemory.GetLinkedFact(activation, key);
                if (factWrapper == null)
                {
                    throw new ArgumentException($"Linked fact does not exist. Key={key}");
                }
                factWrapper.Source = new LinkedFactSource(activation);
                toUpdate.Add(System.Tuple.Create(key, factWrapper, keyedFact.Value));
                toPropagate.Add(factWrapper);
            }
            foreach (var item in toUpdate)
            {
                _workingMemory.UpdateLinkedFact(activation, item.Item1, item.Item2, item.Item3);
            }
            _network.PropagateUpdate(_executionContext, toPropagate);
        }