private ActionResult RunProgressInBackground(string script) { var logFile = $"RunPythonScriptInBackground.{DateTime.Now:yyyyMMddHHmmss}"; ViewBag.LogFile = logFile; var qs = Request.Url?.Query; HostingEnvironment.QueueBackgroundWorkItem(ct => { var qsa = HttpUtility.ParseQueryString(qs ?? ""); var pm = new PythonModel(CurrentDatabase); pm.DictionaryAdd("LogFile", logFile); foreach (string key in qsa) { pm.DictionaryAdd(key, qsa[key]); } string result = pm.RunScript(script); if (result.HasValue()) { pm.LogToContent(logFile, result); } }); return(View("RunPythonScriptProgress")); }
public ActionResult PyScript(string name, string p1, string p2, string v1, string v2) { #if DEBUG #else try { #endif var script = CurrentDatabase.ContentOfTypePythonScript(name); if (!script.HasValue()) { return(Message("no script named " + name)); } if (!ScriptModel.CanRunScript(script)) { return(Message("Not Authorized to run this script")); } if (Regex.IsMatch(script, @"model\.Form\b")) { return(Redirect("/PyScriptForm/" + name)); } script = script.Replace("@P1", p1 ?? "NULL") .Replace("@P2", p2 ?? "NULL") .Replace("V1", v1 ?? "None") .Replace("V2", v2 ?? "None"); if (script.Contains("@qtagid")) { var id = CurrentDatabase.FetchLastQuery().Id; var tag = CurrentDatabase.PopulateSpecialTag(id, DbUtil.TagTypeId_Query); script = script.Replace("@qtagid", tag.Id.ToString()); } ViewBag.report = name; ViewBag.url = Request.Url?.PathAndQuery; if (script.Contains("Background Process Completed")) { var logFile = $"RunPythonScriptInBackground.{DateTime.Now:yyyyMMddHHmmss}"; ViewBag.LogFile = logFile; var qs = Request.Url?.Query; var host = Util.Host; HostingEnvironment.QueueBackgroundWorkItem(ct => { var qsa = HttpUtility.ParseQueryString(qs ?? ""); var pm = new PythonModel(CurrentDatabase); pm.DictionaryAdd("LogFile", logFile); foreach (string key in qsa) { pm.DictionaryAdd(key, qsa[key]); } string result = pm.RunScript(script); if (result.HasValue()) { pm.LogToContent(logFile, result); } }); return(View("RunPythonScriptProgress")); } var pe = new PythonModel(CurrentDatabase); if (script.Contains("@BlueToolbarTagId")) { var id = CurrentDatabase.FetchLastQuery().Id; pe.DictionaryAdd("BlueToolbarGuid", id.ToCode()); } foreach (var key in Request.QueryString.AllKeys) { pe.DictionaryAdd(key, Request.QueryString[key]); } pe.Output = ScriptModel.Run(name, pe); if (pe.Output.StartsWith("REDIRECT=")) { var a = pe.Output.SplitStr("=", 2); return(Redirect(a[1].TrimEnd())); } return(View(pe)); #if DEBUG #else } catch (Exception ex) { return(RedirectShowError(ex.Message)); } #endif }