public static void Start(InputCommand input, Display display) { IShellEngine engine = null; display.TextWriters.Add(Console.Out); // show welcome message display.WriteWelcome(); while (input.Running) { // read next command from user or queue var cmd = input.ReadCommand(); if (string.IsNullOrEmpty(cmd)) continue; try { var isConsoleCommand = ConsoleCommand.TryExecute(cmd, ref engine, display, input); if (isConsoleCommand == false) { if (engine == null) throw ShellExpcetion.NoDatabase(); engine.Run(cmd, display); } } catch (Exception ex) { display.WriteError(ex.Message); } } }
public static void Start(InputCommand input, Display display) { var commands = new List <IShellCommand>(); var env = new Env { Input = input, Display = display }; // register commands RegisterCommands(commands); display.TextWriters.Add(Console.Out); // show welcome message display.WriteWelcome(); while (input.Running) { // read next command from user or queue var cmd = input.ReadCommand(); if (string.IsNullOrEmpty(cmd)) { continue; } try { var s = new StringScanner(cmd); var found = false; // first test all shell app commands foreach (var command in commands) { if (!command.IsCommand(s)) { continue; } command.Execute(s, env, out var a, out var b); found = true; break; } // if not found, try database command if (!found) { display.WriteResult(env.Engine.Run(cmd)); } } catch (Exception ex) { display.WriteError(ex); } } }
public static void Start(InputCommand input, Display display) { var commands = new List<ICommand>(); var env = new Env(); // register commands RegisterCommands(commands); display.TextWriters.Add(Console.Out); // show welcome message display.WriteWelcome(); while (input.Running) { // read next command from user or queue var cmd = input.ReadCommand(); if (string.IsNullOrEmpty(cmd)) continue; try { var s = new StringScanner(cmd); var found = false; // test all commands foreach (var command in commands) { if (!command.IsCommand(s)) continue; // test if command it's only shell command if (command.Access == DataAccess.None) { command.Execute(null, s, display, input, env); } else { using (var engine = env.CreateEngine(command.Access)) { command.Execute(engine, s, display, input, env); } } found = true; break; } if (!found) throw new ShellExpcetion("Command not found"); } catch (Exception ex) { display.WriteError(ex.Message); } } }
static void Main(string[] args) { LiteDatabase db = null; var input = new InputCommand(); var display = new Display(); display.TextWriters.Add(Console.Out); // show welcome message display.WriteWelcome(); // if has a argument, its database file - try open if (args.Length > 0) { try { db = new LiteDatabase(args[0]); } catch (Exception ex) { display.WriteError(ex.Message); } } while (true) { // read next command from user var cmd = input.ReadCommand(); if (string.IsNullOrEmpty(cmd)) { continue; } try { var isConsoleCommand = ConsoleCommand.TryExecute(cmd, ref db, display, input); if (isConsoleCommand == false) { if (db == null) { throw LiteException.NoDatabase(); } var result = db.Run(cmd); display.WriteResult(result); } } catch (Exception ex) { display.WriteError(ex.Message); } } }
static void Main(string[] args) { LiteDatabase db = null; var input = new InputCommand(); var display = new Display(); display.TextWriters.Add(Console.Out); // show welcome message display.WriteWelcome(); // if has a argument, its database file - try open if (args.Length > 0) { try { db = new LiteDatabase(args[0]); } catch (Exception ex) { display.WriteError(ex.Message); } } while (true) { // read next command from user var cmd = input.ReadCommand(); if (string.IsNullOrEmpty(cmd)) continue; try { var isConsoleCommand = ConsoleCommand.TryExecute(cmd, ref db, display, input); if (isConsoleCommand == false) { if(db == null) throw LiteException.NoDatabase(); var result = db.Run(cmd); display.WriteResult(result); } } catch (Exception ex) { display.WriteError(ex.Message); } } }
public static void Start(InputCommand input, Display display) { var env = new Env { Input = input, Display = display }; // show welcome message display.WriteWelcome(); Console.CancelKeyPress += (o, e) => { e.Cancel = true; env.Running = false; }; while (input.Running) { // read next command from user or queue var cmd = input.ReadCommand(); if (string.IsNullOrEmpty(cmd)) { continue; } try { var scmd = GetCommand(cmd); if (scmd != null) { scmd(env); continue; } // if string is not a shell command, try execute as sql command if (env.Database == null) { throw new Exception("Database not connected"); } env.Running = true; display.WriteResult(env.Database.Execute(cmd), env); } catch (Exception ex) { display.WriteError(ex); } } }
public static void Start(InputCommand input, Display display) { IShellEngine engine = null; display.TextWriters.Add(Console.Out); // show welcome message display.WriteWelcome(); while (input.Running) { // read next command from user or queue var cmd = input.ReadCommand(); if (string.IsNullOrEmpty(cmd)) { continue; } try { var isConsoleCommand = ConsoleCommand.TryExecute(cmd, ref engine, display, input); if (isConsoleCommand == false) { if (engine == null) { throw ShellExpcetion.NoDatabase(); } engine.Run(cmd, display); } } catch (Exception ex) { display.WriteError(ex.Message); } } }
public static void Start(InputCommand input, Display display) { var commands = new List <ICommand>(); var env = new Env(); LiteEngine engine = null; // register commands RegisterCommands(commands); display.TextWriters.Add(Console.Out); // show welcome message display.WriteWelcome(); while (input.Running) { // read next command from user or queue var cmd = input.ReadCommand(); if (string.IsNullOrEmpty(cmd)) { continue; } try { var s = new StringScanner(cmd); var found = false; // test all commands foreach (var command in commands) { if (!command.IsCommand(s)) { continue; } command.Execute(engine, s, display, input, env); if (env.Filename != null && engine == null) { engine = env.CreateEngine(DataAccess.Write); } found = true; break; } if (!found) { throw new ShellException("Command not found"); } } catch (Exception ex) { display.WriteError(ex.Message); } } }