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 IAlphaMemoryNode BuildAlphaMemoryNode(AlphaNode parent) { AlphaMemoryNode memoryNode = parent.MemoryNode; if (memoryNode == null) { memoryNode = new AlphaMemoryNode(); parent.MemoryNode = memoryNode; } return(memoryNode); }
private TypeNode BuildTypeNode(Type declarationType, AlphaNode parent) { TypeNode typeNode = parent.ChildNodes .Cast <TypeNode>().FirstOrDefault(tn => tn.FilterType == declarationType); if (typeNode == null) { typeNode = new TypeNode(declarationType); parent.ChildNodes.Add(typeNode); } return(typeNode); }