Skip to content

Commit

Permalink
Update internal APIs to align with .NET 8.0 convention.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dixin committed Jan 25, 2024
1 parent d6a2e91 commit 011f5c5
Show file tree
Hide file tree
Showing 30 changed files with 201 additions and 202 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public static class RetryManagerCachingExtensions
/// <summary>
/// The technology name that can be used to get the default Caching retry strategy name.
/// </summary>
public const string DefaultStrategyTechnologyName = "Caching";
public const string DefaultStrategyTechnologyName = nameof(Caching);

/// <summary>
/// Returns the default retry strategy for Windows Azure Caching.
Expand All @@ -19,27 +19,27 @@ public static class RetryManagerCachingExtensions
[Obsolete("Use GetDefaultCachingRetryStrategy instead.")]
[EditorBrowsable(EditorBrowsableState.Never)]
public static RetryStrategy GetDefaultAzureCachingRetryStrategy(this RetryManager retryManager) =>
retryManager.NotNull().GetDefaultRetryStrategy(DefaultStrategyTechnologyName);
retryManager.ThrowIfNull().GetDefaultRetryStrategy(DefaultStrategyTechnologyName);

/// <summary>
/// Returns the default retry policy dedicated to handling transient conditions with Windows Azure Caching.
/// </summary>
/// <returns>The retry policy for Windows Azure Caching with the corresponding default strategy (or the default strategy if no retry strategy definition assigned to Windows Azure Caching was found).</returns>
[Obsolete("Use GetDefaultCachingRetryPolicy instead.")]
public static RetryPolicy GetDefaultAzureCachingRetryPolicy(this RetryManager retryManager) =>
new (new CacheTransientErrorDetectionStrategy(), retryManager.NotNull().GetDefaultCachingRetryStrategy());
new (new CacheTransientErrorDetectionStrategy(), retryManager.ThrowIfNull().GetDefaultCachingRetryStrategy());

/// <summary>
/// Returns the default retry strategy for Windows Azure Caching.
/// </summary>
/// <returns>The default Windows Azure Caching retry strategy (or the default strategy if no default could be found for Windows Azure Caching).</returns>
public static RetryStrategy GetDefaultCachingRetryStrategy(this RetryManager retryManager) =>
retryManager.NotNull().GetDefaultRetryStrategy(DefaultStrategyTechnologyName);
retryManager.ThrowIfNull().GetDefaultRetryStrategy(DefaultStrategyTechnologyName);

/// <summary>
/// Returns the default retry policy dedicated to handling transient conditions with Windows Azure Caching.
/// </summary>
/// <returns>The retry policy for Windows Azure Caching with the corresponding default strategy (or the default strategy if no retry strategy definition for Windows Azure Caching was found).</returns>
public static RetryPolicy GetDefaultCachingRetryPolicy(this RetryManager retryManager) =>
new (new CacheTransientErrorDetectionStrategy(), retryManager.NotNull().GetDefaultCachingRetryStrategy());
new (new CacheTransientErrorDetectionStrategy(), retryManager.ThrowIfNull().GetDefaultCachingRetryStrategy());
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static class ConfigurationExtensions
string key = RetryConfiguration.DefaultConfigurationKeyRetryStrategy,
Func<IConfigurationSection, RetryStrategy>? getCustomRetryStrategy = null)
{
IConfigurationSection section = configuration.NotNull().GetSection(key.NotNullOrEmpty());
IConfigurationSection section = configuration.ThrowIfNull().GetSection(key.ThrowIfNullOrEmpty());
return section.Exists()
? section.GetRetryStrategies(getCustomRetryStrategy)
: throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, Resources.ConfigurationKeyNotFOund, key), nameof(key));
Expand All @@ -42,7 +42,7 @@ public static class ConfigurationExtensions
public static IDictionary<string, RetryStrategy> GetRetryStrategies(
this IConfigurationSection configurationSection,
Func<IConfigurationSection, RetryStrategy>? getCustomRetryStrategy = null) =>
configurationSection.NotNull().Exists()
configurationSection.ThrowIfNull().Exists()
? configurationSection.GetChildren().ToDictionary(
childSection => childSection.Key,
childSection => childSection.GetRetryStrategy(getCustomRetryStrategy))
Expand All @@ -54,7 +54,7 @@ public static class ConfigurationExtensions
/// <returns>The retry strategy. </returns>
public static RetryStrategy GetRetryStrategy(this IConfigurationSection configurationSection, Func<IConfigurationSection, RetryStrategy>? getCustomRetryStrategy = null)
{
if (!configurationSection.NotNull().Exists())
if (!configurationSection.ThrowIfNull().Exists())
{
throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, Resources.ConfigurationSectionNotExist, configurationSection.Path), nameof(configurationSection));
}
Expand All @@ -74,7 +74,7 @@ public static RetryStrategy GetRetryStrategy(this IConfigurationSection configur
/// <returns>The retry strategy. </returns>
public static FixedInterval GetFixedInterval(this IConfigurationSection configurationSection)
{
if (!configurationSection.NotNull().Exists())
if (!configurationSection.ThrowIfNull().Exists())
{
throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, Resources.ConfigurationSectionNotExist, configurationSection.Path), nameof(configurationSection));
}
Expand All @@ -92,7 +92,7 @@ public static FixedInterval GetFixedInterval(this IConfigurationSection configur
/// <returns>The retry strategy. </returns>
public static Incremental GetIncremental(this IConfigurationSection configurationSection)
{
if (!configurationSection.NotNull().Exists())
if (!configurationSection.ThrowIfNull().Exists())
{
throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, Resources.ConfigurationSectionNotExist, configurationSection.Path), nameof(configurationSection));
}
Expand All @@ -110,7 +110,7 @@ public static Incremental GetIncremental(this IConfigurationSection configuratio
/// <returns>The retry strategy. </returns>
public static ExponentialBackoff GetExponentialBackoff(this IConfigurationSection configurationSection)
{
if (!configurationSection.NotNull().Exists())
if (!configurationSection.ThrowIfNull().Exists())
{
throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, Resources.ConfigurationSectionNotExist, configurationSection.Path), nameof(configurationSection));
}
Expand Down Expand Up @@ -138,7 +138,7 @@ public static ExponentialBackoff GetExponentialBackoff(this IConfigurationSectio
where TRetryStrategy : RetryStrategy
{
Func<IConfigurationSection, RetryStrategy>? covariance = getCustomRetryStrategy;
return GetRetryStrategies(configuration.NotNull(), key.NotNullOrEmpty(), covariance)
return GetRetryStrategies(configuration.ThrowIfNull(), key.ThrowIfNullOrEmpty(), covariance)
.Where(pair => pair.Value is not null and TRetryStrategy)
.ToDictionary(pair => pair.Key, pair => (TRetryStrategy)pair.Value);
}
Expand All @@ -155,7 +155,7 @@ public static ExponentialBackoff GetExponentialBackoff(this IConfigurationSectio
string key = RetryConfiguration.DefaultConfigurationKeyRetryManager,
Func<IConfigurationSection, RetryStrategy>? getCustomRetryStrategy = null)
{
IConfigurationSection section = configuration.NotNull().GetSection(key.NotNullOrEmpty());
IConfigurationSection section = configuration.ThrowIfNull().GetSection(key.ThrowIfNullOrEmpty());
return section.Exists()
? section.GetRetryManager(getCustomRetryStrategy)
: throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, Resources.ConfigurationKeyNotFOund, key), nameof(key));
Expand All @@ -170,7 +170,7 @@ public static ExponentialBackoff GetExponentialBackoff(this IConfigurationSectio
public static RetryManager GetRetryManager(
this IConfigurationSection configurationSection,
Func<IConfigurationSection, RetryStrategy>? getCustomRetryStrategy = null) =>
configurationSection.NotNull().Exists()
configurationSection.ThrowIfNull().Exists()
? configurationSection.Get<RetryManagerOptions>(buildOptions => buildOptions.BindNonPublicProperties = true).ToRetryManager(getCustomRetryStrategy)
: throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, Resources.ConfigurationSectionNotExist, configurationSection.Path), nameof(configurationSection));
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static class RetryConfiguration
string configurationFile = DefaultConfigurationFile,
string configurationKey = DefaultConfigurationKeyRetryStrategy,
Func<IConfigurationSection, RetryStrategy>? getCustomRetryStrategy = null) =>
GetConfiguration(configurationFile.NotNullOrEmpty()).GetRetryStrategies(configurationKey.NotNullOrEmpty(), getCustomRetryStrategy);
GetConfiguration(configurationFile.ThrowIfNullOrEmpty()).GetRetryStrategies(configurationKey.ThrowIfNullOrEmpty(), getCustomRetryStrategy);

/// <summary>
/// ets the retry manager from the specified configuration file and key.
Expand All @@ -44,14 +44,14 @@ public static class RetryConfiguration
string configurationFile = DefaultConfigurationFile,
string configurationKey = DefaultConfigurationKeyRetryManager,
Func<IConfigurationSection, RetryStrategy>? getCustomRetryStrategy = null) =>
GetConfiguration(configurationFile.NotNullOrEmpty()).GetRetryManager(configurationKey.NotNullOrEmpty(), getCustomRetryStrategy);
GetConfiguration(configurationFile.ThrowIfNullOrEmpty()).GetRetryManager(configurationKey.ThrowIfNullOrEmpty(), getCustomRetryStrategy);

/// <summary>Gets the configuration from the specified file.</summary>
/// <param name="configurationFile">The specified configuration file.</param>
/// <returns>The configuration.</returns>
public static IConfiguration GetConfiguration(string configurationFile = DefaultConfigurationFile)
{
configurationFile.NotNullOrEmpty();
configurationFile.ThrowIfNullOrEmpty();

IConfigurationBuilder builder = new ConfigurationBuilder();
builder = Path.GetExtension(configurationFile).ToUpperInvariant() switch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public static class RetryManagerOptionsExtensions
/// <returns></returns>
public static RetryManager ToRetryManager(this RetryManagerOptions options, Func<IConfigurationSection, RetryStrategy>? getCustomRetryStrategy = null)
{
if (options.NotNull().RetryStrategy is null || !options.RetryStrategy.Exists())
if (options.ThrowIfNull().RetryStrategy is null || !options.RetryStrategy.Exists())
{
throw new ArgumentException(Resources.RetryStrategySectionNotFoundInRetryManager, nameof(options));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static class RetryPolicyFactory
public static RetryManager CreateDefault(
string configurationFile = RetryConfiguration.DefaultConfigurationFile, string configurationKey = nameof(RetryManager), Func<IConfigurationSection, RetryStrategy>? getCustomRetryStrategy = null)
{
RetryManager manager = RetryConfiguration.GetRetryManager(configurationFile.NotNullOrEmpty(), configurationKey.NotNullOrEmpty(), getCustomRetryStrategy);
RetryManager manager = RetryConfiguration.GetRetryManager(configurationFile.ThrowIfNullOrEmpty(), configurationKey.ThrowIfNullOrEmpty(), getCustomRetryStrategy);
RetryManager.SetDefault(manager);
return manager;
}
Expand All @@ -33,7 +33,7 @@ public static class RetryPolicyFactory
[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate", Justification = "As designed")]
public static RetryPolicy GetDefaultSqlConnectionRetryPolicy(
string configurationFile = RetryConfiguration.DefaultConfigurationFile, string configurationKey = nameof(RetryManager), Func<IConfigurationSection, RetryStrategy>? getCustomRetryStrategy = null) =>
GetOrCreateRetryManager(configurationKey.NotNullOrEmpty(), configurationKey, getCustomRetryStrategy)
GetOrCreateRetryManager(configurationKey.ThrowIfNullOrEmpty(), configurationKey, getCustomRetryStrategy)
.GetDefaultSqlConnectionRetryPolicy();

/// <summary>
Expand All @@ -43,7 +43,7 @@ public static class RetryPolicyFactory
[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate", Justification = "As designed")]
public static RetryPolicy GetDefaultSqlCommandRetryPolicy(
string configurationFile = RetryConfiguration.DefaultConfigurationFile, string configurationKey = nameof(RetryManager), Func<IConfigurationSection, RetryStrategy>? getCustomRetryStrategy = null) =>
GetOrCreateRetryManager(configurationFile.NotNullOrEmpty(nameof(configurationFile)), configurationKey.NotNullOrEmpty(), getCustomRetryStrategy)
GetOrCreateRetryManager(configurationFile.ThrowIfNullOrEmpty(nameof(configurationFile)), configurationKey.ThrowIfNullOrEmpty(), getCustomRetryStrategy)
.GetDefaultSqlCommandRetryPolicy();

// TODO.
Expand Down Expand Up @@ -86,7 +86,7 @@ public static class RetryPolicyFactory
public static RetryPolicy GetRetryPolicy<T>(
string configurationFile = RetryConfiguration.DefaultConfigurationFile, string configurationKey = nameof(RetryManager), Func<IConfigurationSection, RetryStrategy>? getCustomRetryStrategy = null)
where T : ITransientErrorDetectionStrategy, new() =>
GetOrCreateRetryManager(configurationFile.NotNullOrEmpty(), configurationKey.NotNullOrEmpty(), getCustomRetryStrategy)
GetOrCreateRetryManager(configurationFile.ThrowIfNullOrEmpty(), configurationKey.ThrowIfNullOrEmpty(), getCustomRetryStrategy)
.GetRetryPolicy<T>();

/// <summary>
Expand All @@ -102,7 +102,7 @@ public static class RetryPolicyFactory
string configurationFile = RetryConfiguration.DefaultConfigurationFile,
string configurationKey = nameof(RetryManager),
Func<IConfigurationSection, RetryStrategy>? getCustomRetryStrategy = null) =>
GetOrCreateRetryManager(configurationFile.NotNullOrEmpty(), configurationKey.NotNullOrEmpty(), getCustomRetryStrategy).GetRetryPolicy(errorDetectionStrategy.NotNull());
GetOrCreateRetryManager(configurationFile.ThrowIfNullOrEmpty(), configurationKey.ThrowIfNullOrEmpty(), getCustomRetryStrategy).GetRetryPolicy(errorDetectionStrategy.ThrowIfNull());

/// <summary>
/// Returns an instance of the <see cref="RetryPolicy"/> object for a given error detection strategy and retry strategy.
Expand All @@ -119,7 +119,7 @@ public static class RetryPolicyFactory
string configurationFile = RetryConfiguration.DefaultConfigurationFile,
string configurationKey = nameof(RetryManager),
Func<IConfigurationSection, RetryStrategy>? getCustomRetryStrategy = null) where T : ITransientErrorDetectionStrategy, new() =>
GetOrCreateRetryManager(configurationFile.NotNullOrEmpty(), configurationKey.NotNullOrEmpty(), getCustomRetryStrategy).GetRetryPolicy<T>(retryStrategyName.NotNullOrEmpty());
GetOrCreateRetryManager(configurationFile.ThrowIfNullOrEmpty(), configurationKey.ThrowIfNullOrEmpty(), getCustomRetryStrategy).GetRetryPolicy<T>(retryStrategyName.ThrowIfNullOrEmpty());

/// <summary>
/// Returns an instance of the <see cref="RetryPolicy"/> object for a given error detection strategy and retry strategy.
Expand All @@ -137,7 +137,7 @@ public static class RetryPolicyFactory
string configurationFile = RetryConfiguration.DefaultConfigurationFile,
string configurationKey = nameof(RetryManager),
Func<IConfigurationSection, RetryStrategy>? getCustomRetryStrategy = null) =>
GetOrCreateRetryManager(configurationFile.NotNullOrEmpty(), configurationKey.NotNullOrEmpty(), getCustomRetryStrategy).GetRetryPolicy(retryStrategyName.NotNullOrEmpty(), errorDetectionStrategy.NotNull());
GetOrCreateRetryManager(configurationFile.ThrowIfNullOrEmpty(), configurationKey.ThrowIfNullOrEmpty(), getCustomRetryStrategy).GetRetryPolicy(retryStrategyName.ThrowIfNullOrEmpty(), errorDetectionStrategy.ThrowIfNull());

private static RetryManager GetOrCreateRetryManager(
string configurationFile, string configurationKey, Func<IConfigurationSection, RetryStrategy>? getCustomRetryStrategy = null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public FixedIntervalOptions() : this(true, default, default)
public int RetryCount
{
get => this.retryCount;
init => this.retryCount = value.NotNegative();
init => this.retryCount = value.ThrowIfNegative();
}

/// <summary>
Expand All @@ -38,7 +38,7 @@ public int RetryCount
public TimeSpan RetryInterval
{
get => this.retryInterval;
init => this.retryInterval = value.NotNegative();
init => this.retryInterval = value.ThrowIfNegative();
}
}

Expand Down Expand Up @@ -66,7 +66,7 @@ public IncrementalOptions() : this(true, default, default, default)
public int RetryCount
{
get => this.retryCount;
init => this.retryCount = value.NotNegative();
init => this.retryCount = value.ThrowIfNegative();
}

/// <summary>
Expand All @@ -75,7 +75,7 @@ public int RetryCount
public TimeSpan InitialInterval
{
get => this.initialInterval;
init => this.initialInterval = value.NotNegative();
init => this.initialInterval = value.ThrowIfNegative();
}

/// <summary>
Expand All @@ -84,7 +84,7 @@ public TimeSpan InitialInterval
public TimeSpan Increment
{
get => this.increment;
init => this.increment = value.NotNegative();
init => this.increment = value.ThrowIfNegative();
}
}

Expand Down Expand Up @@ -115,7 +115,7 @@ public ExponentialBackoffOptions() : this(true, default, default, default, defau
public int RetryCount
{
get => this.retryCount;
init => this.retryCount = value.NotNegative();
init => this.retryCount = value.ThrowIfNegative();
}

/// <summary>
Expand All @@ -124,7 +124,7 @@ public int RetryCount
public TimeSpan MinBackOff
{
get => this.minBackOff;
init => this.minBackOff = value.NotNegative();
init => this.minBackOff = value.ThrowIfNegative();
}

/// <summary>
Expand All @@ -133,7 +133,7 @@ public TimeSpan MinBackOff
public TimeSpan MaxBackOff
{
get => this.maxBackOff;
init => this.maxBackOff = value.NotNegative();
init => this.maxBackOff = value.ThrowIfNegative();
}

/// <summary>
Expand All @@ -142,6 +142,6 @@ public TimeSpan MaxBackOff
public TimeSpan DeltaBackOff
{
get => this.deltaBackOff;
init => this.deltaBackOff = value.NotNegative();
init => this.deltaBackOff = value.ThrowIfNegative();
}
}
Loading

0 comments on commit 011f5c5

Please sign in to comment.