예제 #1
0
        static void Main(string[] args)
        {
            var shell   = new LiteShell(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
                {
                    shell.Database = 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, shell, display, input);

                    if (isConsoleCommand == false)
                    {
                        var result = shell.Run(cmd);

                        display.WriteResult(result);
                    }
                }
                catch (Exception ex)
                {
                    display.WriteError(ex.Message);
                }
            }
        }
예제 #2
0
        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);
                }
            }
        }