private async Task <bool> checkConnection() { if (!this.validateConnectionSettings()) { return(false); } this.OperationProgress.IsIndeterminate = true; SettingsTabs.IsEnabled = false; bool success = false; try { this.wallet = new EmercoinWallet(this.host, this.port, this.username, this.password); string balance = await Task.Run(() => this.wallet.GetBalance()); this.wallet.LoadRootDPO(this.rootDPOName); BalanceLabel.Content = "Balance: " + balance + " EMC"; StatusTextBlock.Text = "Connected successfully"; StatusTextBlock.Foreground = this.defaultColor; success = true; } catch (EmercoinWalletException ex) { AppUtils.ShowException(ex, this); StatusTextBlock.Text = "Connection failed"; StatusTextBlock.Foreground = this.errorColor; } this.OperationProgress.IsIndeterminate = false; SettingsTabs.IsEnabled = true; return(success); }
private async Task <bool> checkConnection() { if (!this.validateConnectionSettings()) { return(false); } OperationProgress.IsIndeterminate = true; SettingsGrid.IsEnabled = false; OperationsGrid.IsEnabled = false; bool success = false; try { this.wallet = new EmercoinWallet(this.settings.Host, this.settings.Port, this.settings.Username, this.settings.RpcPassword); string balance = await Task.Run(() => this.wallet.GetBalance()); this.wallet.LoadRootDPO(this.settings.RootDPOName); BalanceLabel.Content = "Balance: " + balance + " EMC"; StatusTextBlock.Text = "Connected to the wallet successfully"; StatusTextBlock.Foreground = this.defaultColor; success = true; } catch (EmercoinWalletException ex) { StatusTextBlock.Text = ex.Message; StatusTextBlock.Foreground = this.errorColor; } OperationProgress.IsIndeterminate = false; SettingsGrid.IsEnabled = true; OperationsGrid.IsEnabled = true; return(success); }
private async Task initialValidation() { // read settings and validate try { Settings.ReadSettings(); this.settings = Settings.Instance; var connectionOk = await this.checkConnection(); if (connectionOk) { StatusTextBlock.Text = "Settings OK"; StatusTextBlock.Foreground = this.defaultColor; } else { return; } // unlock wallet if needed bool walletLocked = false; try { var wallet = new EmercoinWallet(Settings.Instance.Host, Settings.Instance.Port, Settings.Instance.Username, Settings.Instance.RpcPassword); var walletInfo = await Task.Run(() => wallet.GetWalletInfo()); walletLocked = walletInfo != null && walletInfo.locked; } catch (EmercoinWalletException ex) { StatusTextBlock.Text = "Error while checking lock"; StatusTextBlock.Foreground = this.errorColor; AppUtils.ShowException(ex, this); } try { if (walletLocked) { await Task.Run(() => this.wallet.UnlockWallet(Settings.Instance.WalletPassphrase, 100000)); } } catch (EmercoinWalletException ex) { StatusTextBlock.Text = "Could not unlock the configured wallet"; StatusTextBlock.Foreground = this.errorColor; AppUtils.ShowException(ex, this); } } catch { StatusTextBlock.Text = "Check settings"; StatusTextBlock.Foreground = this.errorColor; } finally { this.Activate(); } }
public static async Task <bool> CheckConnection(string host, string port, string username, string password, string rootDPOName) { var wallet = new EmercoinWallet(host, port, username, password); return(await wallet.CheckConnection(rootDPOName)); }