public async Task <JsValue> PostJint(string method, params object[] parameters) { try { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); object result = await _currentClient.Post <object>(method, parameters); stopwatch.Stop(); decimal totalMicroseconds = stopwatch.ElapsedTicks * (1_000_000m / Stopwatch.Frequency); Console.WriteLine($"Request complete in {totalMicroseconds}μs"); string resultString = result?.ToString(); if (resultString == "0x") { return(JsValue.Null); } return(resultString == null ? JsValue.Null : _jsonParser.Parse(resultString)); } catch (HttpRequestException e) { CliConsole.WriteErrorLine(e.Message); } catch (Exception e) { CliConsole.WriteException(e); } return(JsValue.Null); }
public void Error(string text, Exception ex = null) { CliConsole.WriteErrorLine(text); if (ex != null) { CliConsole.WriteException(ex); } }
public async Task <T> Post <T>(string method, params object[] parameters) { try { return(await _currentClient.Post <T>(method, parameters)); } catch (HttpRequestException e) { CliConsole.WriteErrorLine(e.Message); } catch (Exception e) { CliConsole.WriteException(e); } return(default(T)); }
public JsValue Execute(string statement) { try { return(JintEngine.Execute(statement).GetCompletionValue()); } catch (ParserException e) { CliConsole.WriteErrorLine(e.Message); } catch (CliArgumentParserException e) { CliConsole.WriteErrorLine(e.Message); } catch (Exception e) { CliConsole.WriteException(e); } return(JsValue.Null); }
public async Task <T> Post <T>(string method, params object[] parameters) { try { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); T result = await _currentClient.Post <T>(method, parameters); stopwatch.Stop(); Console.WriteLine($"Request complete in {stopwatch.ElapsedMilliseconds}ms"); return(result); } catch (HttpRequestException e) { CliConsole.WriteErrorLine(e.Message); } catch (Exception e) { CliConsole.WriteException(e); } return(default);
public async Task <T> Post <T>(string method, params object[] parameters) { try { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); T result = await _currentClient.Post <T>(method, parameters); stopwatch.Stop(); decimal totalMicroseconds = stopwatch.ElapsedTicks * (1_000_000m / Stopwatch.Frequency); Console.WriteLine($"Request complete in {totalMicroseconds}μs"); return(result); } catch (HttpRequestException e) { CliConsole.WriteErrorLine(e.Message); } catch (Exception e) { CliConsole.WriteException(e); } return(default);
private static void RunEvalLoop() { while (true) { try { if (Terminal != Terminal.Cmder) { Colorful.Console.ForegroundColor = ColorScheme.Text; } const int bufferSize = 1024 * 16; string statement; using (Stream inStream = System.Console.OpenStandardInput(bufferSize)) { Colorful.Console.SetIn(new StreamReader(inStream, Colorful.Console.InputEncoding, false, bufferSize)); CliConsole.WriteLessImportant("nethermind> "); statement = Terminal == Terminal.Cygwin ? Colorful.Console.ReadLine() : ReadLine.Read(); statement = RemoveDangerousCharacters(statement); HistoryManager.UpdateHistory(statement); } if (statement == "exit") { break; } JsValue result = Engine.Execute(statement); WriteResult(result); } catch (Exception e) { CliConsole.WriteException(e); } } }
private static void RunEvalLoop() { try { if (File.Exists(HistoryFilePath)) { foreach (string line in File.ReadLines(HistoryFilePath).TakeLast(60)) { if (line != _removedString) { ReadLine.AddHistory(line); } } } } catch (Exception e) { CliConsole.WriteErrorLine($"Could not load cmd history from {HistoryFilePath} {e.Message}"); } ReadLine.AutoCompletionHandler = new AutoCompletionHandler(); while (true) { try { if (_terminal != Terminal.Cmder) { Console.ForegroundColor = ColorScheme.Text; } int bufferSize = 1024 * 16; string statement; using (Stream inStream = System.Console.OpenStandardInput(bufferSize)) { Console.SetIn(new StreamReader(inStream, Console.InputEncoding, false, bufferSize)); CliConsole.WriteLessImportant("nethermind> "); statement = _terminal == Terminal.Cygwin ? Console.ReadLine() : ReadLine.Read(); CleanStatement(statement); if (!File.Exists(HistoryFilePath)) { File.Create(HistoryFilePath).Dispose(); } if (!SecuredCommands.Any(sc => statement.Contains(sc))) { ReadLine.AddHistory(statement); using (var fileStream = File.AppendText(HistoryFilePath)) { fileStream.WriteLine(statement); } } else { ReadLine.AddHistory(_removedString); } } if (statement == "exit") { break; } JsValue result = _engine.Execute(statement); if (result.IsObject() && result.AsObject().Class == "Function") { CliConsole.WriteGood(result.ToString()); CliConsole.WriteLine(); } else if (!result.IsNull()) { string text = Serializer.Serialize(result.ToObject(), true); // File.AppendAllText("C:\\temp\\cli.txt", text); CliConsole.WriteGood(text); } else { CliConsole.WriteLessImportant("null"); CliConsole.WriteLine(); } // bool isNull = result.IsNull(); // if (!isNull) // { // CliConsole.WriteString(result); // } } catch (Exception e) { CliConsole.WriteException(e); } } }