Exemplo n.º 1
0
 private object EvaluateExpression(ValueExpression expr, IScriptContext ctx)
 {
     try
     {
         return(expr.GetValue(CreateElContext(ctx)));
     }
     catch (ELException elexp)
     {
         throw new ScriptException(elexp);
     }
 }
Exemplo n.º 2
0
        public virtual object GetValue(IVariableContext variableContext)
        {
            if (Context.CommandContext == null)
            {
                throw new ProcessEngineException(
                          "Expression can only be evaluated inside the context of the process engine");
            }

            var context = Context.ProcessEngineConfiguration.ExpressionManager.CreateElContext(variableContext);

            return(ValueExpression.GetValue(context));
        }
Exemplo n.º 3
0
        public override object Eval(Bindings bindings, ELContext context)
        {
            ValueExpression expression = bindings.GetVariable(index);

            if (expression != null)
            {
                return(expression.GetValue(context));
            }
            context.PropertyResolved = false;
            object result = context.ELResolver.GetValue(context, null, name);

            if (!context.PropertyResolved)
            {
                throw new PropertyNotFoundException(LocalMessages.Get(string.Format("error.identifier.property.notfound:{0}", name)));
            }
            return(result);
        }
Exemplo n.º 4
0
 public virtual bool EvaluateSimpleUnaryTests(string simpleUnaryTests, string inputName, IVariableContext variableContext)
 {
     try
     {
         ELContext       elContext       = CreateContext(variableContext);
         ValueExpression valueExpression = TransformSimpleUnaryTests(simpleUnaryTests, inputName, elContext);
         return((bool)valueExpression.GetValue(elContext));
     }
     catch (FeelMissingFunctionException e)
     {
         throw LOG.UnknownFunction(simpleUnaryTests, e);
     }
     catch (FeelMissingVariableException e)
     {
         if (inputName.Equals(e.GetVariable()))
         {
             throw LOG.unableToEvaluateExpressionAsNotInputIsSet(simpleUnaryTests, e);
         }
         else
         {
             throw LOG.unknownVariable(simpleUnaryTests, e);
         }
     }
     catch (FeelConvertException e)
     {
         throw LOG.unableToConvertValue(simpleUnaryTests, e);
     }
     catch (ELException e)
     {
         if (e.InnerException is FeelMethodInvocationException)
         {
             throw LOG.unableToInvokeMethod(simpleUnaryTests, (FeelMethodInvocationException)e.InnerException);
         }
         else
         {
             throw LOG.unableToEvaluateExpression(simpleUnaryTests, e);
         }
     }
 }
Exemplo n.º 5
0
        /// <summary>
        /// 根据初始参数值生成Row,常用来提供给查询面板
        /// </summary>
        /// <returns></returns>
        public Row BuildInitRow()
        {
            var data = new Row();

            foreach (var row in Data)
            {
                string name = row.Str("name");
                if (name == "")
                {
                    continue;
                }

                string val = row.Str("val");
                if (val != "" && val[0] == ':')
                {
                    val = ValueExpression.GetValue(val.Substring(1));
                }
                switch (row.Str("type").ToLower())
                {
                case "bool":
                    if (val == "")
                    {
                        data.AddCell <bool>(name);
                    }
                    else
                    {
                        string l = val.ToLower();
                        data.AddCell(name, (l == "1" || l == "true"));
                    }
                    break;

                case "double":
                    if (val != "" && double.TryParse(val, out var v))
                    {
                        data.AddCell(name, v);
                    }
                    else
                    {
                        data.AddCell <double>(name);
                    }
                    break;

                case "int":
                    if (val != "" && int.TryParse(val, out var i))
                    {
                        data.AddCell(name, i);
                    }
                    else
                    {
                        data.AddCell <int>(name);
                    }
                    break;

                case "date":
                    if (val != "" && DateTime.TryParse(val, out var d))
                    {
                        data.AddCell(name, d);
                    }
                    else
                    {
                        data.AddCell <DateTime>(name);
                    }
                    break;

                default:
                    data.AddCell(name, val);
                    break;
                }
            }
            return(data);
        }
Exemplo n.º 6
0
        /// <summary>
        /// 根据初始参数值生成查询参数字典
        /// </summary>
        /// <returns></returns>
        public Dict BuildInitDict()
        {
            Dict dict = new Dict();

            foreach (var row in Data)
            {
                string name = row.Str("name");
                if (name == "")
                {
                    continue;
                }

                string val = row.Str("val");
                if (val != "" && val[0] == ':')
                {
                    val = ValueExpression.GetValue(val.Substring(1));
                }
                switch (row.Str("type").ToLower())
                {
                case "bool":
                    if (val == "")
                    {
                        dict[name] = false;
                    }
                    else
                    {
                        string l = val.ToLower();
                        dict[name] = (l == "1" || l == "true");
                    }
                    break;

                case "double":
                    if (val != "" && double.TryParse(val, out var v))
                    {
                        dict[name] = v;
                    }
                    else
                    {
                        dict[name] = default(double);
                    }
                    break;

                case "int":
                    if (val != "" && int.TryParse(val, out var i))
                    {
                        dict[name] = i;
                    }
                    else
                    {
                        dict[name] = default(int);
                    }
                    break;

                case "date":
                    if (val != "" && DateTime.TryParse(val, out var d))
                    {
                        dict[name] = d;
                    }
                    else
                    {
                        dict[name] = default(DateTime);
                    }
                    break;

                default:
                    dict[name] = val;
                    break;
                }
            }
            return(dict);
        }
 protected override string VisitMemberExpression(MemberExpression memberExpression) =>
 IsMemberExpressionBelongsResource(memberExpression) ? base.VisitMemberExpression(memberExpression) : _valueExpression.GetValue(memberExpression).ToQuery();
Exemplo n.º 8
0
 protected internal override void Invoke()
 {
     InvocationResult = _valueExpression.GetValue(_elContext);
 }
Exemplo n.º 9
0
        public Object GetValue(IVariableContext variableContext)
        {
            ELContext elContext = elContextFactory.CreateElContext(variableContext);

            return(expression.GetValue(elContext));
        }