private async void ContentDialog_Closing(ContentDialog sender, ContentDialogClosingEventArgs args) { switch (args.Result) { case ContentDialogResult.Primary: //验证 var d = args.GetDeferral(); if (!await this.SignIn()) { args.Cancel = true; } d.Complete(); break; default: //当前未登录且点击取消 if (WebConnect.Current == null) { App.Current.Exit(); } break; } }
private async Task logOnAsync(ContentDialogClosingEventArgs args) { try { var username = this.tb_user.Text; var password = this.pb_pass.Password; if (string.IsNullOrWhiteSpace(username)) { this.tb_info.Text = Strings.Resources.Views.LogOnDialog.NoUserName; this.tb_user.Focus(FocusState.Programmatic); args.Cancel = true; } else if (string.IsNullOrEmpty(password)) { this.tb_info.Text = Strings.Resources.Views.LogOnDialog.NoPassword; this.pb_pass.Focus(FocusState.Programmatic); args.Cancel = true; } else { var d = args.GetDeferral(); try { this.tb_info.Text = ""; try { if (this.recap != null) { await this.recap.Submit(this.tb_ReCaptcha.Text); } } catch (Exception ex) { await loadReCapcha(); this.tb_info.Text = ex.GetMessage(); this.tb_ReCaptcha.Focus(FocusState.Programmatic); args.Cancel = true; return; } try { await Client.Current.LogOnAsync(username, password, this.recap); AccountManager.CurrentCredential = AccountManager.CreateCredential(username, password); } catch (InvalidOperationException ex) { await loadReCapcha(); this.tb_info.Text = ex.GetMessage(); this.tb_user.Focus(FocusState.Programmatic); args.Cancel = true; } catch (Exception ex) { this.tb_info.Text = ex.GetMessage(); this.tb_user.Focus(FocusState.Programmatic); args.Cancel = true; } } finally { d.Complete(); } } } finally { await Dispatcher.YieldIdle(); this.pb_Loading.IsIndeterminate = false; } }
ContentDialogClosingDeferral IContentDialogClosingEventArgsResolver.GetDeferral(ContentDialogClosingEventArgs e) => e.GetDeferral();