Ejemplo n.º 1
0
        internal PythonWebScript(string filePath, Dictionary <string, string> arguemtents) : base(filePath, arguemtents)
        {
            WebServerManager = new WebServerManager(Path.GetDirectoryName(filePath));
            pythonEngine     = Python.CreateEngine();
            pythonScope      = pythonEngine.CreateScope();
            pythonRuntime    = pythonEngine.Runtime;
            ICollection <string> paths = pythonEngine.GetSearchPaths();

            paths.Add(ScriptProcessor.rootWebPageDirectory);
            pythonEngine.SetSearchPaths(paths);
            addObject(WebServerManager, "Server");
        }
Ejemplo n.º 2
0
        internal PythonWebScript() : base()
        {
            WebServerManager = new WebServerManager(Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory));
            pythonEngine     = Python.CreateEngine();
            pythonScope      = pythonEngine.CreateScope();
            pythonRuntime    = pythonEngine.Runtime;
            ICollection <string> paths = pythonEngine.GetSearchPaths();

            paths.Add(ScriptProcessor.rootWebPageDirectory);
            pythonEngine.SetSearchPaths(paths);
            addObject(WebServerManager, "Server");
        }
Ejemplo n.º 3
0
        public override ReturnType excuteScript(out string HTMLOutput)
        {
            //HTMLOutput = "";

            try
            {
                if (!compiled)
                {
                    compileScript();
                }

                TextWriter   tw = new StringWriter();
                MemoryStream ms = new MemoryStream();

                pythonRuntime.IO.SetOutput(ms, tw);

                var result = compiledScript.Execute(pythonScope);

                string errorCode, errorMessage, redirectURL;

                if (WebServerManager.isError(out errorCode, out errorMessage))
                {
                    HTMLOutput = "";
                    return(ReturnType.Error);
                }

                if (WebServerManager.isRedirecting(out redirectURL))
                {
                    HTMLOutput = "";
                    return(ReturnType.Redirect);
                }

                HTMLOutput = tw.ToString();
                return(ReturnType.HTML);
            }
            catch (Exception ex)
            {
                HTMLOutput = ex.Message;
                return(ReturnType.HTML);
            }
        }