private async Task <IConnectionWithId <DbConnection> > GetOrCreateConnectionAsync(ConnectionFactoryParameters parameters, CancellationToken cancellationToken)
        {
            if (this._connection != null)
            {
                return(this._connection);
            }

            await this._connectionLock.WaitAsync(cancellationToken).ConfigureAwait(false);

            try
            {
                if (this._connection != null)
                {
                    return(this._connection);
                }
                var connection = this._factory.CreateConnection(parameters);
                await connection.Connection.OpenAsync(cancellationToken).ConfigureAwait(false);

                if (!string.IsNullOrWhiteSpace(this._overriddenDatabaseName))
                {
                    connection.Connection.ChangeDatabase(this._overriddenDatabaseName);
                }

                return(this._connection = connection);
            }
            finally
            {
                this._connectionLock.Release();
            }
        }
Ejemplo n.º 2
0
 public PooledConnection(IConnectionWithId <MySqlConnection> connectionWithId,
                         int indexInPool,
                         long payOutNumber)
 {
     this.ConnectionWithId = connectionWithId;
     this.IndexInPool      = indexInPool;
     this.PayOutNumber     = payOutNumber;
 }
 private void ReleaseUnmanagedResources()
 {
     this._connection?.Dispose();
     this._connection = null;
 }
Ejemplo n.º 4
0
 public void Deconstruct(out IConnectionWithId <MySqlConnection> connectionWithId, out int indexInPool, out long payOutNumber)
 {
     connectionWithId = this.ConnectionWithId;
     indexInPool      = this.IndexInPool;
     payOutNumber     = this.PayOutNumber;
 }