Example #1
0
 private ICommandSeparator GetSeparator()
 {
     if (separator == null)
     {
         separator = CreateSeparator();
     }
     return(separator);
 }
Example #2
0
        protected virtual LineExecutionResultCode ExecuteLine(string line)
        {
            ICommandSeparator commandSeparator = GetSeparator();

            if (commandSeparator != null)
            {
                StringBuilder lineBuilder = new StringBuilder(line);
                lineBuilder.Append(Environment.NewLine);
                commandSeparator.Append(lineBuilder.ToString());

                LineExecutionResultCode resultCode = LineExecutionResultCode.Incomplete;

                while (commandSeparator.MoveNext())
                {
                    string completeCommand = commandSeparator.Current;
                    if (HandlesSettings)
                    {
                        completeCommand = Settings.Substitute(completeCommand);
                    }

                    Command c = Commands.GetCommand(completeCommand);

                    if (c == null)
                    {
                        commandSeparator.Consumed();
                        // do not shadow successful executions with the 'line-empty'
                        // message. Background is: when we consumed a command, that
                        // is complete with a trailing ';', then the following newline
                        // would be considered as empty command. So return only the
                        // 'Empty', if we haven't got a succesfully executed line.
                        if (resultCode != LineExecutionResultCode.Executed)
                        {
                            resultCode = LineExecutionResultCode.Empty;
                        }
                    }
                    else if (!c.IsComplete(completeCommand))
                    {
                        commandSeparator.Cont();
                        resultCode = LineExecutionResultCode.Incomplete;
                    }
                    else
                    {
                        Execute(ActiveContext, completeCommand.Trim());

                        commandSeparator.Consumed();

                        resultCode = LineExecutionResultCode.Executed;
                    }
                }

                return(resultCode);
            }

            // if we don't have any separator, we assume it's a complete command
            Execute(ActiveContext, line);
            return(LineExecutionResultCode.Executed);
        }
Example #3
0
 private ICommandSeparator GetSeparator()
 {
     if (separator == null)
         separator = CreateSeparator();
     return separator;
 }