Ejemplo n.º 1
0
        private void BuildJoinNode(ReteBuilderContext context, List <ExpressionElement> conditions = null)
        {
            var expressionElements = conditions ?? new List <ExpressionElement>();
            var node = context.BetaSource
                       .Sinks.OfType <JoinNode>()
                       .FirstOrDefault(x =>
                                       x.RightSource == context.AlphaSource &&
                                       x.LeftSource == context.BetaSource &&
                                       ExpressionElementComparer.AreEqual(
                                           x.Declarations, x.ExpressionElements,
                                           context.Declarations, expressionElements));

            if (node == null)
            {
                var compiledExpressions = new List <ILhsExpression <bool> >(expressionElements.Count);
                foreach (var expressionElement in expressionElements)
                {
                    var compiledExpression = _ruleExpressionCompiler.CompileLhsExpression <bool>(expressionElement, context.Declarations);
                    compiledExpressions.Add(compiledExpression);
                }
                node    = new JoinNode(context.BetaSource, context.AlphaSource, context.Declarations.ToList(), expressionElements, compiledExpressions, context.HasSubnet);
                node.Id = GetNodeId();
            }
            node.NodeInfo.Add(context.Rule);
            BuildBetaMemoryNode(context, node);
            context.ResetAlphaSource();
        }
        private static void AssertNotEqual(List <Declaration> declarationsFirst, IEnumerable <NamedExpressionElement> first, List <Declaration> declarationsSecond, IEnumerable <NamedExpressionElement> second)
        {
            //Act
            bool result = ExpressionElementComparer.AreEqual(declarationsFirst, first, declarationsSecond, second);

            //Assert
            Assert.False(result);
        }
        private static void AssertNotEqual(NamedExpressionElement first, NamedExpressionElement second)
        {
            //Act
            bool result = ExpressionElementComparer.AreEqual(first, second);

            //Assert
            Assert.False(result);
        }
Ejemplo n.º 4
0
        private void BuildSelectionNode(ReteBuilderContext context, ExpressionElement element)
        {
            SelectionNode node = context.CurrentAlphaNode
                                 .ChildNodes.OfType <SelectionNode>()
                                 .FirstOrDefault(sn => ExpressionElementComparer.AreEqual(sn.ExpressionElement, element));

            if (node == null)
            {
                var compiledExpression = ExpressionCompiler.CompileLhsFactExpression <bool>(element);
                node = new SelectionNode(element, compiledExpression);
                context.CurrentAlphaNode.ChildNodes.Add(node);
            }
            node.NodeInfo.Add(context.Rule, element);
            context.CurrentAlphaNode = node;
        }
Ejemplo n.º 5
0
        private void BuildBindingNode(ReteBuilderContext context, BindingElement element)
        {
            var node = context.BetaSource
                       .Sinks.OfType <BindingNode>()
                       .FirstOrDefault(x =>
                                       ExpressionElementComparer.AreEqual(x.ExpressionElement, element));

            if (node == null)
            {
                var compiledExpression = ExpressionCompiler.CompileLhsTupleExpression <object>(element, context.Declarations);
                node = new BindingNode(element, compiledExpression, element.ResultType, context.BetaSource);
            }
            node.NodeInfo.Add(context.Rule, element);
            BuildBetaMemoryNode(context, node);
            context.ResetAlphaSource();
        }
Ejemplo n.º 6
0
        private void BuildAggregateNode(ReteBuilderContext context, AggregateElement element)
        {
            var node = context.AlphaSource
                       .Sinks.OfType <AggregateNode>()
                       .FirstOrDefault(x =>
                                       x.RightSource == context.AlphaSource &&
                                       x.LeftSource == context.BetaSource &&
                                       x.Name == element.Name &&
                                       ExpressionElementComparer.AreEqual(x.Expressions, element.Expressions));

            if (node == null)
            {
                var aggregatorFactory = BuildAggregatorFactory(context, element);
                node = new AggregateNode(context.BetaSource, context.AlphaSource, element.Name,
                                         element.Expressions, aggregatorFactory, context.HasSubnet);
            }
            node.NodeInfo.Add(context.Rule, element);
            BuildBetaMemoryNode(context, node);
            context.ResetAlphaSource();
        }
Ejemplo n.º 7
0
		/// <summary>
		///  static method for comparing two ExpressionElement. This is used in =, <, >, <>, <=, >= elements.
		///  If elements are equal returns 0, if E1 is less that E2, return -1 else if E1 is greater 1 
		/// </summary>
		protected static int Compare (ExpressionElement E1, ExpressionElement E2, DataRow Row)
		{ 
			ExpressionElementComparer comparer = new ExpressionElementComparer(E1, Row);

			return comparer.CompareTo(E2);
		}
Ejemplo n.º 8
0
		/// <summary>
		///  IsNull function does not return boolean value, so throw exception
		/// </summary>
		public override bool Test (DataRow Row) 
		{
			ExpressionElement E;
			ExpressionElement columnElement = (ExpressionElement)Elements [0];

			ExpressionElementComparer comparer = new ExpressionElementComparer(columnElement, Row);

			for (int i = 1; i < Elements.Count; i++)
			{
				E = (ExpressionElement)Elements [i];
				if(comparer.CompareTo(E) == 0)
					return true;
			}
			return false;
		}