private void PrintContext() { _output.WriteLine(""); _output.WriteLine("Context:"); _output.WriteLine(_context?.ToString()); _output.WriteLine(""); }
void Update() { if (Input.GetKeyDown(KeyCode.Return) && string.IsNullOrWhiteSpace(InputService.InputField.text) == false) { Outputservice.WriteLine($"> {InputService.InputField.text}"); InputService.ProcessInput(); InputService.InputField.ActivateInputField(); LocationText.text = game.Player.Location.Name; } #if UNITY_EdITOR if (game.IsRunning == false) { UnityEditor.EditorApplication.isPlaying = false; #else Application.Quit(); #endif } }
public void Log <TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func <TState, Exception, string> formatter) { string messageText = formatter(state, exception); _outputService.WriteLine(messageText); }
public void Run() { Console.CancelKeyPress += CancelKeyPress; using (_output = new OutputService(true, true)) { _context = JObject.FromObject(new { input1 = "555-99-5656" }); PrintContext(); while (true) { try { Console.Write(":> "); _command = Console.ReadLine(); _output.WriteLine($"Command: {_command}"); if (_context == null) { throw new ApplicationException("Context is empty."); } if (string.IsNullOrEmpty(_command)) { _command = "context"; } if (_command.ToLower() == "exit") { break; } if (_command.StartsWith("{") || _command.ToLower().StartsWith("context {")) { _context = JObject.Parse(_command.Replace("context ", "")); PrintContext(); continue; } if (_command.ToLower().StartsWith("context")) { PrintContext(); continue; } try { // Evaluate //var contextJson = _context.ToString(); //var parameters = new FormulaRuntimeParameters(contextJson); //var schema = Schema.GetSchemaFromJson(contextJson); //var expr = new FormulaWithParameters(_command, schema); //var value = await runner.RunAsync(expr, parameters); BrunoProgram ast = ParseService.Parse(_command); object result = InterpreterService.Evaluate(ast); PrintResult(result); _command = null; } catch (BrunoRuntimeException error) { PrintException(error); } } catch (Exception ex) { PrintException(ex); } } } }