예제 #1
0
파일: Session.cs 프로젝트: arastoul/NRules
        public void QueueRetractLinked(Activation activation, IEnumerable <KeyValuePair <object, object> > keyedFacts)
        {
            var toRemove    = new List <Tuple <object, Fact> >();
            var toPropagate = new List <Fact>();

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

            LinkedFactSet current;

            if (_linkedFacts.Count == 0 || (current = _linkedFacts.Peek()).Action != LinkedFactAction.Retract)
            {
                current = new LinkedFactSet(LinkedFactAction.Retract);
                _linkedFacts.Enqueue(current);
            }
            current.Facts.AddRange(toPropagate);
        }
예제 #2
0
파일: Session.cs 프로젝트: zhrjin/NRules
        public void RetractLinked(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.GetFact(fact);

            if (factWrapper == null)
            {
                throw new ArgumentException($"Linked fact does not exist. Key={key}", nameof(fact));
            }
            _network.PropagateRetract(_executionContext, new List <Fact> {
                factWrapper
            });
            _workingMemory.RemoveLinkedFact(activation, key, factWrapper);
        }
예제 #3
0
파일: Session.cs 프로젝트: zhlf1987/NRules
        public void RetractLinked(Activation activation, IEnumerable <KeyValuePair <object, object> > keyedFacts)
        {
            var toRemove    = new List <Tuple <object, Fact> >();
            var toPropagate = new List <Fact>();

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