Exemple #1
0
        public static string ShowHistory(string id = "", int num = 10)
        {
            Shell s = Shell.GetShell(id);

            if (s != null)
            {
                if (s.MainControl.Dispatcher.CheckAccess())
                {
                    ShellTextControl c = s.MainControl as ShellTextControl;
                    if (c != null)
                    {
                        ShellTextBox b = c.GetContents;
                        if (b != null)
                        {
                            return(b.GetHistory(num));
                        }
                    }
                }
                else
                {
                    return((string)s.MainControl.Dispatcher.Invoke(new Func <string>(() => { return ShowHistory(s.ShellId, num); })));
                }
            }
            return("Error: no history available.");
        }
 public static string HtmlCss(string id, string fileName = "")
 {
     if (!String.IsNullOrWhiteSpace(id))
     {
         Shell s = Shell.GetShell(id);
         if (s != null)
         {
             if (s.MainControl.Dispatcher.CheckAccess())
             {
                 ShellHtmlControl h = s.MainControl as ShellHtmlControl;
                 if (h == null)
                 {
                     return("Error: no html control.");
                 }
                 if (!String.IsNullOrWhiteSpace(fileName))
                 {
                     h.ShellCssFileName = fileName;
                 }
                 return(h.ShellCssFileName);
             }
             else
             {
                 return((string)s.MainControl.Dispatcher.Invoke(new Func <string>(()
                                                                                  => { return HtmlCss(s.ShellId, fileName); })));
             }
         }
     }
     return("");
 }
Exemple #3
0
 public static string PlotDataFile(string dataFileName)
 {
     if (!String.IsNullOrWhiteSpace(dataFileName))
     {
         string id = PlotControl.OpenPlotShell();
         Shell  s  = Shell.GetShell(id);
         if (s != null)
         {
             PlotControl p = s.MainControl as PlotControl;
             if (p != null)
             {
                 DataCache d      = new DataCache(dataFileName);
                 string    header = "";
                 d.LoadFromFile(dataFileName, out header);
                 p.NumPointsPerPlot = d.AbsoluteCount;
                 p.SetCache(d);
                 return(id);
             }
             s.Close();
             return("Error: unable to open plot control.");
         }
         return("Error: unable to open plot shell.");
     }
     return("Error: bad file name.");
 }
Exemple #4
0
        public static string SetCommandPrompt(string id = "", string prompt = null)
        {
            Shell s = Shell.GetShell(id);

            if (s != null)
            {
                if (s.MainControl.Dispatcher.CheckAccess())
                {
                    ShellTextControl c = s.MainControl as ShellTextControl;
                    if (c != null)
                    {
                        ShellTextBox b = c.GetContents;
                        if (b != null)
                        {
                            if (prompt == null)
                            {
                                return(b.GetPromptPrefix());
                            }
                            prompt = prompt.Trim();
                            b.SetPromptPrefix(prompt);
                            return("");
                        }
                    }
                }
                else
                {
                    return((string)s.MainControl.Dispatcher.Invoke(new Func <string>(() => { return SetCommandPrompt(s.ShellId, prompt); })));
                }
            }
            return("Error: could not access prompt.");
        }
Exemple #5
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("");
        }
Exemple #6
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("");
 }
Exemple #7
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("");
 }
Exemple #8
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("");
 }
Exemple #9
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("");
 }
Exemple #10
0
 public override void Init()
 {
     base.Init();
     ShellEngine = ScriptEngine.Create(Shell.GetShell(OwnerShellId));
     Clear();
     if (!String.IsNullOrWhiteSpace(ShellStartScriptName))
     {
         RunScript(OwnerShellId, ShellStartScriptName);
     }
     if (ParentXmlNode != null)
     {
         ShellEngine.Serializer(ParentXmlNode, false);
         ParentXmlNode = null;
     }
 }
Exemple #11
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("");
        }