public D3NEGraph UpdateUserDefinedFunction(string name, D3NEGraph graph, string updatedBy) { var constructor = new ExpressionTreeConstructor(name, graph, FunctionsFacade); // Graph Validation var tree = constructor.Construct(); return(UserDefinedFuncsRepo.UpdateFunction(name, graph, updatedBy)); }
public ExpressionTreeConstructor( string functionName, D3NEGraph graph, FunctionsFacade functionFacade, Dictionary <string, LambdaExpression> cachedTrees = null, Dictionary <string, ParameterExpression> callStackPointers = null ) { FunctionName = functionName; FunctionsFacade = functionFacade; CachedTrees = cachedTrees ?? new Dictionary <string, LambdaExpression>(); CallStackTreePointers = callStackPointers ?? new Dictionary <string, ParameterExpression>(); Validator = new GraphValidator(graph, functionFacade); Validator.Validate(); Nodes = graph.Nodes; LocalVars = new Dictionary <string, ParameterExpression>(); foreach (var localVar in graph.LocalVariables) { LocalVars[localVar.Name] = Expression.Variable(DataTypes.GetType(localVar.Type), $"{functionName}-{localVar.Name}"); } EntryParams = new ParameterExpression[graph.Inputs.Length]; int index = 0; foreach (var param in graph.Inputs) { EntryParams[index++] = Expression.Parameter(DataTypes.GetType(param.Type), $"{functionName}-{param.Name}"); } ReturnParam = Expression.Parameter(DataTypes.GetType(graph.Output.Type), $"{functionName}-{graph.Output.Name}"); LoopVars = new Dictionary <Tuple <int, int>, ParameterExpression>(); var loopNodes = graph.Nodes.Where(n => n.Type == FunctionNames.For || n.Type == FunctionNames.ForEach); foreach (var loopNode in loopNodes) { if (loopNode.Type == FunctionNames.For) { LoopVars[Tuple.Create(loopNode.Id, 1)] = Expression.Variable(typeof(double?), $"{functionName}-LoopVar{loopNode.Id}"); } else if (loopNode.Type == FunctionNames.ForEach) { LoopVars[Tuple.Create(loopNode.Id, 1)] = Expression.Variable(typeof(double?), $"{functionName}-LoopVar{loopNode.Id}"); LoopVars[Tuple.Create(loopNode.Id, 2)] = Expression.Variable(typeof(double?), $"{functionName}-LoopVar{loopNode.Id}"); } } Type[] typeArgs = graph.Inputs.Select(p => DataTypes.GetType(p.Type)).Concat(new Type[] { DataTypes.GetType(graph.Output.Type) }).ToArray(); Type lambdaType = Expression.GetFuncType(typeArgs); Self = Expression.Variable(lambdaType, $"{functionName}-Self"); ReturnTarget = Expression.Label(ReturnParam.Type, $"{functionName}-Return"); }
public IHttpActionResult PutGraph([FromUri] string name, [FromBody] D3NEGraph graph) { var updated = VxbFacade.UpdateUserDefinedFunction(name, graph, null); if (updated == null) { return(NotFound()); } return(Ok(graph)); }
public D3NEGraph UpdateFunction(string name, D3NEGraph graph, string updatedBy) { using (var db = new ApiDbContext()) { var function = db.UserDefinedFunctions.Find(name); if (function == null) { return(null); } function.GraphJson = JsonConvert.SerializeObject(graph); function.LastUpdatedBy = updatedBy; function.LastUpdatedOn = DateTime.Now; db.SaveChanges(); return(graph); } }
public D3NEGraph CreateFunction(string name, D3NEGraph graph, string createdBy) { using (var db = new ApiDbContext()) { db.UserDefinedFunctions.Add(new UserDefinedFunction { Name = name, GraphJson = JsonConvert.SerializeObject(graph), CreatedOn = DateTime.Now, CreatedBy = createdBy, LastUpdatedOn = DateTime.Now, LastUpdatedBy = createdBy }); db.SaveChanges(); return(graph); } }
public IHttpActionResult PostGraph([FromUri] string name, [FromBody] D3NEGraph graph) { VxbFacade.CreateUserDefinedFunction(name, graph, null); return(Created("", graph)); }
public GraphValidator(D3NEGraph graphModel, FunctionsFacade functionFacade) { Model = graphModel; Facade = functionFacade; }