public long Run()

in XForm/XForm/InteractiveRunner.cs [50:150]


        public long Run()
        {
            long lastCount = 0;

            try
            {
                while (true)
                {
                    Console.Write("> ");

                    // Read the next query line
                    string nextLine = Console.ReadLine();

                    Stopwatch w = Stopwatch.StartNew();
                    try
                    {
                        if (String.IsNullOrEmpty(nextLine)) return lastCount;

                        string[] parts = nextLine.Split(' ');
                        string command = parts[0].ToLowerInvariant();
                        switch (command)
                        {
                            case "quit":
                            case "exit":
                                // Stop on empty, "quit", or "exit"
                                return lastCount;


                            case "back":
                            case "undo":
                                // Unwrap on "back" or "undo"
                                IXTable last = _stages.LastOrDefault();
                                if (last != null)
                                {
                                    _pipeline = last;
                                    _stages.RemoveAt(_stages.Count - 1);
                                    _commands.RemoveAt(_commands.Count - 1);
                                }

                                break;
                            case "save":
                                string tableName = parts[1];
                                string queryPath = _xDatabaseContext.StreamProvider.Path(LocationType.Query, tableName, ".xql");
                                _xDatabaseContext.StreamProvider.WriteAllText(queryPath, String.Join(Environment.NewLine, _commands));
                                Console.WriteLine($"Query saved to \"{tableName}\".");


                                _commands.Clear();
                                _commands.Add($"read \"{tableName}\"");
                                _pipeline = null;
                                _pipeline = AddStage(_commands[0]);

                                break;
                            case "run":
                                LoadScript(parts[1]);
                                break;
                            case "rerun":
                                LoadScript(s_commandCachePath);
                                break;
                            default:
                                try
                                {
                                    _pipeline = AddStage(nextLine);
                                    break;
                                }
                                catch (Exception ex) when (!Debugger.IsAttached)
                                {
                                    Console.WriteLine($"Error: {ex.Message}");
                                    continue;
                                }
                        }
                    }
                    catch (ArgumentException ex)
                    {
                        Console.WriteLine(ex.Message);
                        continue;
                    }

                    SaveScript(s_commandCachePath);

                    // Get the first 10 results and 10 columns
                    IXTable firstTenWrapper = _pipeline;
                    firstTenWrapper = _xDatabaseContext.Query("limit 10 10", firstTenWrapper);
                    firstTenWrapper = _xDatabaseContext.Query("write cout", firstTenWrapper);
                    lastCount = firstTenWrapper.Count();

                    // Get the count
                    RunResult result = _pipeline.RunUntilTimeout(TimeSpan.FromSeconds(3));
                    lastCount += result.RowCount;
                    firstTenWrapper.Reset();

                    Console.WriteLine();
                    Console.WriteLine($"{lastCount:n0} rows in {w.Elapsed.ToFriendlyString()}. {(result.IsComplete ? "" : "[incomplete]")}");
                    Console.WriteLine();
                }
            }
            finally
            {
                if (_pipeline != null) _pipeline.Dispose();
            }
        }