private async Task <T> GetConfiguration(FederationPartyConfiguration context, CancellationToken cancel) { if (context == null) { throw new ArgumentNullException(nameof(context)); } var now = DateTimeOffset.UtcNow; T currentConfiguration; if (ConfigurationManager <T> ._congigurationCache.TryGetValue(context.FederationPartyId, out currentConfiguration)) { if (context.SyncAfter > now) { return(currentConfiguration); } } await this._refreshLock.WaitAsync(cancel); try { if (context.SyncAfter <= now) { try { ConfigurationManager <T> configurationManager = this; T obj = await this._configRetriever.GetAsync(context, CancellationToken.None) .ConfigureAwait(true); currentConfiguration = obj; configurationManager = null; obj = default(T); context.LastRefresh = now; context.SyncAfter = DataTimeExtensions.Add(now.UtcDateTime, context.AutomaticRefreshInterval); ConfigurationManager <T> ._congigurationCache.TryAdd(context.FederationPartyId, currentConfiguration); } catch (Exception ex) { context.SyncAfter = DataTimeExtensions.Add(now.UtcDateTime, context.AutomaticRefreshInterval < context.RefreshInterval ? context.AutomaticRefreshInterval : context.RefreshInterval); throw new InvalidOperationException(String.Format("IDX10803: Unable to obtain configuration from: '{0}'.", (context.MetadataAddress ?? "null")), ex); } } return(currentConfiguration); } finally { this._refreshLock.Release(); } }
public void RequestRefresh(string relyingPartyId) { var context = this._relyingPartyContextBuilder.BuildRelyingPartyContext(relyingPartyId); var utcNow = DateTimeOffset.UtcNow; if (!(utcNow >= DataTimeExtensions.Add(context.LastRefresh.UtcDateTime, context.RefreshInterval))) { return; } context.SyncAfter = utcNow; }