public ActionResult Ajax(FeedModel model) { model.Provider = Provider; if (model.Command == "run-script") { string query = string.Empty; string error = string.Empty; string buffer = string.Empty; string html = string.Empty; Hashtable data = new Hashtable(); if (model.FeedType == DataFeedType.Python) { query = model.Query; } else { query = string.Format("data(sqlquery(\"{0}\"))", model.Query.Replace("\n", " ").Replace("\"", @"\""").Trim()); } var dict = new Dictionary <object, object>(); DataFeedItem.ApplyDefaultParameters(model.DefaultParameters, dict); var parameters = ScriptParameters.Create(dict); var result = _engine.Run(query, parameters); if (result.Exception != null) { error = result.Exception.Message; } buffer = result.Buffer.ToString(); html = result.Html.ToString(); if (result.DataSet.Count > 0) { foreach (KeyValuePair <string, ScriptData> kvp in result.DataSet) { data.Add(kvp.Key, new { Headers = kvp.Value.GetHeaders().Select(x => x.DisplayText).ToArray(), Items = kvp.Value.GetItems() }); } } return(Json(new { Success = true, Message = "", Error = error, Buffer = buffer, Html = html, Data = data, Parameters = parameters.ToString() })); } else { return(Json(new { Success = false, Message = "Invalid command" })); } }
/// <summary> /// Gets a dictionary that contains default parameters (if any) merged with the given parameters, overwritting defaults. /// </summary> public virtual void ApplyDefaultParameters(IDictionary <object, object> parameters) => DataFeedItem.ApplyDefaultParameters(DefaultParameters, parameters);