void ISqlConsole.Execute(string command) { string line = null; StringReader reader = new StringReader(command); while ((line = reader.ReadLine()) != null) { Console.WriteLine(this._currentLineNumber + "> " + line); if (!this.ProcessConsoleEntry(line)) { this.QuitConsole = true; return; } if (ConsoleHandler.IsLogOpen) { try { ConsoleHandler.FlushLog(); continue; } catch { continue; } } } this._currentLineNumber = 1L; this.CommandBuffer.Clear(); }
internal void Run(string commandFile, Dictionary <string, string> variables) { this.EnsureInitialized(); try { if (string.IsNullOrEmpty(commandFile)) { string str; Console.WriteLine(""); Console.WriteLine("Console mode. Type 'help' for more information."); this.QuitConsole = false; do { Console.Write(this._currentLineNumber + "> "); str = Console.ReadLine(); if ((str == null) || !this.ProcessConsoleEntry(str)) { return; } if (ConsoleHandler.IsLogOpen) { try { ConsoleHandler.FlushLog(); } catch { } } }while ((str != null) && !this.QuitConsole); } else { this.PlayCommandFile(commandFile, this._connection, variables); } } finally { try { this._connection.Close(); } catch { } } }
private static void Main(string[] args) { ConsoleHandler.Initialize(); ConsoleUtil.ResizeConsoleInputBuffer(0x6400); try { try { CommandLineParser.ParseCommandArgs(args); } catch (CommandParserException exception) { if (!string.IsNullOrEmpty(exception.Message)) { Console.WriteLine(exception.Message); } return; } catch (Exception ex) { if (!string.IsNullOrEmpty(ex.Message)) { Console.WriteLine(ex.Message); } return; } if (CommandLineParser.Command == null) { ShowHelpCommand.ExecuteDirect(); } else { var command = CommandLineParser.Command as ShowHelpCommand; if (command != null) { ((ISimpleCommand)CommandLineParser.Command).Execute(); } else { if (!string.IsNullOrEmpty(CommandLineParser.LogFilePath)) { CommandLineParser.CleanupArguments(args); ConsoleHandler.StartLog(CommandLineParser.LogFilePath, ProgramInfo.ExecutableName, new string[0]); } try { var engineCommand = CommandLineParser.Command as IEngineCommand; if (engineCommand != null) { new Engine(CommandLineParser.ConnectionOptions).Execute(engineCommand); } else { var simpleCommand = CommandLineParser.Command as ISimpleCommand; if (simpleCommand != null) { simpleCommand.Execute(); } } } catch (Exception exception2) { Console.WriteLine(exception2.Message); } } } } finally { ConsoleHandler.Cleanup(); } }
private void ExecuteExtendedCommand(ConsoleCommand command) { try { if (command is TimerCommand) { this._timerEnabled = !this._timerEnabled; if (this._timerEnabled) { Console.WriteLine("Timer enabled."); } else { Console.WriteLine("Timer disabled."); } return; } if (command is CommandTimeoutCommand) { int timeout = ((CommandTimeoutCommand)command).Timeout; if (timeout < 0) { Console.WriteLine("Invalid command timeout specified. Must be a positive integer."); } else { this._engine.ConnectionManager.ConnectionOptions.CommandTimeout = timeout; if (timeout == 0) { Console.WriteLine("Command timeout set to 0 (unlimited)."); } else if (timeout > 0) { Console.WriteLine("Command timeout set to " + timeout + " second(s)."); } } return; } if (command is ShowHistoryCommand) { this.ShowHistory(((ShowHistoryCommand)command).CommandCount); return; } if (command is SaveHistoryCommand) { this.SaveHistory(((SaveHistoryCommand)command).FilePath); return; } if (command is ClearHistoryCommand) { this._addToHistory = false; this._history.Clear(); Console.WriteLine("History cleared."); return; } if (command is OpenLogCommand) { if (ConsoleHandler.IsLogOpen) { throw new Exception("Log is already opened. To create a new log file, first close the current log using 'logclose'."); } ConsoleHandler.StartLog(((OpenLogCommand)command).FilePath, "> " + Settings.ConsoleCommandPrefix + "logopen", new string[] { ((OpenLogCommand)command).FilePath }); Console.WriteLine("Log opened."); return; } if (command is CloseLogCommand) { if (!ConsoleHandler.IsLogOpen) { throw new Exception("Log is already closed."); } ConsoleHandler.StopLog(); Console.WriteLine("Log closed."); return; } Console.WriteLine("Extended command not recognized."); } catch (Exception exception) { Console.WriteLine("Error processing extended command."); if (!string.IsNullOrEmpty(exception.Message)) { Console.WriteLine(exception.Message); } } Console.WriteLine(""); }