Example #1
0
 private void buttonRunScript_Click(object sender, EventArgs e)
 {
     ExecuteScriptEventArgs args = new ExecuteScriptEventArgs { Script = textBoxSript.Text };
     OnScriptReady(args);
     this.Close();
     
 }
Example #2
0
 protected virtual void OnScriptReady(ExecuteScriptEventArgs e)
 {
     ExecuteScriptEventHandler handler = ScriptReady;
     if (handler != null)
     {
         handler(this, e);
     }
 }
Example #3
0
        private void buttonRunScript_Click(object sender, EventArgs e)
        {
            ExecuteScriptEventArgs args = new ExecuteScriptEventArgs {
                Script = textBoxSript.Text
            };

            OnScriptReady(args);
            this.Close();
        }
Example #4
0
        protected virtual void OnScriptReady(ExecuteScriptEventArgs e)
        {
            ExecuteScriptEventHandler handler = ScriptReady;

            if (handler != null)
            {
                handler(this, e);
            }
        }
Example #5
0
 /// <summary>Execute a SPSL script Async</summary>
 /// <param name="scriptArgs">A <seealso cref="ExecuteScriptEventArgs"/> object containing the script to execute and parameters</param>
 public static void BeginExecuteScript(ExecuteScriptEventArgs scriptArgs)
 {
     string[] scriptlines = scriptArgs.Script.Split('\n');
     if (scriptlines.Length > 0
         && scriptArgs.IsSPSL)
     {
         new System.Threading.Thread(delegate ()
         {
             foreach (string line in scriptlines)
             {
                 CommandData command;
                 TryParseScriptLine(line, out command);
                 if (command != null)
                 {
                     command.SendToTerminal(scriptArgs.Handle.ToInt32());                        
                 }
             }
         }).Start();
     }
 }
Example #6
0
        /// <summary>Open a new putty window with its settings being passed in a <seealso cref="SessionData"/> object</summary>
        /// <param name="session">The <seealso cref="SessionData"/> object containing the settings</param>
        public static ctlPuttyPanel OpenPuttySession(SessionData session)
        {
            Log.InfoFormat("Opening putty session, id={0}", session == null ? "" : session.SessionId);
            ctlPuttyPanel panel = null;
            if (session != null)
            {
                // This is the callback fired when the panel containing the terminal is closed
                // We use this to save the last docking location and to close the panel
                PuttyClosedCallback callback = delegate
                {
                    if (panel != null)
                    {
                        // save the last dockstate (if it has been changed)
                        if (session.LastDockstate != panel.DockState
                            && panel.DockState != DockState.Unknown
                            && panel.DockState != DockState.Hidden)
                        {
                            session.LastDockstate = panel.DockState;
                            SuperPuTTY.SaveSessions();
                        }

                        if (panel.InvokeRequired)
                        {
                            panel.BeginInvoke((MethodInvoker)delegate {
                                panel.Close();
                            });
                        }
                        else
                        {
                            panel.Close();
                        }
                    }
                };

                try {
                    panel = new ctlPuttyPanel(session, callback);

                    ApplyDockRestrictions(panel);
                    ApplyIconForWindow(panel, session);
                    panel.Show(MainForm.DockPanel, session.LastDockstate);
                    ReportStatus("Opened session: {0} [{1}]", session.SessionId, session.Proto);

                    if (!String.IsNullOrEmpty(session.SPSLFileName)
                        && File.Exists(session.SPSLFileName))
                    {
                        ExecuteScriptEventArgs scriptArgs = new ExecuteScriptEventArgs() { Script = File.ReadAllText(session.SPSLFileName), Handle = panel.AppPanel.AppWindowHandle };
                        if (!String.IsNullOrEmpty(scriptArgs.Script))
                        {
                            SPSL.BeginExecuteScript(scriptArgs);
                        }
                    }
                } catch (InvalidOperationException ex)
                {
                    MessageBox.Show("Error trying to create session " + ex.Message, "Failed to create session panel", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            return panel;
        }
Example #7
0
 /// <summary>Process the script.</summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void Editor_ScriptReady(object sender, ExecuteScriptEventArgs e)
 {
     if(!String.IsNullOrEmpty(e.Script))
     {
         string[] script = e.Script.Split('\n');
         foreach (string line in script)
         {
             TrySendCommandsFromToolbar(new CommandData(line.TrimEnd()), !this.tbBtnMaskText.Checked);
         }
     }
 }
Example #8
0
 /// <summary>Process the script.</summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void Editor_ScriptReady(object sender, ExecuteScriptEventArgs e)
 {            
     if (!String.IsNullOrEmpty(e.Script))
     {
         string[] scriptlines = e.Script.Split('\n');
         if (scriptlines.Length > 0 
             && e.IsSPSL)
         {
             new Thread(delegate()
             {
                 foreach (string line in scriptlines)
                 {
                     CommandData command;                                                                                    
                     SPSL.TryParseScriptLine(line, out command);
                     if (command != null)
                     {
                         TrySendCommandsFromToolbar(command, false);
                     }
                 }
             }).Start();
         }
         else // Not a spsl script
         {
             foreach (string line in scriptlines)
             {
                 TrySendCommandsFromToolbar(new CommandData(line.TrimEnd('\n'), new KeyEventArgs(Keys.Enter)), !this.tbBtnMaskText.Checked);
             }
         }
     }
 }
Example #9
0
        /// <summary>Open a new putty window with its settings being passed in a <seealso cref="SessionData"/> object</summary>
        /// <param name="session">The <seealso cref="SessionData"/> object containing the settings</param>
        public static ctlPuttyPanel OpenProtoSession(SessionData session)
        {
            Log.InfoFormat("Opening putty session, id={0}", session == null ? "" : session.SessionId);
            ctlPuttyPanel panel = null;

            if (session != null)
            {
                String Executable = PuttyStartInfo.GetExecutable(session);
                if (String.IsNullOrEmpty(Executable))
                {
                    MessageBox.Show("Error trying to create session: " + session.ToString() +
                                    "\nExecutable not set for " + session.Proto.ToString() + " protocol." +
                                    "\nGo to tools->options->General tab to set the path to the executable."
                                    , "Failed to create a session", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(null);
                }
                if (!File.Exists(Executable))
                {
                    MessageBox.Show("Error trying to create session: " + session.ToString() +
                                    "\nExecutable not found for " + session.Proto.ToString() + " protocol." +
                                    "\nThe path for the executable was set as \"" + Executable + "\"." +
                                    "\nGo to tools->options->General tab to set the path to the executable."
                                    , "Failed to create a session", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(null);
                }

                // This is the callback fired when the panel containing the terminal is closed
                // We use this to save the last docking location and to close the panel
                PuttyClosedCallback callback = delegate
                {
                    if (panel != null)
                    {
                        // save the last dockstate (if it has been changed)
                        if (session.LastDockstate != panel.DockState &&
                            panel.DockState != DockState.Unknown &&
                            panel.DockState != DockState.Hidden)
                        {
                            session.LastDockstate = panel.DockState;
                            SuperPuTTY.SaveSessions();
                        }

                        if (panel.InvokeRequired)
                        {
                            panel.BeginInvoke((MethodInvoker) delegate {
                                panel.Close();
                            });
                        }
                        else
                        {
                            panel.Close();
                        }
                    }
                };

                try {
                    panel = new ctlPuttyPanel(session, callback);

                    ApplyDockRestrictions(panel);
                    ApplyIconForWindow(panel, session);
                    panel.Show(MainForm.DockPanel, session.LastDockstate);
                    ReportStatus("Opened session: {0} [{1}]", session.SessionId, session.Proto);

                    if (!String.IsNullOrEmpty(session.SPSLFileName) &&
                        File.Exists(session.SPSLFileName))
                    {
                        ExecuteScriptEventArgs scriptArgs = new ExecuteScriptEventArgs()
                        {
                            Script = File.ReadAllText(session.SPSLFileName), Handle = panel.AppPanel.AppWindowHandle
                        };
                        if (!String.IsNullOrEmpty(scriptArgs.Script))
                        {
                            SPSL.BeginExecuteScript(scriptArgs);
                        }
                    }
                } catch (InvalidOperationException ex)
                {
                    MessageBox.Show("Error trying to create session " + ex.Message, "Failed to create session panel", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            return(panel);
        }
Example #10
0
        /// <summary>Open a new putty window with its settings being passed in a <seealso cref="SessionData"/> object</summary>
        /// <param name="session">The <seealso cref="SessionData"/> object containing the settings</param>
        public static ctlPuttyPanel OpenProtoSession(SessionData session)
        {
            Log.InfoFormat("Opening putty session, id={0}", session == null ? "" : session.SessionId);
            ctlPuttyPanel panel = null;

            if (session != null)
            {
                String Executable = PuttyStartInfo.GetExecutable(session);
                if (String.IsNullOrEmpty(Executable))
                {
                    MessageBox.Show("Error trying to create session: " + session.ToString() +
                                    "\nExecutable not set for " + session.Proto.ToString() + " protocol." +
                                    "\nGo to tools->options->General tab to set the path to the executable."
                                    , "Failed to create a session", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(null);
                }
                if (!File.Exists(Executable))
                {
                    MessageBox.Show("Error trying to create session: " + session.ToString() +
                                    "\nExecutable not found for " + session.Proto.ToString() + " protocol." +
                                    "\nThe path for the executable was set as \"" + Executable + "\"." +
                                    "\nGo to tools->options->General tab to set the path to the executable."
                                    , "Failed to create a session", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(null);
                }

                // This is the callback fired when the panel containing the terminal is closed
                // We use this to save the last docking location and to close the panel
                PuttyClosedCallback callback = delegate
                {
                    if (panel != null)
                    {
                        // save the last dockstate (if it has been changed)
                        if (session.LastDockstate != panel.DockState &&
                            panel.DockState != DockState.Unknown &&
                            panel.DockState != DockState.Hidden)
                        {
                            session.LastDockstate = panel.DockState;
                            SuperPuTTY.SaveSessions();
                        }

                        if (panel.InvokeRequired)
                        {
                            panel.BeginInvoke((MethodInvoker) delegate {
                                panel.Close();
                            });
                        }
                        else
                        {
                            panel.Close();
                        }
                    }
                };

                try {
                    panel = new ctlPuttyPanel(session, callback);

                    ApplyDockRestrictions(panel);
                    ApplyIconForWindow(panel, session);
                    panel.Show(MainForm.DockPanel, session.LastDockstate);
                    ReportStatus("Opened session: {0} [{1}]", session.SessionId, session.Proto);

                    if (!String.IsNullOrWhiteSpace(session.SPSLFileName))
                    {
                        String fileName = session.SPSLFileName;
                        String script   = String.Empty;

                        if (Regex.IsMatch(fileName, @"^https?:\/\/", RegexOptions.IgnoreCase))
                        {
                            try
                            {
                                HttpWebRequest req      = WebRequest.CreateHttp(fileName);
                                var            response = req.GetResponse();
                                using (var stream = new StreamReader(response.GetResponseStream()))
                                {
                                    script = stream.ReadToEnd();
                                }
                            }
                            catch (Exception)
                            {
                                script = String.Empty;
                            }
                        }
                        else
                        {
                            if (fileName.StartsWith("file://", StringComparison.OrdinalIgnoreCase))
                            {
                                fileName = fileName.Substring("file://".Length);
                            }

                            if (File.Exists(fileName))
                            {
                                script = File.ReadAllText(fileName);
                            }
                        }

                        if (!String.IsNullOrEmpty(script))
                        {
                            ExecuteScriptEventArgs scriptArgs = new ExecuteScriptEventArgs()
                            {
                                Script = script, Handle = panel.AppPanel.AppWindowHandle
                            };
                            SPSL.BeginExecuteScript(scriptArgs);
                        }
                    }
                } catch (InvalidOperationException ex)
                {
                    MessageBox.Show("Error trying to create session " + ex.Message, "Failed to create session panel", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            return(panel);
        }