示例#1
0
 /// <summary>
 /// Executes <see cref="SqlDriverConfiguration.ConnectionInitializationSql"/> (if any).
 /// </summary>
 /// <param name="connection">Connection to initialize.</param>
 /// <param name="configuration">Driver configuration.</param>
 public static void ExecuteInitializationSql(DbConnection connection, SqlDriverConfiguration configuration)
 {
     if (string.IsNullOrEmpty(configuration.ConnectionInitializationSql))
     {
         return;
     }
     using (var command = connection.CreateCommand()) {
         command.CommandText = configuration.ConnectionInitializationSql;
         command.ExecuteNonQuery();
     }
 }
        /// <summary>
        /// Creates driver for the specified <paramref name="connectionInfo"/>
        /// and <paramref name="configuration"/>.
        /// </summary>
        /// <param name="connectionInfo">The connection info to create driver from.</param>
        /// <param name="configuration">Additional configuration options for the driver.</param>
        /// <returns>Created driver.</returns>
        public SqlDriver GetDriver(ConnectionInfo connectionInfo, SqlDriverConfiguration configuration)
        {
            ArgumentValidator.EnsureArgumentNotNull(connectionInfo, nameof(connectionInfo));
            ArgumentValidator.EnsureArgumentNotNull(configuration, nameof(configuration));

            var connectionString = GetConnectionString(connectionInfo);

            configuration = configuration.Clone();
            var driver = CreateDriver(connectionString, configuration);

            driver.Initialize(this, connectionInfo);
            return(driver);
        }
        /// <summary>
        /// Asynchronously creates driver for the specified <paramref name="connectionInfo"/>
        /// and <paramref name="configuration"/>.
        /// </summary>
        /// <remarks> Multiple active operations are not supported. Use <see langword="await"/>
        /// to ensure that all asynchronous operations have completed.</remarks>
        /// <param name="connectionInfo">The connection info to create driver from.</param>
        /// <param name="configuration">Additional configuration options for the driver.</param>
        /// <param name="token">The token to cancel asynchronous operation if needed.</param>
        /// <returns>Created driver.</returns>
        public async Task <SqlDriver> GetDriverAsync(
            ConnectionInfo connectionInfo, SqlDriverConfiguration configuration, CancellationToken token)
        {
            ArgumentValidator.EnsureArgumentNotNull(connectionInfo, nameof(connectionInfo));
            ArgumentValidator.EnsureArgumentNotNull(configuration, nameof(configuration));

            var connectionString = GetConnectionString(connectionInfo);

            configuration = configuration.Clone();
            var driver = await CreateDriverAsync(connectionString, configuration, token).ConfigureAwait(false);

            driver.Initialize(this, connectionInfo);
            return(driver);
        }
 /// <summary>
 /// Asynchronously creates the driver from the specified <paramref name="connectionString"/>.
 /// </summary>
 /// <remarks> Multiple active operations are not supported. Use <see langword="await"/>
 /// to ensure that all asynchronous operations have completed.</remarks>
 /// <param name="connectionString">The connection string to create driver from.</param>
 /// <param name="configuration">Additional configuration for the driver.</param>
 /// <param name="token">The token to cancel asynchronous operation if needed.</param>
 /// <returns>Created driver.</returns>
 protected abstract Task <SqlDriver> CreateDriverAsync(
     string connectionString, SqlDriverConfiguration configuration, CancellationToken token);
 /// <summary>
 /// Creates the driver from the specified <paramref name="connectionString"/>.
 /// </summary>
 /// <param name="connectionString">The connection string to create driver from.</param>
 /// <param name="configuration">Additional configuration for the driver.</param>
 /// <returns>Created driver.</returns>
 protected abstract SqlDriver CreateDriver(string connectionString, SqlDriverConfiguration configuration);