private SynchronizerViewModel(Process walletProcess, WalletClient client) { WalletRpcProcess = walletProcess; WalletRpcClient = client; Messenger.RegisterSingleton<SynchronizerViewModel>(OnMessageReceived); }
private void Application_Startup(object sender, StartupEventArgs e) { WalletClient.Initialize(); var startupTask = Task.Run(async () => { await TransportSecurity.EnsureCertificatePairExists(); // TODO: Make network selectable (parse e.Args for a network) var walletProcess = WalletProcess.Start(BlockChainIdentity.TestNet3); WalletClient walletClient; try { walletClient = await WalletClient.ConnectAsync(WalletClient.LocalNetworkAddress); } catch (Exception) { if (walletProcess.HasExited) { throw new Exception("Wallet process closed unexpectedly"); } walletProcess.KillIfExecuting(); throw; } return Tuple.Create(walletProcess, walletClient); }); startupTask.Wait(); var startupResult = startupTask.Result; WalletRpcProcess = startupResult.Item1; WalletRpcClient = startupResult.Item2; Application.Current.Exit += Application_Exit; }
private void Application_Startup(object sender, StartupEventArgs e) { var args = ProcessArguments.ParseArguments(e.Args); var activeNetwork = args.IntendedNetwork; WalletClient.Initialize(); var appDataDir = Portability.LocalAppData(Environment.OSVersion.Platform, AssemblyResources.Organization, AssemblyResources.ProductName); Directory.CreateDirectory(appDataDir); var startupTask = Task.Run(async () => { // Begin the asynchronous reading of the certificate before starting the wallet // process. This uses filesystem events to know when to begin reading the certificate, // and if there is too much delay between wallet writing the cert and this process // beginning to observe the change, the event may never fire and the cert won't be read. var rootCertificateTask = TransportSecurity.ReadModifiedCertificateAsync(appDataDir); var walletProcess = WalletProcess.Start(activeNetwork, appDataDir); WalletClient walletClient; try { var listenAddress = WalletProcess.RpcListenAddress("localhost", activeNetwork); var rootCertificate = await rootCertificateTask; walletClient = await WalletClient.ConnectAsync(listenAddress, rootCertificate); } catch (Exception) { if (walletProcess.HasExited) { throw new Exception("Wallet process closed unexpectedly"); } walletProcess.KillIfExecuting(); throw; } return Tuple.Create(walletProcess, walletClient); }); startupTask.Wait(); var startupResult = startupTask.Result; ActiveNetwork = activeNetwork; WalletRpcProcess = startupResult.Item1; WalletRpcClient = startupResult.Item2; Application.Current.Exit += Application_Exit; }