public ActionResult PyScriptForm(string name) { try { var script = FetchPyScriptForm(name); if (!script.HasValue()) { return(Message("no script named " + name)); } var pe = new PythonModel(Util.Host); foreach (var key in Request.QueryString.AllKeys) { pe.DictionaryAdd(key, Request.QueryString[key]); } pe.Data.pyscript = name; pe.HttpMethod = "get"; pe.RunScript(script); return(View(pe)); } catch (Exception ex) { return(RedirectShowError(ex.Message)); } }
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(Guid id, string report) { var content = DbUtil.Db.ContentOfTypePythonScript(report); if (content == null) { return(Content("no script named " + report)); } if (!CanRunScript(content)) { return(Message("Not Authorized to run this script")); } if (!content.Contains("BlueToolbarReport") && !content.Contains("@BlueToolbarTagId")) { return(Content("Missing Call to Query Function 'BlueToolbarReport'")); } if (id == Guid.Empty) { return(Content("Must be run from the BlueToolbar")); } var pe = new PythonModel(Util.Host); pe.DictionaryAdd("BlueToolbarGuid", id.ToCode()); foreach (var key in Request.QueryString.AllKeys) { pe.DictionaryAdd(key, Request.QueryString[key]); } pe.RunScript(content); return(View(pe)); }
public void DocusignApiTest() { var model = new PythonModel(db); var result = model.RunScript(Resources.DocusignApiTest); result.TrimEnd().ShouldBe("[False, False, False, False, False, False, False, False, False, False, False, False, False, False, False]"); }
public void RunPyScript() { var content = CurrentDatabase.ContentOfTypePythonScript(Report); if (content == null) { throw new Exception("no script named " + Report); } if (!CanRunScript(content)) { throw new Exception("Not Authorized to run this script"); } if (!content.Contains("BlueToolbarReport") && !content.Contains("@BlueToolbarTagId")) { throw new Exception("Missing Call to Query Function 'BlueToolbarReport'"); } if (Id == Guid.Empty) { throw new Exception("Must be run from the BlueToolbar"); } var pe = new PythonModel(CurrentDatabase.Host); pe.DictionaryAdd("BlueToolbarGuid", Id.ToCode()); foreach (var key in HttpContextFactory.Current.Request.QueryString.AllKeys) { pe.DictionaryAdd(key, HttpContextFactory.Current.Request.QueryString[key]); } pe.RunScript(content); Results = pe.Output; }
public void ShouldRunPythonScriptFromString(string script) { var pe = new PythonModel(CMSDataContext.Create(DatabaseFixture.Host)); var result = pe.RunScript(script); result.ShouldNotBeNull(); }
public ActionResult TestScript() { //var id = DbUtil.Db.ScratchPadQuery(@"MemberStatusId = 10[Member] AND LastName = 'C*'"); var text = System.IO.File.ReadAllText(Server.MapPath("~/test.py")); ViewBag.Text = PythonModel.RunScript(Util.Host, text); return(View("Test")); }
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)); }
public ActionResult Test(int?id) { var script = System.IO.File.ReadAllText(Server.MapPath($"~/test{id}.py")); if (!CanRunScript(script)) { return(Message("Not Authorized to run this script")); } ViewBag.text = PythonModel.RunScript(Util.Host, script); return(View()); }
public ActionResult Script(string id) { try { var script = CurrentDatabase.Content(id); PythonModel.RunScript(CurrentDatabase.Host, script.Body); } catch (Exception e) { return(Content(e.Message)); } return(Content("done")); }
public ActionResult Script(string id) { try { var script = DbUtil.Db.Content(id); PythonModel.RunScript(Util.Host, script.Body); } catch (Exception e) { return(Content(e.Message)); } return(Content("done")); }
public ActionResult PyScript(string name, string p1, string p2, string v1, string v2) { try { var script = DbUtil.Db.ContentOfTypePythonScript(name); if (!script.HasValue()) { return(Message("no script named " + name)); } if (!CanRunScript(script)) { return(Message("Not Authorized to run this script")); } if (script.Contains("model.Form")) { 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 = DbUtil.Db.FetchLastQuery().Id; var tag = DbUtil.Db.PopulateSpecialTag(id, DbUtil.TagTypeId_Query); script = script.Replace("@qtagid", tag.Id.ToString()); } var pe = new PythonModel(Util.Host); if (script.Contains("@BlueToolbarTagId")) { var id = DbUtil.Db.FetchLastQuery().Id; pe.DictionaryAdd("BlueToolbarGuid", id.ToCode()); } foreach (var key in Request.QueryString.AllKeys) { pe.DictionaryAdd(key, Request.QueryString[key]); } pe.RunScript(script); ViewBag.report = name; ViewBag.url = Request.Url?.PathAndQuery; return(View(pe)); } catch (Exception ex) { return(RedirectShowError(ex.Message)); } }
public ActionResult VitalStats() { var script = DbUtil.Db.ContentOfTypePythonScript("VitalStats"); if (!script.HasValue()) { script = System.IO.File.ReadAllText(Server.MapPath("/Content/VitalStats.py")); } ViewBag.table = script.Contains("class VitalStats") ? QueryFunctions.OldVitalStats(DbUtil.Db, script) : PythonModel.RunScript(DbUtil.Db.Host, script); return(View()); }
private static void Do(string script) { var dbname = ConfigurationManager.AppSettings["Host"]; var db = CMSDataContext.Create(dbname); db.FromBatch = true; var m = new PythonModel(db); if (File.Exists(script)) { Console.WriteLine(m.RunScriptFile(script)); } else { var s = script; Console.WriteLine(m.RunScript(s)); } }
public ActionResult PyScriptForm() { try { var pe = new PythonModel(Util.Host); foreach (var key in Request.Form.AllKeys) { pe.DictionaryAdd(key, Request.Form[key]); } pe.HttpMethod = "post"; var script = DbUtil.Db.ContentOfTypePythonScript(pe.Data.pyscript); return(Content(pe.RunScript(script))); } catch (Exception ex) { return(RedirectShowError(ex.Message)); } }
public ActionResult VitalStats() { if (Util2.OrgLeadersOnly) { return(Redirect("/Home")); } var script = CurrentDatabase.ContentOfTypePythonScript("VitalStats"); if (!script.HasValue()) { script = System.IO.File.ReadAllText(Server.MapPath("/Content/VitalStats.py")); } ViewBag.table = script.Contains("class VitalStats") ? QueryFunctions.OldVitalStats(CurrentDatabase, script) : PythonModel.RunScript(CurrentDatabase.Host, script); return(View()); }
public bool TryRunPython(int pid) { var ev = Organization.GetExtra(DbUtil.Db, OrgId, "OrgMembersPageScript"); if (!ev.HasValue()) { return(false); } var script = DbUtil.Db.ContentOfTypePythonScript(ev); if (!script.HasValue()) { return(false); } var pe = new PythonModel(Util.Host); pe.Data.OrgId = OrgId; pe.Data.PeopleId = pid; Results = pe.RunScript(script); return(true); }
private string RunScript() { if (person == null) { return(GetNoPersonMessage()); } var m = new PythonModel(CurrentDatabase); var script = CurrentDatabase.ContentOfTypePythonScript(action.ScriptName); if (!script.HasValue()) { return(GetError($"Script name {action.ScriptName} not found")); } m.DictionaryAdd("ToNumber", To); m.DictionaryAdd("ToGroupId", row.ToGroupId); m.DictionaryAdd("FromNumber", From); m.DictionaryAdd("Message", Body); m.DictionaryAdd("PeopleId", row.FromPeopleId); m.DictionaryAdd("Name", person.Name); m.DictionaryAdd("First", person.FirstName); m.DictionaryAdd("Last", person.LastName); var msg = Util.PickFirst( m.RunScript(script).Trim(), action.ReplyMessage, action.DefaultMessage); row.ActionResponse = DoReplacments(msg); CurrentDatabase.SmsReceiveds.InsertOnSubmit(row); CurrentDatabase.SubmitChanges(); SendNotices(); if (msg.Equal("NONE")) { return(String.Empty); } return(row.ActionResponse); }
public ActionResult TestScript() { var text = System.IO.File.ReadAllText(Server.MapPath("ttt.py")); return(Content(PythonModel.RunScript(Util.Host, text))); }
public ActionResult TestScript(string script) { return(Content(PythonModel.RunScript(Util.Host, script))); }
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 }