Example #1
0
        /// <summary>Try to parse a script line into commands and arguments</summary>
        /// <param name="line">The line to parse</param>
        /// <param name="commandData">A <seealso cref="CommandData"/> object with commands and keystrokes</param>
        /// <returns>true on success, false on failure, CommandData will be null for commands not requiring data to be sent</returns>        
        public static bool TryParseScriptLine(String line, out CommandData commandData)
        {
            commandData = null;
            if (string.IsNullOrEmpty(line)
                || line.StartsWith("#")) // a comment line, ignore
            {
                return false;
            }


            string command = string.Empty;
            string args = string.Empty;

            int index = line.IndexOf(' ');
            if (index > 0)
            {
                command = line.Substring(0, index);
                args = line.Substring(index + 1).TrimEnd();
            }
            else
            {
                command = line.ToUpperInvariant().TrimEnd();
            }

            // lookup command and execute action associated with it.                
            Func<String, CommandData> spslCommand = MatchCommand(command);
            if (spslCommand != null)
            {
                commandData = spslCommand(args);
                return true;
            }
            else
            {
                Log.WarnFormat("Command {0} Not Supported", command);
                return false;
            }
        }
Example #2
0
        int TrySendCommandsFromToolbar(CommandData command, bool saveHistory)
        {
            int sent = 0;
            //String command = this.tsSendCommandCombo.Text; //this.tbTextCommand.Text;
            if (this.DockPanel.DocumentsCount > 0)
            {
                foreach (DockContent content in this.DockPanel.Documents)
                {
                    ctlPuttyPanel puttyPanel = content as ctlPuttyPanel;
                    if (puttyPanel != null && this.sendCommandsDocumentSelector.IsDocumentSelected(puttyPanel))
                    {
                        int handle = puttyPanel.AppPanel.AppWindowHandle.ToInt32();
                        Log.InfoFormat("SendCommand: session={0}, command=[{1}], handle={2}", puttyPanel.Session.SessionId, command, handle);

                        command.SendToTerminal(handle);
                        /*
                        foreach (Char c in command.Chars)
                        {
                            NativeMethods.SendMessage(handle, NativeMethods.WM_CHAR, (int)c, 0);
                        }

                        NativeMethods.SendMessage(handle, NativeMethods.WM_CHAR, (int)Keys.Enter, 0);*/
                        //NativeMethods.SendMessage(handle, NativeMethods.WM_KEYUP, (int)Keys.Enter, 0);
                        sent++;
                    }
                }
                if (sent > 0)
                {
                    // success...clear text and save in mru
                    this.tsSendCommandCombo.Text = string.Empty;
                    if (command != null && !string.IsNullOrEmpty(command.Command) && saveHistory)
                    {
                        this.tsSendCommandCombo.Items.Add(command.ToString());
                    }
                }
            }
            return sent;
        }
Example #3
0
        int TrySendCommandsFromToolbar(CommandData command, bool saveHistory)
        {
            int sent = 0;
            if (this.DockPanel.DocumentsCount > 0)
            {
                foreach (DockContent content in this.DockPanel.Documents)
                {
                    ctlPuttyPanel puttyPanel = content as ctlPuttyPanel;
                    if (puttyPanel != null && this.sendCommandsDocumentSelector.IsDocumentSelected(puttyPanel))
                    {
                        int handle = puttyPanel.AppPanel.AppWindowHandle.ToInt32();
                        Log.InfoFormat("SendCommand: session={0}, command=[{1}], handle={2}", puttyPanel.Session.SessionId, command, handle);

                        command.SendToTerminal(handle);

                        sent++;
                    }
                }

                if (sent > 0)
                {
                    // success...clear text and save in mru
                    this.tsSendCommandCombo.Text = string.Empty;
                    if (command != null && !string.IsNullOrEmpty(command.Command) && saveHistory)
                    {
                        this.tsSendCommandCombo.Items.Add(command.ToString());
                    }
                }
            }
            return sent;
        }
Example #4
0
        /// <summary>Send commands to open sessions</summary>
        /// <param name="command">The <seealso cref="CommandData"/> object containing text and or keyboard commands</param>
        /// <param name="saveHistory">If True, save the history in the command toolbar combobox</param>
        /// <returns>The number terminals commands have been sent to</returns>
        private int TrySendCommandsFromToolbar(CommandData command, bool saveHistory)
        {
            int sent = 0;

            if(this.DockPanel.Contents.Count > 0)
            {
                foreach (IDockContent doc in VisualOrderTabSwitchStrategy.GetDocuments(this.DockPanel))
                {
                    if (doc is ctlPuttyPanel)
                    {
                        ctlPuttyPanel panel = doc as ctlPuttyPanel;
                        if (this.sendCommandsDocumentSelector.IsDocumentSelected(panel))
                        {
                            int handle = panel.AppPanel.AppWindowHandle.ToInt32();
                            //Log.InfoFormat("SendCommand: session={0}, command=[{1}], handle={2}", panel.Session.SessionId, command, handle);

                            command.SendToTerminal(handle);

                            sent++;                 
                        }
                    }
                }                 

                if (sent > 0)
                {
                    // success...clear text and save in mru                    
                    if (command != null && !string.IsNullOrEmpty(command.Command) && saveHistory)
                    {
                        if (this.InvokeRequired)
                        {
                            this.BeginInvoke((MethodInvoker)delegate {
                                tsCommandHistory.Insert(0, new HistoryEntry() { Command = command.Command });
                            });
                        }
                        else
                        {                            
                            tsCommandHistory.Insert(0, new HistoryEntry() { Command = command.Command });
                        }                       
                    }

                    if (this.InvokeRequired)
                    {
                        this.BeginInvoke((MethodInvoker)delegate {
                            this.tsSendCommandCombo.Text = string.Empty;
                        });
                    }
                    else
                    {
                        this.tsSendCommandCombo.Text = string.Empty;
                    }
                }
            }
            return sent;
        }
Example #5
0
 /// <summary>Send a single character to terminal sessions</summary>
 /// <param name="arg">The character to send</param>
 /// <returns>A <seealso cref="CommandData"/> object containing the character to send</returns>
 internal static CommandData SendCharHandler(string arg)
 {
     CommandData data = new CommandData(arg);
     return data;
 }
Example #6
0
 /// <summary>Send a string to a terminal containing commands</summary>
 /// <param name="arg">The pre-parsed string to send</param>
 /// <returns>A string containing commands to send with variables replaced with a carriage return sent at the end</returns>
 internal static CommandData SendLineHandler(string arg)
 {
     // TODO: parse the arguments and replace and variables with customized data
     CommandData data = new CommandData(arg, new KeyEventArgs(Keys.Enter));
     return data;
 }