/// <summary> /// Gets the command timeout. /// </summary> /// <param name="connectionString">The connection string.</param> /// <returns>The command timeout.</returns> private static int GetCommandTimeout(string connectionString) { var TimeoutMatch = ConnectionTimeoutRegex.Match(connectionString); return(TimeoutMatch.Success && int.TryParse(TimeoutMatch.Groups[2].Value, out var TempCommandTimeout) && TempCommandTimeout > 0 ? TempCommandTimeout : 30); }
/// <summary> /// Constructor /// </summary> /// <param name="configuration">The configuration.</param> /// <param name="factory">The factory.</param> /// <param name="connection">The connection.</param> /// <param name="name">The name.</param> /// <param name="parameterPrefix">The parameter prefix.</param> /// <param name="retries">The retries.</param> /// <exception cref="System.ArgumentNullException">configuration</exception> public Connection(IConfiguration configuration, DbProviderFactory factory, string connection, string name, string parameterPrefix = "@", int retries = 0) { Retries = retries; Configuration = configuration ?? throw new ArgumentNullException(nameof(configuration)); Name = string.IsNullOrEmpty(name) ? "Default" : name; Factory = factory ?? SqlClientFactory.Instance; SourceType = Factory.GetType().FullName ?? string.Empty; var TempConfig = configuration.GetConnectionString(Name); ConnectionString = !string.IsNullOrEmpty(connection) ? connection : (TempConfig ?? Name); if (string.IsNullOrEmpty(parameterPrefix)) { if (Factory is SqlClientFactory) { DatabaseName = DatabaseNameRegex.Match(ConnectionString).Groups[1].Value; ParameterPrefix = "@"; } else if (SourceType.Contains("Oracle", StringComparison.OrdinalIgnoreCase)) { ParameterPrefix = ":"; } } else { ParameterPrefix = parameterPrefix; if (Factory is SqlClientFactory) { DatabaseName = DatabaseNameRegex.Match(ConnectionString).Groups[1].Value; } } if (ConnectionTimeoutRegex.IsMatch(ConnectionString)) { var TimeoutValue = ConnectionTimeoutRegex.Match(ConnectionString).Groups[2].Value; CommandTimeout = int.TryParse(TimeoutValue, out var TempCommandTimeout) ? TempCommandTimeout : 30; } CommandTimeout = CommandTimeout <= 0 ? 30 : CommandTimeout; }