Esempio n. 1
0
        private void BuildJoinNode(ReteBuilderContext context, IEnumerable <ConditionElement> conditions = null)
        {
            var betaConditions = new List <IBetaCondition>();

            if (conditions != null)
            {
                foreach (var condition in conditions)
                {
                    var betaCondition = ExpressionCompiler.CompileBetaCondition(condition, context.Declarations);
                    betaConditions.Add(betaCondition);
                }
            }

            var node = context.BetaSource
                       .Sinks.OfType <JoinNode>()
                       .FirstOrDefault(x =>
                                       x.RightSource == context.AlphaSource &&
                                       x.LeftSource == context.BetaSource &&
                                       ConditionComparer.AreEqual(x.Conditions, betaConditions));

            if (node == null)
            {
                node = new JoinNode(context.BetaSource, context.AlphaSource, context.HasSubnet);
                if (context.HasSubnet)
                {
                    node.Conditions.Insert(0, new SubnetCondition());
                }
                foreach (var betaCondition in betaConditions)
                {
                    node.Conditions.Add(betaCondition);
                }
            }
            BuildBetaMemoryNode(context, node);
            context.ResetAlphaSource();
        }