private ILimitValueSource CreateValueSourceFrom(ExpanderCountNode countNode)
        {
            Debug.Assert(countNode.IsLiteral || countNode.IsCounterReference || countNode.IsFunctionInvocation);

            if (countNode.IsLiteral)
            {
                return(new LiteralLimitValueSource(countNode.Literal));
            }
            if (countNode.IsFunctionInvocation)
            {
                var functionInvocationContext = new FunctionInvocationContext(countNode.FunctionInvocation, Model);
                return(new FunctionInvocationValueSource(functionInvocationContext));
            }
            var theCounter = Counters.First(counter => counter.CounterName == countNode.CounterReference.CounterName);

            return(new CounterLimitValueSource(theCounter));
        }
Пример #2
0
        private ILimitValueSource CreateValueSourceFrom(ExpanderCountNode countNode)
        {
            Debug.Assert(countNode.IsLiteral || countNode.IsCounterReference || countNode.IsFunctionInvocation);

            switch (countNode.InnerExpression)
            {
            case IntegerLiteralNode literalNode:
                return(new LiteralLimitValueSource(literalNode));

            case FunctionInvocationNode functionInvocationNode:
                var functionInvocationContext = new FunctionInvocationContext(functionInvocationNode, Model);
                return(new FunctionInvocationValueSource(functionInvocationContext));

            case CounterReferenceNode counterReferenceNode:
                var counterReference = Counters.First(counter => counter.CounterName == counterReferenceNode.CounterName);
                return(new CounterLimitValueSource(counterReference));

            default:
                throw new NotImplementedException("Unknown count expression.");
            }
        }
 /// <summary>
 /// Initialize the function invocation limit value with a counter context.
 /// </summary>
 /// <param name="theContext">Counter context.</param>
 public FunctionInvocationValueSource(FunctionInvocationContext theContext)
 {
     this.context = theContext;
 }