コード例 #1
0
        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 = CurrentDatabase.ContentOfTypePythonScript(pe.Data.pyscript);
                return(Content(pe.RunScript(script)));
            }
            catch (Exception ex)
            {
                return(RedirectShowError(ex.Message));
            }
        }
コード例 #2
0
        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());
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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
        }