async Task <IEnumerable <NetworkEndpoint> > RefreshStaleEndpoints(IEnumerable <NetworkEndpoint> stale) { var refreshing = stale.Select(async(NetworkEndpoint oldState) => { var newState = oldState; try { newState = await refresher.Refresh(oldState); log.LogInformation("Refreshed NetworkEndpoint. Endpoint:{@Endpoint}", newState); var updated = await endpointManager.UpdateEndpointAsync(newState); newState = updated; if (newState != null) { cache.Put(newState); } log.LogInformation("Updated NetworkEndpoint. Old:{@{Old} New:{@New}", oldState, newState); } catch (HttpRequestException hre) { log.LogError("Failed to refresh NetworkEndpoint. Endpoint:{@Endpoint} Error:{Error}", oldState, hre.Message); } catch (DbException se) { log.LogError("Failed to update NetworkEndpoint. Old:{@Old} New:{@New} Error:{Error}", oldState, newState, se.Message); cache.PopOrDefault(oldState.Issuer); } return(newState); }); return(await Task.WhenAll(refreshing)); }
async Task <IEnumerable <NetworkEndpoint> > RefreshStaleEndpoints(IEnumerable <NetworkEndpoint> stale) { var refreshing = stale.Select(async(NetworkEndpoint oldState) => { var newState = oldState; try { newState = await refresher.Refresh(oldState); log.LogInformation("Refreshed NetworkEndpoint. Endpoint:{@Endpoint}", newState); cache.Put(newState); await endpointService.UpdateAsync(newState); log.LogInformation("Updated NetworkEndpoint. Old:{@{Old} New:{@New}", oldState, newState); } catch (HttpRequestException hre) { log.LogError("Could not refresh NetworkEndpoint. Endpoint:{@Endpoint} Error:{Error}", oldState, hre.Message); } catch (SqlException se) { log.LogError("Could not update NetworkEndpoint. Old:{@Old} New:{@New} Error:{Error}", oldState, newState, se.Message); } return(newState); }); return(await Task.WhenAll(refreshing)); }
public async Task <NetworkEndpoint> UpdateEndpointAsync(NetworkEndpoint e) { Ensure.NotNull(e, nameof(e)); Ensure.NotNullOrWhitespace(e.Name, nameof(e.Name)); validator.Validate(e); Ensure.NotNullOrWhitespace(e.Issuer, nameof(e.Issuer)); Ensure.NotNullOrWhitespace(e.KeyId, nameof(e.KeyId)); Ensure.NotNull(e.Certificate, nameof(e.Certificate)); var updated = await updater.UpdateEndpointAsync(e); cache.Put(updated); log.LogInformation("Updated NetworkEndpoint. Result:{@Result}", updated); return(updated); }