private async Task <T> GetConfiguration(RelyingPartyContext context, CancellationToken cancel) { var now = DateTimeOffset.UtcNow; T currentConfiguration; if (ConfigurationManager <T> ._congigurationCache.TryGetValue(context.RelyingPartyId, 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.MetadataAddress, CancellationToken.None).ConfigureAwait(false); currentConfiguration = obj; configurationManager = null; obj = default(T); context.LastRefresh = now; context.SyncAfter = DataTimeExtensions.Add(now.UtcDateTime, context.AutomaticRefreshInterval); } 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); } } ConfigurationManager <T> ._congigurationCache.TryAdd(context.RelyingPartyId, currentConfiguration); return(currentConfiguration); } finally { this._refreshLock.Release(); } }
public RelyingPartyContext BuildRelyingPartyContext(string relyingPartyId) { if (this._cacheProvider.Contains(relyingPartyId)) { return(this._cacheProvider.Get <RelyingPartyContext>(relyingPartyId)); } var relyingPartyContext = this._dbContext.Set <RelyingPartySettings>() .FirstOrDefault(x => x.RelyingPartyId == relyingPartyId); var context = new RelyingPartyContext(relyingPartyId, relyingPartyContext.MetadataPath); context.RefreshInterval = TimeSpan.FromSeconds(relyingPartyContext.RefreshInterval); context.AutomaticRefreshInterval = TimeSpan.FromDays(relyingPartyContext.AutoRefreshInterval); object policy = new MemoryCacheItemPolicy(); ((ICacheItemPolicy)policy).SlidingExpiration = TimeSpan.FromDays(1); this._cacheProvider.Put(relyingPartyId, context, (ICacheItemPolicy)policy); return(context); }
public RelyingPartyContext BuildRelyingPartyContext(string relyingPartyId) { var context = new RelyingPartyContext(relyingPartyId, "C:\\"); return(context); }