예제 #1
0
파일: Session.cs 프로젝트: arastoul/NRules
        public IFactResult TryInsertAll(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 factObject in facts)
            {
                var factWrapper = _workingMemory.GetFact(factObject);
                if (factWrapper == null)
                {
                    factWrapper = new Fact(factObject);
                    toPropagate.Add(factWrapper);
                }
                else
                {
                    failed.Add(factObject);
                }
            }

            var result = new FactResult(failed);

            if (result.FailedCount == 0 || options == BatchOptions.SkipFailed)
            {
                foreach (var fact in toPropagate)
                {
                    _workingMemory.AddFact(fact);
                }

                _network.PropagateAssert(_executionContext, toPropagate);

                PropagateLinked();
            }
            return(result);
        }