Esempio n. 1
0
        public AlphaBuilderContext <T> BuildSelectionNode <T>(AlphaBuilderContext <T> context, Expression <Func <T, bool> > conditionExpression)
            where T : class
        {
            using (_logger.BeginScope($"{nameof(BuildSelectionNode)}<{typeof(T).Name}>"))
            {
                var alphaCondition = new AlphaCondition <T>(conditionExpression);

                _logger.LogDebug($"Condition: {alphaCondition}");

                IAlphaNode <T> alphaNode = context.CurrentNode;

                SelectionNode <T> selectionNode = alphaNode.GetChildNodes <SelectionNode <T> >()
                                                  .FirstOrDefault(x => x.Condition.Equals(alphaCondition));
                if (selectionNode == null)
                {
                    using (_logger.BeginScope("Create"))
                    {
                        _logger.LogDebug($"Creating selection node: {typeof(T).Name}");

                        selectionNode = new SelectionNode <T>(_loggerFactory, alphaCondition);
                        alphaNode.AddChild(selectionNode);
                    }
                }

                return(new RuntimeAlphaBuilderContext <T>(context.Declaration, selectionNode));
            }
        }
        public AlphaBuilderContext <TFact> Build(IRuntimeBuilder builder, AlphaBuilderContext <TFact> context)
        {
            foreach (var condition in _conditions)
            {
                context = builder.BuildSelectionNode(context, condition.ConditionExpression);
            }

            return(context);
        }
Esempio n. 3
0
        public ITerminalNode <T> BuildTerminalNode <T>(AlphaBuilderContext <T> context)
            where T : class
        {
            using (_logger.BeginScope($"{nameof(BuildTerminalNode)}<{typeof(T).Name}>"))
            {
                BetaBuilderContext <T> betaContext = BuildJoinNode(context);

                var factIndexMap = betaContext.CreateIndexMap(betaContext.Declaration);

                _logger.LogDebug($"Creating terminal node: {typeof(T).Name}");

                return(new TerminalNode <T>(betaContext.CurrentSource, factIndexMap));
            }
        }
Esempio n. 4
0
        public BetaBuilderContext <T, T> BuildJoinNode <T>(AlphaBuilderContext <T> context)
            where T : class
        {
            using (_logger.BeginScope($"{nameof(BuildJoinNode)}<{typeof(T).Name}>"))
            {
                var betaSource  = new DummyNode <T>() as ITupleSource <T>;
                var alphaSource = context.CurrentSource as IFactSource <T>;

                _logger.LogDebug($"Creating join node: {typeof(T).Name}");

                var node = new JoinNode <T, T>(betaSource, alphaSource, new BetaCondition <T, T>((x, y) => true));

                return(new RuntimeBetaBuilderContext <T, T>(context.Declaration, node));
            }
        }
 public ContextValue(AlphaBuilderContext <T> alphaContext, BetaBuilderContext <T> betaContext)
 {
     _alphaContext = alphaContext;
     _betaContext  = betaContext;
 }
 public void Add <T>(AlphaBuilderContext <T> alphaContext, BetaBuilderContext <T> betaContext)
     where T : class
 {
     _values.Add(alphaContext.Declaration, new ContextValue <T>(alphaContext, betaContext));
 }