-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pull provider configuration from database (#203)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
3294481
commit 362d1c2
Showing
36 changed files
with
1,569 additions
and
473 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,18 @@ | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace TagzApp.Common; | ||
|
||
/// <summary> | ||
/// An interface to configure the services for a Social Media Provider | ||
/// </summary> | ||
public interface IConfigureProvider | ||
{ | ||
|
||
/// <summary> | ||
/// Register all of the services with dependency injection for the social media provider | ||
/// </summary> | ||
/// <param name="services">The dependency injection services</param> | ||
/// <param name="configuration">Application Configuration</param> | ||
/// <returns></returns> | ||
IServiceCollection RegisterServices(IServiceCollection services, IConfiguration configuration); | ||
|
||
} | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace TagzApp.Common; | ||
|
||
/// <summary> | ||
/// An interface to configure the services for a Social Media Provider | ||
/// </summary> | ||
public interface IConfigureProvider | ||
{ | ||
/// <summary> | ||
/// Register all of the services with dependency injection for the social media provider | ||
/// </summary> | ||
/// <param name="services">The dependency injection services</param> | ||
/// <param name="cancellationToken"></param> | ||
/// <returns>Service Collection</returns> | ||
Task<IServiceCollection> RegisterServices(IServiceCollection services, CancellationToken cancellationToken = default); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace TagzApp.Common; | ||
|
||
public interface IProviderConfigurationRepository | ||
{ | ||
Task<ProviderConfiguration?> GetConfigurationSettingsAsync(string name, CancellationToken cancellationToken = default); | ||
} |
42 changes: 42 additions & 0 deletions
42
src/TagzApp.Common/InMemoryProviderConfigurationRepository.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using Microsoft.Extensions.Configuration; | ||
|
||
namespace TagzApp.Common; | ||
public class InMemoryProviderConfigurationRepository : IProviderConfigurationRepository | ||
{ | ||
private readonly IConfiguration _Configuration; | ||
|
||
public InMemoryProviderConfigurationRepository(IConfiguration configuration) | ||
{ | ||
_Configuration = configuration; | ||
} | ||
|
||
public async Task<ProviderConfiguration> GetConfigurationSettingsAsync(string name, CancellationToken cancellationToken = default) | ||
{ | ||
var appSettingsSection = $"providers:{name.ToLower()}"; | ||
var providerConfig = new ProviderConfiguration | ||
{ | ||
Name = name, | ||
}; | ||
|
||
var configSettings = _Configuration.GetSection(appSettingsSection).GetChildren(); | ||
|
||
foreach (var configSetting in configSettings) | ||
{ | ||
if (configSetting.Key == "Activated") | ||
{ | ||
providerConfig.Activated = bool.Parse(configSetting.Value ?? "false"); | ||
continue; | ||
} | ||
|
||
if (configSetting.Key == "Description") | ||
{ | ||
providerConfig.Description = configSetting.Value ?? string.Empty; | ||
continue; | ||
} | ||
|
||
providerConfig.ConfigurationSettings!.Add(configSetting.Key, configSetting.Value ?? string.Empty); | ||
} | ||
|
||
return await Task.FromResult(providerConfig); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
namespace TagzApp.Common.Models; | ||
|
||
public class ProviderConfiguration | ||
{ | ||
public int Id { get; set; } | ||
public string Name { get; set; } = string.Empty; | ||
public string Description { get; set; } = string.Empty; | ||
public Dictionary<string, string>? ConfigurationSettings { get; set; } | ||
public bool Activated { get; set; } | ||
|
||
public ProviderConfiguration() | ||
{ | ||
ConfigurationSettings = new Dictionary<string, string>(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
namespace TagzApp.Communication; | ||
|
||
public abstract class BaseConfigurationProvider | ||
{ | ||
private readonly IProviderConfigurationRepository _ProviderConfigurationRepository; | ||
|
||
public BaseConfigurationProvider(IProviderConfigurationRepository providerConfigurationRepository) | ||
{ | ||
_ProviderConfigurationRepository = providerConfigurationRepository; | ||
} | ||
|
||
protected abstract void MapConfigurationValues(ProviderConfiguration providerConfiguration); | ||
|
||
protected async Task LoadConfigurationValuesAsync(string providerName, CancellationToken cancellationToken = default) | ||
{ | ||
var providerConfiguration = await _ProviderConfigurationRepository.GetConfigurationSettingsAsync(providerName, cancellationToken); | ||
|
||
if (providerConfiguration != null) | ||
{ | ||
MapConfigurationValues(providerConfiguration); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.