public ActionResult PyScript(string name, string p1, string p2, string v1, string v2) { var m = new PythonScriptModel(CurrentDatabase); var script = m.FetchScript(name); if (script == null) { return(Message("no python script named " + name)); } if (!PythonScriptModel.CanRunScript(script)) { return(Message("Not Authorized to run this script")); } if (Regex.IsMatch(script, @"model\.Form\b")) { return(Redirect("/PyScriptForm/" + name)); } script = m.ReplaceParametersInScript(script, p1, p2, v1, v2); ViewBag.report = name; ViewBag.url = Request.Url?.PathAndQuery; if (script.Contains("Background Process Completed")) { return(RunProgressInBackground(script)); } #if DEBUG #else try { #endif var ret = m.RunPythonScript(script, p1, p2); m.pythonModel.Output = ret; if (m.pythonModel.Output.StartsWith("REDIRECT=")) { var a = m.pythonModel.Output.SplitStr("=", 2); return(Redirect(a[1].TrimEnd())); } return(View(m.pythonModel)); #if DEBUG #else } catch (Exception ex) { return(Message(ex.Message)); } #endif }
public ActionResult InstallPyScriptProject() { var m = new PythonScriptModel(CurrentDatabase); var script = m.FetchScript("InstallPyScriptProject"); if (!script.HasValue()) { script = System.IO.File.ReadAllText(Server.MapPath("/Content/InstallPyScriptProject.py")); } if (!PythonScriptModel.CanRunScript(script)) { return(Message("Not Authorized to run this script")); } return(Redirect("/PyScriptForm/InstallPyScriptProject")); }
public object PythonAPI(string name) { var model = new PythonScriptModel(CurrentDatabase); var script = model.FetchScript(name); if (!CanRunScript(script)) { throw new Exception("Not Authorized to run this script"); } model.PrepareHttpPost(); var query = Request.RequestUri.ParseQueryString(); foreach (var key in query.AllKeys) { model.pythonModel.DictionaryAdd(key, query.Get(key)); } var ret = model.RunPythonScript(script); return(new { output = ret, data = model.pythonModel.Data }); }
public ActionResult PyScriptForm(string name, string p1 = null, string p2 = null) { #if DEBUG #else try { #endif var m = new PythonScriptModel(CurrentDatabase); var script = m.FetchScript(name); m.RunPythonScript(script, p1, p2); return(View(m.pythonModel)); #if DEBUG #else } catch (Exception ex) { return(RedirectShowError(ex.Message)); } #endif }
public ActionResult PyScriptForm(string name = null) { try { var model = new PythonScriptModel(CurrentDatabase); var script = model.FetchScript(Request.Form["pyscript"] ?? name); model.PrepareHttpPost(); var ret = model.RunPythonScript(script); if (ret.StartsWith("REDIRECT=")) { return(Redirect(ret.Substring(9).Trim())); } if (model.pythonModel.Output.HasValue() && !model.pythonModel.Form.HasValue()) { return(View("PyScript", model.pythonModel)); } return(Content(ret)); } catch (Exception ex) { return(Content($@"<div class='alert alert-danger' style='font-family: monospace; white-space: pre;'>{ex.Message}</div></div>")); } }