public SqlConfigurableRetryLogicLoader(ISqlConfigurableRetryConnectionSection connectionRetryConfigs, ISqlConfigurableRetryCommandSection commandRetryConfigs, string cnnSectionName = SqlConfigurableRetryConnectionSection.Name, string cmdSectionName = SqlConfigurableRetryCommandSection.Name) { #if !NETFRAMEWORK // Just only one subscription to this event is required. // This class isn't supposed to be called more than one time; // SqlConfigurableRetryLogicManager manages a single instance of this class. System.Runtime.Loader.AssemblyLoadContext.Default.Resolving -= Default_Resolving; System.Runtime.Loader.AssemblyLoadContext.Default.Resolving += Default_Resolving; #endif AssignProviders(connectionRetryConfigs == null ? null : CreateRetryLogicProvider(cnnSectionName, connectionRetryConfigs), commandRetryConfigs == null ? null : CreateRetryLogicProvider(cmdSectionName, commandRetryConfigs)); }
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 { // 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()); }