/// <summary> /// Create a new method expression. /// The expression must be an lvalue expression or literal text. /// The expected return type may be <code>null</code>, meaning "don't care". /// If it is an lvalue expression, the parameter types must not be <code>null</code>. /// If it is literal text, the expected return type must not be <code>void</code>. </summary> /// <param name="store"> used to get the parse tree from. </param> /// <param name="functions"> the function mapper used to bind functions </param> /// <param name="variables"> the variable mapper used to bind variables </param> /// <param name="expr"> the expression string </param> /// <param name="returnType"> the expected return type (may be <code>null</code>) </param> /// <param name="paramTypes"> the expected parameter types (must not be <code>null</code> for lvalues) </param> public TreeMethodExpression(TreeStore store, FunctionMapper functions, VariableMapper variables, ITypeConverter converter, string expr, Type returnType, Type[] paramTypes) : base() { Tree tree = store.Get(expr); this.builder = store.Builder; this.bindings = tree.Bind(functions, variables, converter); this.expr = expr; this.type = returnType; this.types = paramTypes; this.node = tree.Root; this.deferred = tree.Deferred; if (node.LiteralText) { if (returnType == typeof(void)) { throw new ELException(LocalMessages.Get("error.method.literal.void", expr)); } } else if (!node.MethodInvocation) { if (!node.LeftValue) { throw new ELException(LocalMessages.Get("error.method.invalid", expr)); } if (paramTypes == null) { throw new ELException(LocalMessages.Get("error.method.notypes")); } } }
/// <summary> /// Create a bindings. </summary> /// <param name="fnMapper"> the function mapper to use </param> /// <param name="varMapper"> the variable mapper to use </param> /// <param name="converter"> custom type converter </param> /// <returns> tree bindings </returns> public virtual Bindings Bind(FunctionMapper fnMapper, VariableMapper varMapper, ITypeConverter converter) { MethodInfo[] methods = null; if (functions.Count > 0) { if (fnMapper == null) { throw new ELException(LocalMessages.Get("error.function.nomapper")); } methods = new MethodInfo[functions.Count]; foreach (IFunctionNode node in functions) { string image = node.Name; MethodInfo method = null; int colon = image.IndexOf(':'); if (colon < 0) { method = fnMapper.ResolveFunction("", image); } else { method = fnMapper.ResolveFunction(image.Substring(0, colon), image.Substring(colon + 1)); } if (method == null) { throw new ELException(LocalMessages.Get("{0} error.function.notfound", image)); } //if (node.VarArgs && method.VarArgs) //{ // if (method.ParameterTypes.length > node.ParamCount + 1) // { // throw new ELException(LocalMessages.Get("error.function.params", image)); // } //} //else //{ // if (method.ParameterTypes.length != node.ParamCount) // { // throw new ELException(LocalMessages.Get("error.function.params", image)); // } //} methods[node.Index] = method; } } ValueExpression[] expressions = null; if (identifiers.Count > 0) { expressions = new ValueExpression[identifiers.Count]; foreach (IIdentifierNode node in identifiers) { ValueExpression expression = null; if (varMapper != null) { expression = varMapper.ResolveVariable(node.Name); } expressions[node.Index] = expression; } } return(new Bindings(methods, expressions, converter)); }
static void Main(string[] args) { DataModel model = new DataModel(); FunctionMapper mapper = new FunctionMapper(); var ip = new byte[] { 127, 0, 0, 1 }; TcpListener server = new TcpListener(new IPAddress(ip), 8888); server.Start(); Byte[] send = new byte[50000]; Byte[] receive = new byte[5000]; string jsonString = ""; Console.WriteLine("Waiting for connection..."); while (true) { TcpClient client = server.AcceptTcpClient(); Console.WriteLine("Connection!..."); NetworkStream stream = client.GetStream(); stream.Read(receive, 0, receive.Length); string received = Encoding.ASCII.GetString(receive); Console.WriteLine(received); jsonObject jsono = JsonConvert.DeserializeObject <jsonObject>(received); jsonString = mapper.Map(jsono); receive = new byte[5000]; received = ""; send = Encoding.UTF8.GetBytes(jsonString); stream.Write(send, 0, send.Length); } }
public virtual ELContext CreateContext(ExpressionFactory expressionFactory, IVariableContext variableContext) { ELResolver elResolver = this.CreateElResolver(); FunctionMapper functionMapper = this.CreateFunctionMapper(); VariableMapper variableMapper = this.CreateVariableMapper(expressionFactory, variableContext); return(new FeelElContext(elResolver, functionMapper, variableMapper)); }
/// <summary> /// Create a new value expression. </summary> /// <param name="store"> used to get the parse tree from. </param> /// <param name="functions"> the function mapper used to bind functions </param> /// <param name="variables"> the variable mapper used to bind variables </param> /// <param name="expr"> the expression string </param> /// <param name="type"> the expected type (may be <code>null</code>) </param> public TreeValueExpression(TreeStore store, FunctionMapper functions, VariableMapper variables, ITypeConverter converter, string expr, Type type) : base() { Tree tree = store.Get(expr); this.builder = store.Builder; this.bindings = tree.Bind(functions, variables, converter); this.expr = expr; this.type = type; this.node = tree.Root; this.deferred = tree.Deferred; if (type == null) { throw new System.NullReferenceException(LocalMessages.Get("error.value.notype")); } }
public override MethodInfo ResolveFunction(string prefix, string localName) { var i = this.functionMappers.GetEnumerator(); MethodInfo method; do { if (!i.MoveNext()) //.hasNext()) { throw LOG.unknownFunction(prefix, localName); } FunctionMapper functionMapper = i.Current;//.next(); method = functionMapper.ResolveFunction(prefix, localName); } while (method == null); return(method); }
/// <summary> /// Create a bindings. </summary> /// <param name="fnMapper"> the function mapper to use </param> /// <param name="varMapper"> the variable mapper to use </param> /// <returns> tree bindings </returns> public virtual Bindings Bind(FunctionMapper fnMapper, VariableMapper varMapper) { return(Bind(fnMapper, varMapper, null)); }
public FeelElContext(ELResolver elResolver, FunctionMapper functionMapper, VariableMapper variableMapper) { this.elResolver = elResolver; this.functionMapper = functionMapper; this.variableMapper = variableMapper; }
public ProcessEngineElContext(IList <FunctionMapper> functionMappers) { functionMapper = new CompositeFunctionMapper(functionMappers); }
/// <param name="elFunctionMapper"> </param> public virtual void AddFunctionMapper(FunctionMapper elFunctionMapper) { FunctionMappers.Add(elFunctionMapper); }
public FunctionService(IDatabaseContext databaseContext, FunctionMapper functionMapper) { _databaseContext = databaseContext; _functionMapper = functionMapper; }
public virtual void Remove(FunctionMapper functionMapper) { this.functionMappers.Remove(functionMapper); }
public virtual void Add(FunctionMapper functionMapper) { this.functionMappers.Add(functionMapper); }
/// <param name="elFunctionMapper"> </param> public virtual void addFunctionMapper(FunctionMapper elFunctionMapper) { this.functionMappers.Add(elFunctionMapper); }