private async Task remoteSettingsLogic() { this.OperationProgress.IsIndeterminate = true; // Check settings bool connectionOk = false; try { connectionOk = await EmercoinWallet.CheckConnection( this.remoteSettingsPage.HostText.Text, this.remoteSettingsPage.PortNumberText.Text, this.remoteSettingsPage.UsernameText.Text, this.remoteSettingsPage.RpcPassword.Password, Settings.Instance.RootDPOName); this.StatusTextBlock.Text = "Connected successfully"; this.StatusTextBlock.Foreground = this.defaultColor; } catch (EmercoinWalletException ex) { this.StatusTextBlock.Text = ex.Message; this.StatusTextBlock.Foreground = this.errorColor; } bool walletLocked = true; bool pwdChecked = false; if (connectionOk) { try { var wallet = new EmercoinWallet( this.remoteSettingsPage.HostText.Text, this.remoteSettingsPage.PortNumberText.Text, this.remoteSettingsPage.UsernameText.Text, this.remoteSettingsPage.RpcPassword.Password); var walletInfo = await Task.Run(() => wallet.GetWalletInfo()); walletLocked = (walletInfo != null && walletInfo.locked) || !string.IsNullOrEmpty(Settings.Instance.WalletPassphrase); if (walletLocked) { pwdChecked = await wallet.CheckWalletPassphrase(Settings.Instance.WalletPassphrase); } } catch (EmercoinWalletException ex) { } if (walletLocked && !pwdChecked) { this.StatusTextBlock.Text = "Wallet passphrase check failed"; this.StatusTextBlock.Foreground = this.errorColor; } } this.OperationProgress.IsIndeterminate = false; this.closeDisabled = false; this.success = connectionOk && (!walletLocked || pwdChecked); if (this.success) { this.saveSettingsFromUI(); this.DialogResult = true; } else { var promptResult = MessageBox.Show(this, "Configuration check error. Save settings anyway?", "Save settings", MessageBoxButton.YesNo, MessageBoxImage.Question); if (promptResult == MessageBoxResult.Yes) { this.saveSettingsFromUI(); this.DialogResult = true; } } }
private async Task localModeLogic() { // get the best wallet instance among installed var walletApps = WalletInstallInfo.GetInfo(); var walletApp = walletApps.Count() > 0 ? walletApps.OrderBy(i => i.Version).ThenBy(i => i.Bitness).Last() : null; if (walletApp == null) { Process.Start("https://sourceforge.net/projects/emercoin/files/"); throw new SettingsWizardException("No Emercoin Core applications installed on this computer"); } var walletConfigPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\" + "Emercoin" + "\\emercoin.conf"; var confManager = new EmercoinConfigManager(walletConfigPath); var conf = confManager.ReadConfig(); // check emercoin config if corresponds to publisher settings if (!conf.ValidateParameters(Settings.Instance.Port, Settings.Instance.Username, Settings.Instance.RpcPassword)) { confManager.FixToActive(conf); confManager.WriteConfig(conf, walletConfigPath); Settings.Instance.Host = "localhost"; Settings.Instance.Port = conf.GetParameterValue(EmercoinConfig.portParam) ?? string.Empty; Settings.Instance.Username = conf.GetParameterValue(EmercoinConfig.userParam) ?? string.Empty; Settings.Instance.RpcPassword = conf.GetParameterValue(EmercoinConfig.rpcPasswordParam) ?? string.Empty; Settings.WriteSettings(); } // restart wallet in order to apply new settings bool connectionOk = false; if (walletApp.IsExecuting()) { // test connection var testWallet = new EmercoinWallet(Settings.Instance.Host, Settings.Instance.Port, Settings.Instance.Username, Settings.Instance.RpcPassword); try { connectionOk = await testWallet.CheckConnection(Settings.Instance.RootDPOName); } catch (EmercoinWalletException ex) { } if (!connectionOk) { this.walletClose(walletApp); // wait and start wallet Action <Task> startNewWallet = (t) => { if (walletApp.IsExecuting()) { throw new SettingsWizardException("Emercoin wallet wasn't able to close in time"); } else { Process.Start(walletApp.FilePath); } }; await Task.Delay(15000).ContinueWith(startNewWallet); await Task.Delay(15000); } } else { var proc = await Task.Run(() => Process.Start(walletApp.FilePath)); await Task.Delay(15000); } // test wallet connection again var wallet = new EmercoinWallet(Settings.Instance.Host, Settings.Instance.Port, Settings.Instance.Username, Settings.Instance.RpcPassword); try { connectionOk = await wallet.CheckConnection(Settings.Instance.RootDPOName); this.StatusTextBlock.Text = "Connected successfully"; this.StatusTextBlock.Foreground = this.defaultColor; } catch (EmercoinWalletException ex) { throw new SettingsWizardException("Connection to the local wallet failed"); } bool walletLocked = true; bool pwdChecked = false; var walletInfo = await Task.Run(() => wallet.GetWalletInfo()); walletLocked = (walletInfo != null && walletInfo.locked) || !string.IsNullOrEmpty(Settings.Instance.WalletPassphrase); if (walletLocked) { pwdChecked = await wallet.CheckWalletPassphrase(Settings.Instance.WalletPassphrase); if (!pwdChecked) { throw new SettingsWizardException("Wallet passphrase check failed"); } } this.closeDisabled = false; this.success = connectionOk && (!walletLocked || pwdChecked); }