in aspnet/Microsoft.Samples.XMLA.HTTP/Microsoft.Samples.XMLA.HTTP.Proxy/ConnectionPool.cs [96:144]
public ConnectionPoolEntry GetConnection(string connectionString, AuthData authData)
{
var key = connectionString;
ConnectionPoolEntry rv = null;
avalableConnections.AddOrUpdate(key, k => new ConcurrentStack<ConnectionPoolEntry>(), (k, c) =>
{
while (c.TryPop( out var entry ))
{
//if we discover that the entry has expired, dispose of it
//this typically happens when the entry uses BEARER auth and its token
//has expired (or is about to).
if ( DateTime.Now > entry.ValidTo.Subtract(TimeSpan.FromMinutes(1)) )
{
entry.Connection.Dispose();
continue;
}
rv = entry;
break;
}
return c;
});
if (rv == null)
{
var con = new AdomdConnection(connectionString);
rv = new ConnectionPoolEntry(con, connectionString);
var validTo = DateTime.Now.AddMinutes(5); //default
if (authData.Scheme == AuthScheme.BEARER)
{
var token = tokenHelper.ReadToken(authData.PasswordOrToken);
if (validTo > token.ValidTo.ToLocalTime())
{
validTo = token.ValidTo.ToLocalTime();
}
}
rv.ValidTo = validTo;
con.Open();
}
rv.RecordCheckOut();
return rv;
}