private void SaveSetting(string token) { IMonkeyService _monkeyService = new MonkeyService(); IConfigService _configService = new ConfigService(); IAppService _appService = new AppService(); try { var user = _monkeyService.GetUserInfo(token); if (user == null || user.otc == null) { textBox_token.Enabled = button_save.Enabled = true; MessageBox.Show("验证失败,请检查token是否正确!"); label_result.Text = "配置失败×"; label_result.ForeColor = Color.Red; return; } var config = _configService.ReadConfig(); config.Token = token; config.Wallet = user.otc; _configService.Save(config); var hnbc_token = _appService.Login(user.otc, user.nickName); textBox_token.Enabled = button_save.Enabled = true; if (hnbc_token == null) { MessageBox.Show("连接服务器失败,部分功能将无法使用!"); label_result.Text = "配置失败×"; label_result.ForeColor = Color.Red; return; } config.ServerToken = hnbc_token.accessToken; config.UserConfig = hnbc_token.userConfig; _configService.Save(config); MessageBox.Show("配置成功!请重新打开软件!"); label_result.Text = "配置成功√"; label_result.ForeColor = Color.Lime; }catch (Exception ex) { textBox_token.Enabled = button_save.Enabled = true; label_result.Text = "配置失败×"; label_result.ForeColor = Color.Red; MessageBox.Show("配置失败,原因:" + ex.Message); } }
public override Task InitializeAsync(object navigationData) { Monkeys = MonkeyService.GetMonkeys(); return base.InitializeAsync(navigationData); }