Skip to content

Commit

Permalink
Remove System.Configuration.ConfigurationManager package reference
Browse files Browse the repository at this point in the history
  • Loading branch information
lahma committed Aug 10, 2024
1 parent 06545bc commit 0f62d32
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ protected override IDbConnectionManager GetDBConnectionManager()
return serviceProvider.GetRequiredService<IDbConnectionManager>();
}

private protected override string GetNamedConnectionString(string connectionStringName)
protected override string? GetNamedConnectionString(string connectionStringName)
{
var configuration = serviceProvider.GetRequiredService<IConfiguration>();
var connectionString = configuration.GetConnectionString(connectionStringName);
Expand Down
30 changes: 25 additions & 5 deletions src/Quartz/Impl/StdSchedulerFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Configuration;
using System.IO;
using System.Reflection;
using System.Threading;
Expand Down Expand Up @@ -265,7 +264,7 @@ public virtual void Initialize()

internal static NameValueCollection? InitializeProperties(ILog logger, bool throwOnProblem)
{
var props = Util.Configuration.GetSection(ConfigurationSectionName);
var props = ReadConfigurationSection();
var requestedFile = QuartzEnvironment.GetEnvironmentVariable(PropertiesFile);
var propFileName = !string.IsNullOrWhiteSpace(requestedFile) ? requestedFile : "~/quartz.config";

Expand Down Expand Up @@ -313,6 +312,23 @@ public virtual void Initialize()
return props;
}

private static NameValueCollection? ReadConfigurationSection()
{
#if NETFRAMEWORK
try
{
return (NameValueCollection) System.Configuration.ConfigurationManager.GetSection(ConfigurationSectionName);
}
catch (Exception e)
{
var log = LogProvider.GetLogger(typeof(StdSchedulerFactory));
log.Warn($"Could not read configuration using ConfigurationManager.GetSection: {e.Message}");
}
#endif
return null;

}

/// <summary>
/// Creates a new name value collection and overrides its values
/// with system values (environment variables).
Expand Down Expand Up @@ -820,7 +836,7 @@ private async Task<IScheduler> Instantiate()
ISchedulerPlugin plugin;
try
{
var pluginTypeType = loadHelper.LoadType(plugInType) ?? throw new ConfigurationException($"Could not load plugin type {plugInType}");
var pluginTypeType = loadHelper.LoadType(plugInType) ?? throw new SchedulerException($"Could not load plugin type {plugInType}");
// we need to use concrete types to resolve correct one
var method = GetType().GetMethod(nameof(InstantiateType), BindingFlags.Instance | BindingFlags.NonPublic)!.MakeGenericMethod(pluginTypeType);
plugin = (ISchedulerPlugin) method.Invoke(this, new [] { pluginTypeType })!;
Expand Down Expand Up @@ -1090,10 +1106,14 @@ private async Task<IScheduler> Instantiate()
}
}

private protected virtual string GetNamedConnectionString(string dsConnectionStringName)
protected virtual string? GetNamedConnectionString(string connectionStringName)
{
var connectionStringSettings = ConfigurationManager.ConnectionStrings[dsConnectionStringName];
#if NETFRAMEWORK
var connectionStringSettings = System.Configuration.ConfigurationManager.ConnectionStrings[connectionStringName];
return connectionStringSettings.ConnectionString;
#else
return null;
#endif
}

protected virtual T InstantiateType<T>(Type? implementationType)
Expand Down
1 change: 0 additions & 1 deletion src/Quartz/Quartz.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
<PackageReference Include="LibLog" Version="5.0.8" PrivateAssets="all" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="2.1.1" />
<PackageReference Include="PolySharp" Version="1.14.1" PrivateAssets="all" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="6.0.1" Condition=" '$(TargetFramework)' != 'net462' and '$(TargetFramework)' != 'net472' " />
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="4.7.1" Condition=" '$(TargetFramework)' == 'netstandard2.0' or '$(TargetFramework)' == 'net472' " />
</ItemGroup>
</Project>
25 changes: 0 additions & 25 deletions src/Quartz/Util/Configuration.cs

This file was deleted.

0 comments on commit 0f62d32

Please sign in to comment.