Пример #1
0
 /// <summary>
 /// Run a shell command in current database. Returns a BsonValue as result
 /// </summary>
 public BsonValue RunCommand(string command)
 {
     if (_shell == null)
     {
         _shell = new LiteShell(this);
     }
     return _shell.Run(command);
 }
Пример #2
0
        static void Main(string[] args)
        {
            var shell = new LiteShell();
            var input = new InputCommand();

            shell.RegisterAll();
            shell.Display.TextWriters.Add(Console.Out);

            // show welcome message
            shell.Display.WriteWelcome();

            // if has a argument, its database file - try open
            if (args.Length > 0)
            {
                try
                {
                    shell.Engine = new LiteEngine(args[0]);
                }
                catch (Exception ex)
                {
                    shell.Display.WriteError(ex.Message);
                }
            }

            while (true)
            {
                // read next command from user
                var cmd = input.ReadCommand();

                if (string.IsNullOrEmpty(cmd))
                {
                    continue;
                }

                try
                {
                    if (cmd.StartsWith("open "))
                    {
                        if (shell.Engine != null)
                        {
                            shell.Engine.Dispose();
                        }

                        shell.Engine = new LiteEngine(cmd.Substring(5));
                    }
                    else
                    {
                        shell.Run(cmd);
                    }
                }
                catch (Exception ex)
                {
                    shell.Display.WriteError(ex.Message);
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Run a command shell formating $0, $1 to JSON string args item index
        /// </summary>
        public BsonValue Run(string command, params BsonValue[] args)
        {
            var shell = new LiteShell();

            var cmd = Regex.Replace(command, @"\$(\d+)", (k) =>
            {
                var index = Convert.ToInt32(k.Groups[1].Value);
                return JsonSerializer.Serialize(args[index]);
            });

            return shell.Run(_engine.Value, cmd);
        }
Пример #4
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);
                }
            }
        }
Пример #5
0
        /// <summary>
        /// If command is a console command, execute and returns true - if not, just returns false
        /// </summary>
        public static bool TryExecute(string command, LiteShell shell, Display display, InputCommand input)
        {
            var s = new StringScanner(command);

            foreach (var cmd in Commands)
            {
                if (cmd.IsCommand(s))
                {
                    cmd.Execute(shell, s, display, input);
                    return(true);
                }
            }

            return(false);
        }
Пример #6
0
        /// <summary>
        /// If command is a console command, execute and returns true - if not, just returns false
        /// </summary>
        public static bool TryExecute(string command, LiteShell shell, Display display, InputCommand input)
        {
            var s = new StringScanner(command);

            foreach (var cmd in Commands)
            {
                if (cmd.IsCommand(s))
                {
                    cmd.Execute(shell, s, display, input);
                    return true;
                }
            }

            return false;
        }
Пример #7
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);
                }
            }
        }
Пример #8
0
        /// <summary>
        /// Run a command shell
        /// </summary>
        public BsonValue Run(string command)
        {
            var shell = new LiteShell();

            return shell.Run(_engine.Value, command);
        }
Пример #9
0
 public abstract void Execute(LiteShell shell, StringScanner s, Display display, InputCommand input);
Пример #10
0
 public abstract void Execute(LiteShell shell, StringScanner s, Display display, InputCommand input);