Пример #1
0
        public PeersApp() : base("Peers")
        {
            string[] urls = { DefaultUrl };

            var logger            = LimboLogs.Instance;
            var serializer        = new EthereumJsonSerializer();
            var httpClient        = new HttpClient();
            var defaultHttpClient = new DefaultHttpClient(httpClient, serializer, logger, int.MaxValue);
            var proxy             = new JsonRpcClientProxy(defaultHttpClient, urls, logger);

            _adminRpc = new AdminJsonRpcClientProxy(proxy);

            MenuBar menu = new MenuBar(new MenuBarItem[]
            {
                new MenuBarItem("_File", new MenuItem[]
                {
                    new MenuItem("_Quit", "", () => { Application.RequestStop(); })
                }),
            });

            ListView view = new ListView()
            {
                X      = 0,
                Y      = 1,
                Width  = Dim.Fill(),
                Height = Dim.Fill() - 1,
            };

            view.AllowsAll();

            Add(menu, view);

            bool UpdateTimer(MainLoop mainLoop)
            {
                _adminRpc.admin_peers(true).ContinueWith(
                    t => Application.MainLoop.Invoke(() =>
                {
                    Title = $"Last Peers Update {DateTime.Now}";
                    view.SetSourceAsync(t.Result.Result.Select(ToPeerInfoRow).OrderByDescending(r => r.Reputation).ToArray());
                })
                    );

                return(true);
            }

            var token = Application.MainLoop.AddTimeout(TimeSpan.FromSeconds(10), UpdateTimer);
        }