public static void Execute(HttpExchange ex) { string rawCode = File.ReadAllText(ex.requestedResource); CodeExecuter ce = new CodeExecuter(ex, rawCode); currentProcessor = ce; Exception e; if (!ce.Process(out e)) { ex.ProcessResponse(ErrorFormatter.FormatServerError(500, "Internal Server Error", "The LWASP Server had a problem while processing " + ex.requestedResource + ".<br/>Message: " + e.Message)); } else { object o; string[] output = ce.Execute(out o); if (output == null) // TODO complete this code { if (o is CompilerErrorCollection) // Compilation error { string errorCollection = ""; foreach (CompilerError er in (CompilerErrorCollection)o) { errorCollection += ErrorFormatter.FormatCompilerError(er, ce.FinalCode) + "<br/>"; } ex.ProcessResponse(errorCollection); } else if (o is Exception) // Runtime error { if (((Exception)o).Message == "LWASP Error") { ex.oWrite("<h1>500 Internal Server Error</h1><br/>Server error message was: " + e.Message); ex.oClose(); } else { ex.ProcessResponse(ErrorFormatter.FormatException((Exception)o, ce.FinalCode)); } } } else { string fCode = ce.BaseCode; for (int i = 0; i < output.Length; i++) { fCode = fCode.ReplaceFirst("{LWASP_CODE_SEGMENT_" + i + "_}", output[i]); } currentProcessor.connection.ProcessResponse(fCode.Trim()); } } }
private void button2_Click(object sender, EventArgs e) { if (!isActivated) { Thread wsThread = new Thread(WebScriptManager.RunExecutionQueue); wsThread.IsBackground = true; wsThread.Start(); Thread servThread = new Thread(() => { HttpExchange.Run(); }); servThread.IsBackground = true; servThread.Start(); serverThread = servThread; try { IDEServer = new SimpleWebServer.WebServer(Utils.HandleIDE, "http://localhost:" + ConfigurationManager.SETTINGS["IDE_PORT"] + "/"); IDEServer.Run(); } catch { MessageBox.Show("Failed to initialize IDE server!"); } isActivated = true; button2.Text = "Stop server"; } else { try { IDEServer.Stop(); } catch { MessageBox.Show("Failed to stop IDE server!"); } WebScriptManager.StopExecutionQueue(); try { HttpExchange._server.Close(); serverThread.Abort(); serverThread.Interrupt(); } catch { MessageBox.Show("LWASP was unable to stop the server!\r\nPlease try again or restart LWASP"); } isActivated = false; button2.Text = "Start server"; } }
public CodeExecuter(HttpExchange conn, string code = "") { connection = conn; BaseCode = code; }
public static void Enqueue(HttpExchange hx) { ExecutionQueue.Enqueue(hx); }