private static SqlRetryLogicBaseProvider CreateRetryLogicProvider(string sectionName, ISqlConfigurableRetryConnectionSection configSection) { string methodName = MethodBase.GetCurrentMethod().Name; SqlClientEventSource.Log.TryTraceEvent("<sc.{0}.{1}|INFO> Entry point.", TypeName, methodName); try { if (configSection == null) { throw SqlReliabilityUtil.ArgumentNull(nameof(configSection)); } // Create a SqlRetryLogicOption object from the discovered retry logic values var retryOption = new SqlRetryLogicOption() { NumberOfTries = configSection.NumberOfTries, DeltaTime = configSection.DeltaTime, MinTimeInterval = configSection.MinTimeInterval, MaxTimeInterval = configSection.MaxTimeInterval }; // Prepare the transient error lists if (!string.IsNullOrEmpty(configSection.TransientErrors)) { retryOption.TransientErrors = configSection.TransientErrors.Split(',').Select(x => Convert.ToInt32(x)).ToList(); } // Prepare the authorized SQL statement just for SqlCommands if (configSection is ISqlConfigurableRetryCommandSection cmdSection && !string.IsNullOrEmpty(cmdSection.AuthorizedSqlCondition)) { retryOption.AuthorizedSqlCondition = (x) => Regex.IsMatch(x, cmdSection.AuthorizedSqlCondition); } SqlClientEventSource.Log.TryTraceEvent("<sc.{0}.{1}|INFO> Successfully created a {2} object to use on creating a retry logic provider from the section '{3}'.", TypeName, methodName, nameof(SqlRetryLogicOption), sectionName); // Extract the SqlRetryLogicBaseProvider object from the given information var provider = ResolveRetryLogicProvider(configSection.RetryLogicType, configSection.RetryMethod, retryOption); SqlClientEventSource.Log.TryTraceEvent("<sc.{0}.{1}|INFO> Successfully created a {2} object from the section '{3}'.", TypeName, methodName, nameof(SqlRetryLogicBaseProvider), sectionName); return(provider); } catch (Exception e) { SqlClientEventSource.Log.TryTraceEvent("<sc.{0}.{1}|INFO> {2}", TypeName, methodName, e); } SqlClientEventSource.Log.TryTraceEvent("<sc.{0}.{1}|INFO> Due to an exception, the default non-retriable logic will be applied.", TypeName, methodName); // Return default provider if an exception occured. return(SqlConfigurableRetryFactory.CreateNoneRetryProvider()); }
/// <summary> /// The default non retry provider will apply if a parameter passes by null. /// </summary> private void AssignProviders(SqlRetryLogicBaseProvider cnnProvider = null, SqlRetryLogicBaseProvider cmdProvider = null) { ConnectionProvider = cnnProvider ?? SqlConfigurableRetryFactory.CreateNoneRetryProvider(); CommandProvider = cmdProvider ?? SqlConfigurableRetryFactory.CreateNoneRetryProvider(); }