async Task <RegisterOperationResult?> TryOneRequest(IKey key, KeyRegisterRequest request, CancellationToken cancellationToken) { try { var result = await key.RegisterAsync(request, cancellationToken); log.Info(result.Status.ToString()); switch (result.Status) { case KeyResponseStatus.Success: return(RegisterOperationResult.Success(request, result.Data)); } } catch (KeyGoneException) { // No sense in continuing with this signer, the key isn't physically present anymore log.DebugFormat("Key '{0}' is gone", keyId); throw; } catch (TaskCanceledException) { // Let cancellation bubble up throw; } catch (KeyBusyException) { // Maybe it won't be busy later } catch (Exception exception) { log.Error("Authenticate request failed", exception); } return(null); }
async Task <RegisterOperationResult?> TryRegisteringOnceAsync(IKey key, CancellationToken cancellationToken) { int challengesTried = 0; foreach (var request in requests) { challengesTried += 1; var requestSignResult = await TryOneRequest(key, request, cancellationToken); if (requestSignResult.HasValue) { return(requestSignResult.Value); } } if (challengesTried == 0) { return(RegisterOperationResult.Failure(KeyResponseStatus.Failure)); } return(null); }