示例#1
0
        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
        }
示例#2
0
        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"));
        }