public JObject Post(string lambda, [FromBody] JObject input) { Library.DataModel.ItemList result = crudService.Query("_js", new Library.DataModel.DataQuery() { PageNumber = 1, PageSize = 1, RawQuery = $"{{\"Path\":\"{lambda}\"}}" }); JToken js = result.Items[0]; string code = js["Code"].ToString(); Dictionary <string, object> tmpIn = input.ToObject <Dictionary <string, object> >(); Dictionary <string, object> tmpOur = new Dictionary <string, object>(); Engine add = new Engine() .SetValue("input", tmpIn) .SetValue("output", tmpOur) .Execute(code); return(JObject.FromObject(tmpOur)); }
public JObject Post(string lambda, [FromBody] JObject input) { Library.DataModel.ItemList result = crudService.Query("_js", new Library.DataModel.DataQuery() { PageNumber = 1, PageSize = 1, RawQuery = $"{{\"Path\":\"{lambda}\"}}" }); JToken js = result.Items[0]; string code = js["Code"].ToString(); Dictionary <string, object> tmpIn = input.ToObject <Dictionary <string, object> >(); Dictionary <string, object> tmpOut = new Dictionary <string, object>(); Engine engine = new Engine((x) => { x.AllowClr(typeof(JavascriptRestClient).Assembly); x.AllowClr(typeof(JavascriptRestClientRequest).Assembly); }); engine.SetValue("input", tmpIn); engine.SetValue("RAWCMSRestClient", Jint.Runtime.Interop.TypeReference.CreateTypeReference(engine, typeof(JavascriptRestClient))); engine.SetValue("RAWCMSRestClientRequest", Jint.Runtime.Interop.TypeReference.CreateTypeReference(engine, typeof(JavascriptRestClientRequest))); engine.SetValue("output", tmpOut); try { logger.LogDebug($"calling lambda: {lambda}"); engine.Execute(code); } catch (Exception e) { logger.LogError($"Error on lambda javascript script: {e.Message} "); tmpOut.Add("Error", e.Message); } logger.LogDebug($"Lambda response: {tmpOut}"); return(JObject.FromObject(tmpOut)); }