using System.Data; using Umbraco.Core.Persistence.FaultHandling; namespace Umbraco.Core.Persistence { /// /// Provides a set of extension methods adding retry capabilities into the standard interface, which is used in PetaPoco. /// public static class PetaPocoConnectionExtensions { /// /// Opens a database connection with the connection settings specified in the ConnectionString property of the connection object. /// Uses the default retry policy when opening the connection. /// /// The connection object that is required as per extension method declaration. public static void OpenWithRetry(this IDbConnection connection) { var connectionString = connection.ConnectionString ?? string.Empty; var retryPolicy = RetryPolicyFactory.GetDefaultSqlConnectionRetryPolicyByConnectionString(connectionString); OpenWithRetry(connection, retryPolicy); } /// /// Opens a database connection with the connection settings specified in the ConnectionString property of the connection object. /// Uses the specified retry policy when opening the connection. /// /// The connection object that is required as per extension method declaration. /// The retry policy defining whether to retry a request if the connection fails to be opened. public static void OpenWithRetry(this IDbConnection connection, RetryPolicy retryPolicy) { // Check if retry policy was specified, if not, use the default retry policy. (retryPolicy != null ? retryPolicy : RetryPolicy.NoRetry).ExecuteAction(connection.Open); } } }