示例#1
0
 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);
         }
     }
 }
示例#2
0
        public static string LoadScript(ScriptEngine se, String scriptName, ArrayList args)
        {
            string result = ""; int lineNum = 0;
            string filePath = GetScriptFilePath(scriptName);

            if (String.IsNullOrWhiteSpace(filePath))
            {
                return("Error: script name not found: try updating script cache.");
            }
            ArrayList ary = new ArrayList();

            ary.Add(EscapeStringLiteral(filePath));
            foreach (string s in args)
            {
                ary.Add(EscapeStringLiteral(s));
            }
            try {
                StreamReader   sr = new StreamReader(filePath);
                StringSplitter ss = new StringSplitter(Scripts.IsValidName);
                string         s, r;
                while ((s = sr.ReadLine()) != null)
                {
                    s = StripComments(s);
                    if (s != null)
                    {
                        try {
                            ++lineNum;
                            r = SubVars(s, ary);
                            if (se.GetScriptFilteringEnabled())
                            {
                                result += ScriptFilter.Filter(se, ss, r);
                            }
                            else
                            {
                                result += r;
                            }
                            result += "\n";
                        } catch (Exception e) {
                            result = "Error: filtering script " + scriptName + " line:" + lineNum + ":" + s + "\n"
                                     + "Exception:" + e.Message;
                        }
                    }
                }
                sr.Close();
                sr = null;
            } catch (Exception e) {
                result = "Error: loading script " + scriptName + " from " + filePath + "\n"
                         + "Exception:" + e.Message;
            }
            return(result);
        }