Beispiel #1
0
        public static string ShowVars(string id = "", string pattern = "^.*")
        {
            Shell s = Shell.GetShell(id);

            if (s != null)
            {
                if (s.MainControl.Dispatcher.CheckAccess())
                {
                    if (s.MainControl is ScriptControl)
                    {
                        ScriptControl c = s.MainControl as ScriptControl;
                        if (c.ShellEngine != null)
                        {
                            return(c.ShellEngine.ListVars(pattern));
                        }
                        return("Error: no script engine.");
                    }
                }
                else
                {
                    return((string)s.MainControl.Dispatcher.Invoke(new Func <string>(()
                                                                                     => { return ShowVars(s.ShellId, pattern); })));
                }
            }
            return("");
        }
Beispiel #2
0
 public static string TaskState(string id, string taskId = "*", string state = "")
 {
     if (!String.IsNullOrWhiteSpace(id))
     {
         if (String.IsNullOrWhiteSpace(taskId))
         {
             taskId = "*";
         }
         Shell s = Shell.GetShell(id);
         if (s != null)
         {
             if (s.MainControl.Dispatcher.CheckAccess())
             {
                 if (s.MainControl is ScriptControl)
                 {
                     ScriptControl c = s.MainControl as ScriptControl;
                     if (c.ShellEngine != null)
                     {
                         return(c.ShellEngine.TaskState(taskId, state));
                     }
                     return("Error: no script engine.");
                 }
             }
             else
             {
                 return((string)s.MainControl.Dispatcher.Invoke(new Func <string>(()
                                                                                  => { return TaskState(s.ShellId, taskId, state); })));
             }
         }
     }
     return("");
 }
Beispiel #3
0
 public static string Schedule(string id, string script, string when, Int32 delay)
 {
     if (!String.IsNullOrWhiteSpace(id) && !String.IsNullOrWhiteSpace(script))
     {
         Shell s = Shell.GetShell(id);
         if (s != null)
         {
             if (s.MainControl.Dispatcher.CheckAccess())
             {
                 if (s.MainControl is ScriptControl)
                 {
                     ScriptControl c = s.MainControl as ScriptControl;
                     if (c.ShellEngine != null)
                     {
                         c.ShellEngine.ScheduleTask(script, when, delay);
                     }
                     else
                     {
                         return("Error: no script engine.");
                     }
                 }
             }
             else
             {
                 s.MainControl.Dispatcher.Invoke((Action)(()
                                                          => { Schedule(s.ShellId, script, when, delay); }));
             }
         }
     }
     return("");
 }
Beispiel #4
0
 public static string Break(string id)
 {
     if (!String.IsNullOrWhiteSpace(id))
     {
         Shell s = Shell.GetShell(id);
         if (s != null)
         {
             if (s.MainControl.Dispatcher.CheckAccess())
             {
                 if (s.MainControl is ScriptControl)
                 {
                     ScriptControl c = s.MainControl as ScriptControl;
                     if (c.ShellEngine != null)
                     {
                         c.ShellEngine.BreakEngine();
                     }
                 }
             }
             else
             {
                 s.MainControl.Dispatcher.Invoke((Action)(() => { Break(s.ShellId); }));
             }
         }
     }
     return("");
 }
Beispiel #5
0
 public static string RunScript(string id, string script, bool showCmd = false)
 {
     if (!String.IsNullOrWhiteSpace(id) && !String.IsNullOrWhiteSpace(script))
     {
         Shell s = Shell.GetShell(id);
         if (s != null)
         {
             if (s.MainControl.Dispatcher.CheckAccess())
             {
                 if (s.MainControl is ScriptControl)
                 {
                     ScriptControl c = s.MainControl as ScriptControl;
                     if (c.ShellEngine != null)
                     {
                         c.ShellEngine.PerformCommand(script, showCmd);
                     }
                 }
             }
             else
             {
                 s.MainControl.Dispatcher.Invoke((Action)(() => { RunScript(s.ShellId, script, showCmd); }));
             }
         }
     }
     return("");
 }
Beispiel #6
0
        public static string Process(string id, string action = "*")
        {
            if (!String.IsNullOrWhiteSpace(id))
            {
                Shell s = Shell.GetShell(id);
                if (s != null)
                {
                    if (String.IsNullOrWhiteSpace(action))
                    {
                        action = "*";
                    }
                    if (s.MainControl.Dispatcher.CheckAccess())
                    {
                        ScriptEngine.ProcessAction p = ScriptEngine.ProcessAction.None;
                        switch (action.ToUpper()[0])
                        {
                        case 'B': p = ScriptEngine.ProcessAction.Break; break;

                        case 'C': p = ScriptEngine.ProcessAction.Continue; break;

                        case 'P': p = ScriptEngine.ProcessAction.Pause; break;

                        case 'S': p = ScriptEngine.ProcessAction.Stop; break;

                        default: break;
                        }
                        if (s.MainControl is ScriptControl)
                        {
                            ScriptControl c = s.MainControl as ScriptControl;
                            if (c.ShellEngine != null)
                            {
                                return(c.ShellEngine.ApplyProcessAction(p));
                            }
                        }
                        return("Error: no script engine.");
                    }
                    else
                    {
                        return(s.MainControl.Dispatcher.Invoke(new Func <string>(()
                                                                                 => { return Process(s.ShellId, action); })));
                    }
                }
            }
            return("");
        }
Beispiel #7
0
 protected void Shell_OnKeyUp(Object sender, KeyEventArgs e)
 {
     if (e.Key == Key.Return)
     {
         bool   isAtEndOfLine = false;
         string command       = GetEnterCommand(out isAtEndOfLine);
         ScriptControl.RunScript(OwnerShellId, command, !isAtEndOfLine);
     }
     else if (e.Key == Key.C)
     {
         if (e.KeyboardDevice.IsKeyDown(Key.LeftCtrl) ||
             e.KeyboardDevice.IsKeyDown(Key.RightCtrl)
             )
         {
             ScriptControl.Break(OwnerShellId);
         }
     }
 }