private IDictionary <string, IExpression> GetEvaluationExpressions(MustacheConfigSchema schema)
        {
            var evalExpressions = new Dictionary <string, IExpression>();

            foreach (var calculatedParam in schema.CalculatedParams)
            {
                IExpression expression = null;
                switch (calculatedParam.ExpressionType)
                {
                case ExpressionTypeEnum.Any:
                    expression = new AnyExpression(_logger, calculatedParam, schema);
                    break;

                case ExpressionTypeEnum.Bool:
                    expression = new BooleanExpression(_logger, calculatedParam, schema);
                    break;

                case ExpressionTypeEnum.Case:
                    expression = new CaseExpression(_logger, calculatedParam, schema);
                    break;

                case ExpressionTypeEnum.String:
                    expression = new CaseExpression(_logger, calculatedParam, schema);
                    break;
                }

                if (expression != null)
                {
                    evalExpressions.Add(calculatedParam.Name, expression);
                }
            }

            return(evalExpressions);
        }
Ejemplo n.º 2
0
        public EvaluationExpression BuildEvaluationExpression(MustacheConfigSchema schema)
        {
            using (Timing.Over(_logger, "Build case Expression"))
            {
                // TODO: Add validation
                string EvaluationExpression(Dictionary <string, string> dataView)
                {
                    var terms         = _param.Expression.Split(',');
                    var lookupKey     = terms[0]; // First term is the lookup Case(term0) { ...
                    var dataViewValue = dataView.ContainsKey(lookupKey) ? dataView[lookupKey] : string.Empty;
                    var caseResult    = string.Empty;

                    foreach (var term in terms.Skip(1))
                    {
                        var expression = term.Split('=');
                        if ((dataViewValue == null || !expression[0].Equals(dataViewValue)) &&
                            expression[0] != "default")
                        {
                            continue;
                        }

                        caseResult = expression[1];
                        break;
                    }

                    return(caseResult);
                }

                return(EvaluationExpression);
            }
        }
Ejemplo n.º 3
0
        public EvaluationExpression BuildEvaluationExpression(MustacheConfigSchema config)
        {
            var options = ScriptOptions.Default.AddReferences(Assembly.GetExecutingAssembly());

            using (Timing.Over(_logger, "Build StringExpression"))
            {
                return(CSharpScript.EvaluateAsync <EvaluationExpression>(_param.Expression, options).Result);
            }
        }
Ejemplo n.º 4
0
 public EvaluationExpression BuildEvaluationExpression(MustacheConfigSchema schema)
 {
     // TODO: Add validation
     using (Timing.Over(_logger, "Build Any Expression"))
     {
         var keys = _param.Expression.Split(',');
         return(dataView => dataView.Any(kvp =>
                                         keys.Contains(kvp.Key) &&
                                         bool.TryParse(kvp.Value.ToString(), out var boolValue) &&
                                         boolValue).ToString());
     }
 }
Ejemplo n.º 5
0
        private string GetLambdaString(MustacheConfigSchema config)
        {
            var lambda = string.Empty;

            var expressionString = _param.Expression;
            var tree             = SyntaxFactory.ParseExpression(expressionString);

            foreach (var node in tree.DescendantTokens())
            {
                var key = node.ToString();
                if (config.Params.Any(p => p.Name == key))
                {
                    lambda += $" (bool.TryParse(dataView[\"{key}\"], out bool bool{key}Value) && bool{key}Value)";
                }
                else
                {
                    lambda += key;
                }
            }

            lambda = "dataView => { bool result = " + lambda + "; return result.ToString(); }";
            _logger.LogDebug("Created boolean lambda : " + lambda);
            return(lambda);
        }
Ejemplo n.º 6
0
 public BooleanExpression(ILogger logger, CalculatedParam param, MustacheConfigSchema config)
 {
     _param  = param;
     _logger = logger;
     _evaluationExpression = BuildEvaluationExpression(config);
 }
Ejemplo n.º 7
0
 public AnyExpression(ILogger logger, CalculatedParam param, MustacheConfigSchema schema)
 {
     _param  = param;
     _logger = logger;
     _evaluationExpression = BuildEvaluationExpression(schema);
 }
Ejemplo n.º 8
0
 private List <InclusionExpression> GetInclusionExpressions(Dictionary <string, string> dataView, MustacheConfigSchema schema) =>
 schema.ConditionalInclusions
 .Select(x => new InclusionExpression(