Example #1
0
 private string evaluateAnyExpression(ConfigSectionNode exprContainer, string expression)
 {
     try
                         {
                             var evl = new Evaluator( expression );
                             return evl.Evaluate();
                         }
                         catch(Exception error)
                         {
                             throw new ConfigException(StringConsts.CONFIGURATION_SCRIPT_EXPRESSION_EVAL_ERROR.Args( expression,
                                                                                                                     exprContainer.RootPath,
                                                                                                                     error.ToMessageWithType()),
                                                                                                                     error);
                         }
 }
Example #2
0
        private bool evaluateBooleanConditionExpression(ConfigSectionNode exprContainer)
        {
            string expression = CoreConsts.UNKNOWN;
                                try
                                {
                                    expression = exprContainer.Value;
                                    var evl = new Evaluator( expression );
                                    var evlResult = evl.Evaluate();

                                    var condition = evlResult=="1" ||
                                                    evlResult.Equals("yes", StringComparison.InvariantCultureIgnoreCase) ||
                                                    evlResult.Equals("true", StringComparison.InvariantCultureIgnoreCase) ||
                                                    evlResult.Equals("t", StringComparison.InvariantCultureIgnoreCase);

                                    exprContainer.m_Script_Bool_Condition_Result = condition;
                                    return condition;
                                }
                                catch(Exception error)
                                {
                                    throw new ConfigException(StringConsts.CONFIGURATION_SCRIPT_EXPRESSION_EVAL_ERROR.Args( expression,
                                                                                                                            exprContainer.RootPath,
                                                                                                                            error.ToMessageWithType()),
                                                                                                                            error);
                                }
        }
Example #3
0
    private bool invokeEvaluator(NetSiteState netState, Evaluator evaluator)
    {
        if (netState==null) return false;

        string evaluated = string.Empty;

        lock(netState.m_Variables)
        {
          evaluated = evaluator.Evaluate(
                         (varName)=>
                         {
                            if (varName.StartsWith(VAR_EXPRESSION_PREFIX)&&varName.Length>VAR_EXPRESSION_PREFIX.Length)
                            {
                               NetSiteState._value lookedUp;
                               varName = varName.Substring(VAR_EXPRESSION_PREFIX.Length);
                               if (netState.m_Variables.TryGetValue(varName, out lookedUp)) return lookedUp.Value.ToString();
                               //is it important to return "0" so all expressions keep working even if the variable does not exist
                               return "0";
                            }
                            return varName;
                         });
        }
        if (evaluated=="1" ||  //this check for speed as AsBool() does extra conv and parses as int
            evaluated.AsBool()) return true;

        return false;
    }