/// <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)); }
void GetReferencingItems(RepositoryClientBase client, IdentifierTriple variableId, out PhysicalInstance physicalInstance, out DataRelationship dataRelationship, out VariableStatistic variableStatistic) { dataRelationship = null; variableStatistic = null; physicalInstance = VariableMapper.GetPhysicalInstanceWithVariable(variableId, client); foreach (var dr in physicalInstance.DataRelationships) { client.PopulateItem(dr, false, ChildReferenceProcessing.Populate); if (dr.LogicalRecords .SelectMany(x => x.VariablesInRecord) .Any(x => x.CompositeId == variableId)) { dataRelationship = dr; } } foreach (var stats in physicalInstance.Statistics) { client.PopulateItem(stats); if (stats.AgencyId == variableId.AgencyId & stats.VariableReference.Identifier == variableId.Identifier) { variableStatistic = stats; break; } } }
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 ActionResult Update(Guid pk, string agency, string name, string value) { using (var db = ApplicationDbContext.Create()) { try { // Fetch the appropriate variable by ID. var client = RepositoryHelper.GetClient(); var variable = client.GetLatestItem(pk, agency) as Variable; // Get all related items that will have their versions // increased, because they reference the variable. // That is: PhysicalInstance, DataRelationship, and VariableStatistic. PhysicalInstance physicalInstance; DataRelationship dataRelationship; VariableStatistic variableStatistic; GetReferencingItems(client, variable.CompositeId, out physicalInstance, out dataRelationship, out variableStatistic); // Copy information from the POST to the Variable. VariableMapper.UpdateVariableProperty(variable, physicalInstance, dataRelationship, variableStatistic, name, value); // Save the new version of the variable. VersionUpdater.UpdateVersionsAndSave(variable, physicalInstance, dataRelationship, variableStatistic); Guid?piID = physicalInstance?.Identifier; if (piID.HasValue) { var file = db.Files.Where(x => x != null && x.Id == piID) .FirstOrDefault(); if (file != null) { file.HasPendingMetadataUpdates = true; db.SaveChanges(); } } // For x-editable, just a simple 200 return is sufficient if things went well. return(Content(value)); } catch (Exception ex) { throw new HttpException(500, ex.Message, ex); } } }
/// <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; }