Exemple #1
0
        public IFactResult TryUpdateAll(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)
                {
                    UpdateFact(factWrapper, fact);
                    toPropagate.Add(factWrapper);
                }
                else
                {
                    failed.Add(fact);
                }
            }

            var result = new FactResult(failed);

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

                _network.PropagateUpdate(_executionContext, toPropagate);

                PropagateLinked();
            }
            return(result);
        }
Exemple #2
0
        public IFactResult TryInsertAll(IEnumerable <object> facts)
        {
            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)
            {
                foreach (var fact in toPropagate)
                {
                    _workingMemory.AddFact(fact);
                }

                _network.PropagateAssert(_executionContext, toPropagate);

                UnlinkFacts();
            }
            return(result);
        }