public static int Main(string[] args)
        {
            Log.Information("Price update started");

            var configuration = new ConfigurationBuilder()
                                .AddJsonFile("./config.json", false)
                                .AddJsonFile("./config.real.json", true)
                                .Build();

            Log.Logger = new LoggerConfiguration()
                         .ReadFrom.Configuration(configuration)
                         .CreateLogger();

            var startArgs = StartArgs.FromArgs(args);

            var builder    = new ContainerBuilder();
            var initModule = new InitModule(configuration, startArgs);

            builder.RegisterModule(initModule);

            var container = builder.Build();

            var robot = container.Resolve <IRobot>();

            var cancellationToken = new CancellationTokenSource();

            Console.CancelKeyPress += (sender, eventArgs) =>
            {
                cancellationToken.Cancel();
            };

            var result = PriceUpdateResultStatus.Ok;

            robot.ProcessPrice(cancellationToken)
            .ContinueWith(res => result = res.Result, cancellationToken.Token)
            .Wait(cancellationToken.Token);

            return(Convert.ToInt32(result));
        }
Example #2
0
        static async Task Main(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += (_, e) =>
            {
                Application.Top.Running = false;
                Application.RequestStop();
                Application.Shutdown();
                Console.WriteLine($"There was an error.{Environment.NewLine}{e.ExceptionObject}");
            };
            Application.Init();

            var httpClient = new HttpClient();
            var urls       = new[] { DefaultUrl };
            var jsonRpcClientProxyMaxRetries = new JsonRpcClientProxy(new DefaultHttpClient(httpClient,
                                                                                            new EthereumJsonSerializer(), LimboLogs.Instance, int.MaxValue), urls, LimboLogs.Instance);
            var ethJsonRpcClientProxyMaxRetries    = new EthJsonRpcClientProxy(jsonRpcClientProxyMaxRetries);
            var jsonRpcWalletClientProxyMaxRetries = new JsonRpcWalletClientProxy(jsonRpcClientProxyMaxRetries);
            var runnerValidator = new RunnerValidator(httpClient, DefaultUrl);
            var networkModule   = new NetworkModule();

            networkModule.NetworkSelected += async(_, network) =>
            {
                var initModule = new InitModule(ethJsonRpcClientProxyMaxRetries, runnerValidator, network);
                initModule.OptionSelected += async(_, optionInfo) =>
                {
                    var addressesModule = new AddressesModule(optionInfo, jsonRpcWalletClientProxyMaxRetries);
                    addressesModule.AddressesSelected += async(_, addressesEvent) =>
                    {
                        urls = new[] { addressesEvent.NodeAddress };

                        AddAuthorizationHeader(httpClient, addressesEvent.NodeAddress);

                        Application.MainLoop.Invoke(async() =>
                        {
                            var balanceModule = new BalanceModule(ethJsonRpcClientProxyMaxRetries,
                                                                  addressesEvent.AccountAddress);
                            balanceModule.TransferClicked += async(_, transferEvent) =>
                            {
                                var transferModule = new TransferModule(ethJsonRpcClientProxyMaxRetries,
                                                                        jsonRpcWalletClientProxyMaxRetries,
                                                                        transferEvent.Address, transferEvent.Balance);
                                var transferWindow = await transferModule.InitAsync();
                                Application.Top.Add(transferWindow);
                                Application.Run(transferWindow);
                            };
                            var balanceWindow = await balanceModule.InitAsync();
                            Application.Top.Add(balanceWindow);
                            Application.Run(balanceWindow);
                        });
                    };
                    var addressesWindow = await addressesModule.InitAsync();

                    Application.Top.Add(addressesWindow);
                    Application.Run(addressesWindow);
                };

                var initWindow = await initModule.InitAsync();

                Application.Top.Add(initWindow);
                Application.Run(initWindow);
            };
            var networkWindow = await networkModule.InitAsync();

            Application.Top.Add(networkWindow);
            Application.Run();
        }