protected override void VisitPattern(ReteBuilderContext context, PatternElement element) { context.RegisterDeclaration(element.Declaration); if (element.Source == null) { AlphaNode currentNode = BuildTypeNode(element.ValueType, _root); var betaConditions = new List <ConditionElement>(); foreach (var conditionElement in element.Conditions) { if (conditionElement.Declarations.Count() > 1) { betaConditions.Add(conditionElement); continue; } var alphaCondition = new AlphaCondition(conditionElement.Expression); SelectionNode selectionNode = BuildSelectionNode(alphaCondition, currentNode); currentNode = selectionNode; } context.AlphaSource = BuildAlphaMemoryNode(currentNode); if (betaConditions.Count > 0) { var joinNode = BuildJoinNode(context, betaConditions); context.BetaSource = BuildBetaMemoryNode(context, joinNode); } } else { Visit(context, element.Source); //TODO: Handle a more generic case, when pattern adds its own conditions } }
private SelectionNode BuildSelectionNode(AlphaCondition condition, AlphaNode parent) { SelectionNode selectionNode = parent.ChildNodes .OfType <SelectionNode>().FirstOrDefault(sn => sn.Conditions.First().Equals(condition)); if (selectionNode == null) { selectionNode = new SelectionNode(condition); parent.ChildNodes.Add(selectionNode); } return(selectionNode); }
private void BuildSelectionNode(ReteBuilderContext context, ConditionElement condition) { var alphaCondition = new AlphaCondition(condition.Expression); SelectionNode selectionNode = context.CurrentAlphaNode .ChildNodes.OfType <SelectionNode>() .FirstOrDefault(sn => sn.Condition.Equals(alphaCondition)); if (selectionNode == null) { selectionNode = new SelectionNode(alphaCondition); context.CurrentAlphaNode.ChildNodes.Add(selectionNode); } context.CurrentAlphaNode = selectionNode; }