예제 #1
0
파일: Session.cs 프로젝트: arastoul/NRules
        public IFactResult TryRetractAll(IEnumerable <object> facts, BatchOptions options)
        {
            if (facts == null)
            {
                throw new ArgumentNullException(nameof(facts));
            }

            var failed      = new List <object>();
            var toPropagate = new List <Fact>();

            foreach (var fact in facts)
            {
                var factWrapper = _workingMemory.GetFact(fact);
                if (factWrapper != null && factWrapper.Source == null)
                {
                    toPropagate.Add(factWrapper);
                }
                else
                {
                    failed.Add(fact);
                }
            }

            var result = new FactResult(failed);

            if (result.FailedCount == 0 || options == BatchOptions.SkipFailed)
            {
                _network.PropagateRetract(_executionContext, toPropagate);

                foreach (var fact in toPropagate)
                {
                    _workingMemory.RemoveFact(fact);
                }

                PropagateLinked();
            }
            return(result);
        }