Example #1
0
        public string RunPythonScript(string script, string p1 = null, string p2 = null)
        {
            if (script.Contains("@BlueToolbarTagId"))
            {
                var id = Db.FetchLastQuery().Id;
                pythonModel.DictionaryAdd("BlueToolbarGuid", id.ToCode());
            }
            var request = HttpContextFactory.Current.Request;

            foreach (var key in request.QueryString.AllKeys)
            {
                pythonModel.DictionaryAdd(key, request.QueryString[key]);
            }
            if (p1.HasValue())
            {
                pythonModel.DictionaryAdd("p1", p1);
            }
            if (p2.HasValue())
            {
                pythonModel.DictionaryAdd("p2", p2);
            }
            pythonModel.Data.Title = ContributionsMenuTitle(script);
#if DEBUG
            if (runFromPath.HasValue())
            {
                return(PythonModel.ExecutePython(runFromPath, pythonModel, fromFile: true));
            }
#endif
            return(pythonModel.RunScript(script));
        }
Example #2
0
        public static string Run(string name, PythonModel pe)
        {
            var script = DbUtil.Db.ContentOfTypePythonScript(name);

            if (pe.Dictionary("p1") != null)
            {
                script = script.Replace("@P1", pe.Dictionary("p1") ?? "NULL");
            }


            string runfromPath = null;

#if DEBUG
            var runfromRe = new Regex(@"#runfrom=(?<path>.*)\r");
            if (Regex.IsMatch(name, @"test\d*\.py"))
            {
                runfromPath = HttpContext.Current.Server.MapPath($"~/{name}");
                script      = System.IO.File.ReadAllText(HttpContext.Current.Server.MapPath($"~/{name}"));
                var re1    = new Regex(@"#saveas=(?<saveas>.*)\r");
                var saveas = re1.Match(script).Groups["saveas"]?.Value;
                if (saveas.HasValue())
                {
                    SaveAsContent(saveas, script);
                }
            }
            else if (runfromRe.IsMatch(script))
            {
                runfromPath = runfromRe.Match(script).Groups["path"]?.Value;
                if (string.IsNullOrEmpty(runfromPath))
                {
                    throw new Exception($"no match for path");
                }

                script = System.IO.File.ReadAllText(runfromPath);
                SaveAsContent(name, script);
            }
            else
#endif

            if (!script.HasValue())
            {
                throw new Exception("no script named " + name);
            }

            pe.Data.Title = ContributionsMenuTitle(script);

#if DEBUG
            if (runfromPath.HasValue())
            {
                return(PythonModel.ExecutePython(runfromPath, pe, fromFile: true));
            }
#endif
            return(pe.RunScript(script));
        }
Example #3
0
        public void OnEnroll(OrganizationMember om)
        {
            if (!setting.OnEnrollScript.HasValue())
            {
                return;
            }
            var pe = new PythonModel(Util.Host);

            BuildDynamicData(pe, om);
#if DEBUG
            if (setting.OnEnrollScript == "debug")
            {
                ScriptResults =
                    PythonModel.ExecutePython(@"c:\dev\onregister.py", pe, fromFile: true);
                return;
            }
#endif
            var script = DbUtil.Db.ContentOfTypePythonScript(setting.OnEnrollScript);
            ScriptResults = PythonModel.ExecutePython(script, pe);
        }
Example #4
0
        public ActionResult TestScript()
        {
            //var id = DbUtil.Db.ScratchPadQuery(@"MemberStatusId = 10[Member] AND LastName = 'C*'");

            var    file    = Server.MapPath("~/test.py");
            var    logFile = $"RunPythonScriptInBackground.{DateTime.Now:yyyyMMddHHmmss}";
            string host    = Util.Host;

#if false
            HostingEnvironment.QueueBackgroundWorkItem(ct =>
            {
                var pe = new PythonModel(host);
                //pe.DictionaryAdd("OrgId", "89658");
                pe.DictionaryAdd("LogFile", logFile);
                PythonModel.ExecutePythonFile(file, pe);
            });
            return(View("RunPythonScriptProgress"));
#else
            var pe = new PythonModel(host);
            pe.DictionaryAdd("LogFile", logFile);
            ViewBag.Text = PythonModel.ExecutePython(file, pe, fromFile: true);
            return(View("Test"));
#endif
        }