public IObservable <RecoveryOptionResult> Show(UserError userError) { IsBusy = false; var error = userError as TwoFactorRequiredUserError; Debug.Assert(error != null, String.Format(CultureInfo.InvariantCulture, "The user error is '{0}' not a TwoFactorRequiredUserError", userError)); InvalidAuthenticationCode = error.RetryFailed; TwoFactorType = error.TwoFactorType; var ok = OkCommand .Do(_ => IsBusy = true) .Select(_ => AuthenticationCode == null ? RecoveryOptionResult.CancelOperation : RecoveryOptionResult.RetryOperation) .Do(_ => error.ChallengeResult = AuthenticationCode != null ? new TwoFactorChallengeResult(AuthenticationCode) : null); var resend = ResendCodeCommand.Select(_ => RecoveryOptionResult.RetryOperation) .Do(_ => error.ChallengeResult = TwoFactorChallengeResult.RequestResendCode); var cancel = CancelCommand.Select(_ => RecoveryOptionResult.CancelOperation); return(Observable.Merge(ok, cancel, resend) .Take(1) .Do(_ => IsAuthenticationCodeSent = error.ChallengeResult == TwoFactorChallengeResult.RequestResendCode)); }
public IObservable <TwoFactorChallengeResult> Show(UserError userError) { Guard.ArgumentNotNull(userError, nameof(userError)); IsBusy = false; var error = userError as TwoFactorRequiredUserError; if (error == null) { throw new GitHubLogicException( String.Format( CultureInfo.InvariantCulture, "The user error is '{0}' not a TwoFactorRequiredUserError", userError)); } InvalidAuthenticationCode = error.RetryFailed; IsAuthenticationCodeSent = false; TwoFactorType = error.TwoFactorType; var ok = OkCommand .Do(_ => IsBusy = true) .Select(_ => AuthenticationCode == null ? null : new TwoFactorChallengeResult(AuthenticationCode)); var resend = ResendCodeCommand.Select(_ => RecoveryOptionResult.RetryOperation) .Select(_ => TwoFactorChallengeResult.RequestResendCode) .Do(_ => IsAuthenticationCodeSent = true); var cancel = this.WhenAnyValue(x => x.TwoFactorType) .Skip(1) .Where(x => x == TwoFactorType.None) .Select(_ => default(TwoFactorChallengeResult)); return(Observable.Merge(ok, cancel, resend).Take(1)); }