Beispiel #1
0
        public override void ProcessRequest(GusServerRequest Request)
        {
            string file = defaultFile;

            if (Request.GetVariables.ContainsKey("file"))
            {
                file = System.IO.Path.GetFileNameWithoutExtension(Request.GetVariables["file"]) + ".gsc";
            }

            string path = System.IO.Path.Combine(physicalPath, file);

            if (!File.Exists(path))
            {
                Request.WriteNotFoundResponse();
                return;
            }

            dynamic  script       = null;
            Assembly asm          = null;
            string   error        = "";
            string   compiledcode = "";
            string   sharedcode   = "";

            try
            {
                FileInfo fi = new FileInfo(path);

                if (!onMemoryScripts.ContainsKey(path) || onMemoryScripts[path].CodeDate != fi.LastWriteTime)
                {
                    string code = File.ReadAllText(path);
                    GusScripting.GusScriptParser parser = new GusScripting.GusScriptParser();
                    asm          = parser.CreateScriptObject(code, System.IO.Path.GetDirectoryName(path), debug);
                    error        = parser.ErrorMsg;
                    compiledcode = parser.CompiledCode.ExecutionCode;
                    sharedcode   = parser.CompiledCode.SharedCode;

                    if (asm != null)
                    {
                        onMemoryScripts[path] = new CompiledAssemblyInfo {
                            Assmebly = asm, CodeDate = fi.LastWriteTime
                        }
                    }
                    ;
                }
                else
                {
                    asm = onMemoryScripts[path].Assmebly;
                }
            }
            catch { }

            if (asm == null)
            {
                if (debug)
                {
                    Request.Processor.WriteResponseCode("500");

                    if (!string.IsNullOrEmpty(error) && debug)
                    {
                        Request.ResponseStream.WriteText(@"<html><body><h1>HTTP Error 500 - Internal server error</h1><div><p>GusScript compilation error</p></div><h2>Errors</h2><div><p>" + error.Replace("\r\n", "<br />") + "</p></div><h2>Compiled code</h2><div><p>" + compiledcode.Replace("<", "&lt;").Replace(">", "&gt;").Replace(" ", "&nbsp;").Replace("\r\n", "<br />") + "</p><p>" + sharedcode.Replace("<", "&lt;").Replace(">", "&gt;").Replace(" ", "&nbsp;").Replace("\r\n", "<br />") + "</p></div></body></html>");
                    }
                }
                else
                {
                    Request.Processor.WriteError();
                }

                return;
            }

            try
            {
                script = asm.CreateInstance("GusNet.GusScripting.CompiledGusScript");

                script.Execute(Request);
            }
            catch (Exception Ex)
            {
                try
                {
                    Request.ResponseStream.WriteText("<div style=\"background-color:#FFCC00; padding:10px\"><b>Execution error</b><br /><br />" + Ex.Message + " &lt;-&gt; " + Ex.StackTrace + "</div>");
                }
                catch { }
            }
        }
Beispiel #2
0
        public override void ProcessRequest(GusServerRequest Request)
        {
            if (Request.Method.ToLower() != "post")
            {
                return;
            }

            if (Request.PostVariables == null)
            {
                return;
            }

            if (Request.PostVariables.ContainsKey("compile") && Request.PostVariables.ContainsKey("code"))
            {
                string file = Request.PostVariables["compile"];
                string code = Request.PostVariables["code"];

                GusScripting.GusScriptParser parser = new GusScripting.GusScriptParser();
                Assembly asm          = parser.CreateScriptObject(code, "", true);
                string   error        = parser.ErrorMsg;
                string   compiledcode = parser.CompiledCode.ExecutionCode;
                string   sharedcode   = parser.CompiledCode.SharedCode;

                if (asm != null)
                {
                    onMemoryScripts.Add(file, asm);
                }

                if (!string.IsNullOrEmpty(error))
                {
                    Request.Processor.WriteResponseCode("500");
                    Request.ResponseStream.WriteText(@"<html><body><h1>HTTP Error 500 - Internal server error</h1><div><p>GusScript compilation error</p></div><h2>Errors</h2><div><p>" + error.Replace("\r\n", "<br />") + "</p></div><h2>Compiled code</h2><div><p>" + compiledcode.Replace("<", "&lt;").Replace(">", "&gt;").Replace(" ", "&nbsp;").Replace("\r\n", "<br />") + "</p><p>" + sharedcode.Replace("<", "&lt;").Replace(">", "&gt;").Replace(" ", "&nbsp;").Replace("\r\n", "<br />") + "</p></div></body></html>");
                    return;
                }
                else
                {
                    Request.WriteOkResponse();
                    Request.ResponseStream.WriteText(@"<html><body><h1>Code compiled for file " + file + "</h1><div><p>" + compiledcode.Replace("<", "&lt;").Replace(">", "&gt;").Replace(" ", "&nbsp;").Replace("\r\n", "<br />") + "</p><p>" + sharedcode.Replace("<", "&lt;").Replace(">", "&gt;").Replace(" ", "&nbsp;").Replace("\r\n", "<br />") + "</p></div></body></html>");
                    return;
                }
            }

            Assembly asmm;

            try
            {
                if (!onMemoryScripts.ContainsKey(path))
                {
                    Request.WriteNotFoundResponse();
                    return;
                }
                else
                {
                    asmm = onMemoryScripts[path];
                }
            }
            catch
            {
                Request.WriteNotFoundResponse();
                return;
            }

            try
            {
                dynamic script = asmm.CreateInstance("GusScripting.CompiledGusScript");

                script.Execute(Request);
            }
            catch (Exception Ex)
            {
                try
                {
                    Request.ResponseStream.WriteText("<div style=\"background-color:#FFCC00; padding:10px\"><b>Execution error</b><br /><br />" + Ex.Message + "</div>");
                }
                catch { }
            }
        }