public static void d(string shellId, String tag, String message) { if (shellId != null && !String.IsNullOrWhiteSpace(message)) { Shell.Write(shellId, "Debug " + tag + "." + message); } }
public static void w(String tag, String message) { if (!String.IsNullOrWhiteSpace(message)) { Shell.Write(Shell.LogShellId, "Warning " + tag + "." + message); } }
public override void WriteLine(string message) { if (IsTracing && !String.IsNullOrWhiteSpace(message)) { Shell.Write(Shell.LogShellId, "Trace " + message); } }
public void PerformCommand(string cmd, bool showCmd) { if (!String.IsNullOrWhiteSpace(cmd)) { if (ScriptFilteringEnabled) { cmd = ScriptFilter.Filter(this, cmd); } if (!String.IsNullOrWhiteSpace(cmd)) { if (!cmd.EndsWith("\n")) { cmd += "\n"; } if (showCmd) { Shell.Write(ParentShell.ShellId, cmd, true, false); } if (cmd.Equals("break\n") || cmd.StartsWith("break;")) { BreakEngine(); } else if (cmd.Equals("continue\n") || cmd.StartsWith("continue;")) { IsPaused = false; } else { ScriptQueue.Add(cmd); } string state = IsPaused ? "Paused: type 'continue;' to run." : "Running."; MainWindow.UpdateStatus("Shell#" + ParentShell.ShellId, state); } } }
private void ScriptProcessor() { ThreadScriptEngine = this; object v; string s, r; while (!IsClosing) { try { if (IsPaused) { Thread.Sleep(200); } else { s = ScriptQueue.Take();//ParentShell.Interrupter.GetToken); // Ignore interrupt here, Close will stop Q. if ((s != null) && (s.Length > 0)) { r = null; IsRunning = true; try { this.Global.ErrorStack.Clear(); //this.SetDebugMode(true); v = this.Run(s); if (v != null) { r = v.ToString(); } } catch (Exception e) { r = "Error in script:\n" + GetLine(s) + "\n"; s = e.Message; r += s + "\n"; foreach (string m in this.Global.ErrorStack) { if (!s.StartsWith(m)) { r += m + "\n"; } } } IsRunning = false; if ((r != null) && (r.Length > 0)) { Shell.Write(ParentShell.ShellId, r, false, true); // TODO: set params properly. } } } // } catch(OperationCanceledException) { // This is generated when Take is interrupted prior to closing. // //IsClosing = true; // break; } catch (Exception e) { Shell.WriteLine(e.Message); // TODO: writes to console. } } }
// This will keep setting Jint's exit flag to true causing it to exit. // Leaves it in a Paused state. public void BreakPoller() { // ReturnStatement statement = new ReturnStatement((Expression)null); int count = 0; do { BreakEvent.WaitOne(); while (IsRunning) { if (count > 5) { count = 0; Shell.Write("Attempting to interrupt shell..."); EngineThread.Interrupt(); ConditionVariable.Interrupt(EngineThread); } Shell.Write("Attempting (" + count++ + ") to pause shell..."); Visitor.ForceBreak(); Thread.Sleep(1000); } } while (!IsClosing); }