2024-01-24 11:07:18 +01:00
|
|
|
using System.Text.Json;
|
|
|
|
|
using System.Text.Json.Nodes;
|
2020-03-18 19:17:51 +01:00
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
using Microsoft.Extensions.Configuration.Json;
|
|
|
|
|
using Microsoft.Extensions.FileProviders;
|
2022-02-28 22:52:03 +13:00
|
|
|
using Microsoft.Extensions.Logging;
|
2024-01-24 11:07:18 +01:00
|
|
|
using Umbraco.Cms.Core;
|
|
|
|
|
using Umbraco.Cms.Core.Configuration;
|
v10 SQLite support + distributed locking abstractions (#11922)
* Created Persistence.SQLite project skeleton.
* SQLite database initialization
* Various changes and hacks to make things work.
* WIP integration tests
* Fix thread safety tests
* Fix tests that relied on tie breaker sorting.
Spent a fair amount of time looking for a less lazy fix but gave up.
* Convert right join to left join ContentTypeRepository.PerformGetByQuery
SQLite doesn't support right join
* Fix test Can_Generate_Delete_SubQuery_Statement
Worth noting that NPoco.DatabaseTypes.SQLiteDatabaseType doesn't override
EscapeSqlIdentifier so NPoco will escape with [].
SQLite docs say > "A keyword enclosed in square brackets is an identifier.
This is not standard SQL.
This quoting mechanism is used by MS Access and SQL Server and is
included in SQLite for compatibility."
Also could have updated SqliteSyntaxProvider to match npoco but
decided against it.
* Fixes for paginated custom order by
* Fix tests broken by lack of unique indexes.
* Fix SqlServerTableByTableTest tests.
These tests didn't actually do anything as the tables already exist so schema creator just returned.
Did however point out that the default implementation for DoesTableExist just returns false so added a default naive implementation.
* Fix ValidateLoginSession - SelectTop must come later
* dry up database cleanup
* Fix up db migration tests.
We can't drop pk in sqlite without recreating table.
Test looks to be testing that add column works as intended which we can test.
* Prevent schema creation errors.
* SQLite ignore lock tests, WAL back on.
* Fix package schema tests
* Fix NPocoFetchTests - case sensitivity not under test
* Fix AdvancedMigrationTests (where possible)
Migrations probably need a good look later.
Maybe nuke old migrations and only support moving to v10 from v9.
If we do that can do some cleanup.
* Cleanup test database configuration
* Run integration tests against SQLite on build agent.
* Drop MS.Data.SQLite
System.Data.SQLite was quicker to roll out due to more CLR type mapping
* YAML
* Skip Umbraco.Tests.Integration.SqlCe
* Drop SqlServerTableByTable tests.
Until this week they did nothing anyway as they with NewSchemaPerTest
so the tests all passed as CreateTable was no op (already exists).
Also all of the tables are created in an empty database by SchemaValidationTest.cs
DatabaseSchemaCreation_Produces_DatabaseSchemaResult_With_Zero_Errors
* Might aswell run against macOS also.
* Copy azure pipelines task header layout
* Delete SQLCe projects
* Remove SQL CE specific code.
* Remove SQL CE NuSpec, template params, build script setup
* Delete umbraco-netcore-only.sln
* Add SkipTests solution configuration and use for codeql
* Remove reference to deleted nuspec file.
* Refactor ConnectionStrings WRT DataDirectory placeholder & ProviderName.
At this point you can try out SQLite support by setting the following
in appsettings.json and then completing the install process.
"ConnectionStrings": {
"umbracoDbDSN": "Data Source=|DataDirectory|/umbraco.sqlite",
"umbracoDbDSN_ProviderName": "System.Data.SQLite"
},
Not currently possible via installer UI without provider name pre-set in
configuration.
* Switch to Microsoft.Data.Sqlite
Some gross hacks but will be good to find out if this works
with apple silicon.
* Enable selection of SQLite via installer UI (also quick install)
* Remove SqlServerDbProviderFactoryCreator to cleanup a TODO
* Move SQL Server support to its own class library
* Add persistence dependencies to Umbraco.CMS metapackage
* Bugfix packages delete query
Created invalid query for SQLite.
* Try out cypress tests Linux + SQLite
* Prevent cypress test artifact upload failure on attempt 2+
* LocalDb bugfixes
* Drop redundant enum
* Move SqlClient constant
* Misc whitespace
* Remove IsSqlCe extension (TODO: drop non 9->10 migrations later).
* Umbraco.Persistence.* -> Umbraco.Cms.Persistence.*
* Display quick install defaults and per provider default database name.
* Misc remove old comment
* little re-arrange
* Remove almost all usages of IsSqlite extension.
* visual adjustments
* Custom Database Configuration is last step and should then say Install.
* use text instead of disabled inputs
* move legend, rename to Install
* Update SqlMainDomLock to work without distributed locks.
* Added IDistributedLockingMechanism interface and in memory impl.
* Drop locking from ISqlSyntaxProvider & wire up scope to abstraction.
* Added SqlServerDistributedLockingMechanism
* Move distributed locking interfaces and exceptions to Core + xmldocs.
* Fix tests, Misc cleanup, Add SQL distributed locking integration tests
* Provide mechanism to specify DistributedLockingMechanism in config
(even if added by composer)
* Nomplementation -> NoImplementation
* Fix misleading comment
* Integration tests use SqlServerDistributedLockingMechanism when possible
* Handle up-gradable locks SqlServerDistributedLockingMechanism.
TODO: InMemoryDistributedLockingMechanism.
Note: Nuked SqlServerDistributedLockingMechanismTests, will still sleep
at night.
Is covered by Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.LockTests
* Make tests pass for InMemoryDistributedLockingMechanism, pretty hacky.
* Tweak constraints on WithCollectionBuilder so i can drop bad constructor
* Added SqliteDistributedLockingMechanism
* Dropped InMemoryDistributedMechanism + magic
InMemoryDistributedMechanism was pretty rubbish and now we have
a decent implementation for SQLite as we no longer block readers
see 8d1f42b.
Also drop the CollectionBuilder setup, instead do the same as we do
for syntax providers etc, it's more automagical so we never require an
explicit selection although we are allowing for it.
However keeping the optional IUmbracoBuilder constructor param for
CollectionBuilders as it's extremely useful.
* Fix quick install "" database name.
* Hide Database Configuration section when a connection string is pre-set.
Doesn't seem worth it to extract db name from connection string.
* Ensure wal test 2+
* Fix logging inconsistencies.
* Ensure in transaction when obtaining locks + no-op the SQLite read lock.
There's no point in running the query just to make a single test pass.
* Fix installer database display names
* Allow SQLite shared cache without losing deferred transactions
* Opt into shared cache for new SQLite databases + fix filename
* Fix misc inconsistency in .gitignore
* Prefer our interceptor interface
* Restore DEBUG_DATABASES code OnConnectionOpened in case it's used.
* Back to private cache.
* Added retry strategy for SQLite + refactor out SQL server specific stuff
* Fix SQL server tests.
* Misc - Orphaned comment, incorrect casing.
* InMemory SQLite test database & turn shared cache back on everywhere.
Co-authored-by: Niels Lyngsø <niels.lyngso@gmail.com>
2022-03-11 16:14:20 +00:00
|
|
|
using Umbraco.Cms.Core.Configuration.Models;
|
2020-08-20 22:18:50 +01:00
|
|
|
|
2024-01-24 11:07:18 +01:00
|
|
|
namespace Umbraco.Cms.Infrastructure.Configuration;
|
|
|
|
|
|
2025-07-21 08:32:54 +02:00
|
|
|
internal sealed class JsonConfigManipulator : IConfigManipulator
|
2020-03-18 19:17:51 +01:00
|
|
|
{
|
2024-01-24 11:07:18 +01:00
|
|
|
private const string ConnectionStringObjectName = "ConnectionStrings";
|
|
|
|
|
private const string UmbracoConnectionStringPath = $"{ConnectionStringObjectName}:{Constants.System.UmbracoConnectionName}";
|
|
|
|
|
private const string UmbracoConnectionStringProviderNamePath = UmbracoConnectionStringPath + ConnectionStrings.ProviderNamePostfix;
|
|
|
|
|
private const string CmsObjectPath = "Umbraco:CMS";
|
|
|
|
|
private const string GlobalIdPath = $"{CmsObjectPath}:Global:Id";
|
|
|
|
|
private const string DisableRedirectUrlTrackingPath = $"{CmsObjectPath}:WebRouting:DisableRedirectUrlTracking";
|
|
|
|
|
|
2024-05-14 14:12:02 +02:00
|
|
|
private readonly JsonDocumentOptions _jsonDocumentOptions = new() { CommentHandling = JsonCommentHandling.Skip };
|
2024-01-24 11:07:18 +01:00
|
|
|
private readonly IConfiguration _configuration;
|
|
|
|
|
private readonly ILogger<JsonConfigManipulator> _logger;
|
|
|
|
|
private readonly SemaphoreSlim _lock = new(1, 1);
|
|
|
|
|
|
|
|
|
|
public JsonConfigManipulator(IConfiguration configuration, ILogger<JsonConfigManipulator> logger)
|
|
|
|
|
{
|
|
|
|
|
_configuration = configuration;
|
|
|
|
|
_logger = logger;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public async Task RemoveConnectionStringAsync()
|
2020-03-18 19:17:51 +01:00
|
|
|
{
|
2024-01-24 11:07:18 +01:00
|
|
|
JsonConfigurationProvider? provider = GetJsonConfigurationProvider(UmbracoConnectionStringPath);
|
2022-05-25 10:48:45 +01:00
|
|
|
|
2024-01-24 11:07:18 +01:00
|
|
|
JsonNode? jsonNode = await GetJsonNodeAsync(provider);
|
2020-03-18 19:17:51 +01:00
|
|
|
|
2024-01-24 11:07:18 +01:00
|
|
|
if (jsonNode is null)
|
2022-02-28 22:52:03 +13:00
|
|
|
{
|
2024-01-24 11:07:18 +01:00
|
|
|
_logger.LogWarning("Failed to remove connection string from JSON configuration");
|
|
|
|
|
return;
|
2022-02-28 22:52:03 +13:00
|
|
|
}
|
|
|
|
|
|
2024-01-24 11:07:18 +01:00
|
|
|
RemoveJsonNode(jsonNode, UmbracoConnectionStringPath);
|
|
|
|
|
RemoveJsonNode(jsonNode, UmbracoConnectionStringProviderNamePath);
|
2022-05-25 10:48:45 +01:00
|
|
|
|
2024-01-24 11:07:18 +01:00
|
|
|
await SaveJsonAsync(provider, jsonNode);
|
|
|
|
|
}
|
2020-03-18 19:17:51 +01:00
|
|
|
|
2024-01-24 11:07:18 +01:00
|
|
|
/// <inheritdoc />
|
|
|
|
|
public async Task SaveConnectionStringAsync(string connectionString, string? providerName)
|
|
|
|
|
{
|
|
|
|
|
JsonConfigurationProvider? provider = GetJsonConfigurationProvider();
|
|
|
|
|
JsonNode? node = await GetJsonNodeAsync(provider);
|
2020-03-18 19:17:51 +01:00
|
|
|
|
2024-01-24 11:07:18 +01:00
|
|
|
if (node is null)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogWarning("Was unable to load the configuration file to save the connection string");
|
|
|
|
|
return;
|
2020-03-18 19:17:51 +01:00
|
|
|
}
|
|
|
|
|
|
2024-01-24 11:07:18 +01:00
|
|
|
CreateOrUpdateJsonNode(node, UmbracoConnectionStringPath, connectionString);
|
|
|
|
|
if (providerName is not null)
|
2020-03-18 19:17:51 +01:00
|
|
|
{
|
2024-01-24 11:07:18 +01:00
|
|
|
CreateOrUpdateJsonNode(node, UmbracoConnectionStringProviderNamePath, providerName);
|
|
|
|
|
}
|
2020-03-18 19:17:51 +01:00
|
|
|
|
2024-01-24 11:07:18 +01:00
|
|
|
await SaveJsonAsync(provider, node);
|
|
|
|
|
}
|
2020-03-18 19:17:51 +01:00
|
|
|
|
2024-01-24 11:07:18 +01:00
|
|
|
/// <inheritdoc />
|
|
|
|
|
public async Task SaveConfigValueAsync(string itemPath, object value)
|
|
|
|
|
{
|
|
|
|
|
JsonConfigurationProvider? provider = GetJsonConfigurationProvider();
|
|
|
|
|
JsonNode? node = await GetJsonNodeAsync(provider);
|
2020-03-18 19:17:51 +01:00
|
|
|
|
2024-01-24 11:07:18 +01:00
|
|
|
if (node is null)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogWarning("Failed to save configuration key \"{Key}\" in JSON configuration", itemPath);
|
|
|
|
|
return;
|
2020-03-18 19:17:51 +01:00
|
|
|
}
|
|
|
|
|
|
2024-01-24 11:07:18 +01:00
|
|
|
JsonNode? propertyNode = node;
|
|
|
|
|
foreach (var propertyName in itemPath.Split(':'))
|
2020-03-31 10:47:08 +02:00
|
|
|
{
|
2024-01-24 11:07:18 +01:00
|
|
|
propertyNode = FindChildNode(propertyNode, propertyName);
|
|
|
|
|
}
|
2020-03-31 10:47:08 +02:00
|
|
|
|
2024-01-24 11:07:18 +01:00
|
|
|
if (propertyNode is null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-03-31 10:47:08 +02:00
|
|
|
|
2024-01-24 11:07:18 +01:00
|
|
|
propertyNode.ReplaceWith(value);
|
|
|
|
|
await SaveJsonAsync(provider, node);
|
|
|
|
|
}
|
2020-03-31 10:47:08 +02:00
|
|
|
|
2024-01-24 11:07:18 +01:00
|
|
|
/// <inheritdoc />
|
|
|
|
|
public async Task SaveDisableRedirectUrlTrackingAsync(bool disable)
|
|
|
|
|
=> await CreateOrUpdateConfigValueAsync(DisableRedirectUrlTrackingPath, disable);
|
2020-03-31 10:47:08 +02:00
|
|
|
|
2024-01-24 11:07:18 +01:00
|
|
|
/// <inheritdoc />
|
|
|
|
|
public async Task SetGlobalIdAsync(string id)
|
|
|
|
|
=> await CreateOrUpdateConfigValueAsync(GlobalIdPath, id);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Creates or updates a config value at the specified path.
|
|
|
|
|
/// <remarks>This causes a rewrite of the configuration file.</remarks>
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="itemPath">Path to update, uses : as the separator.</param>
|
|
|
|
|
/// <param name="value">The value of the node.</param>
|
|
|
|
|
private async Task CreateOrUpdateConfigValueAsync(string itemPath, object value)
|
|
|
|
|
{
|
|
|
|
|
JsonConfigurationProvider? provider = GetJsonConfigurationProvider();
|
|
|
|
|
JsonNode? node = await GetJsonNodeAsync(provider);
|
2020-03-18 19:17:51 +01:00
|
|
|
|
2024-01-24 11:07:18 +01:00
|
|
|
if (node is null)
|
2020-09-08 15:50:52 +02:00
|
|
|
{
|
2024-01-24 11:07:18 +01:00
|
|
|
_logger.LogWarning("Failed to save configuration key \"{Key}\" in JSON configuration", itemPath);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-09-08 15:50:52 +02:00
|
|
|
|
2024-01-24 11:07:18 +01:00
|
|
|
CreateOrUpdateJsonNode(node, itemPath, value);
|
|
|
|
|
await SaveJsonAsync(provider, node);
|
|
|
|
|
}
|
2020-09-08 15:50:52 +02:00
|
|
|
|
2024-01-24 11:07:18 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// Updates or creates a json node at the specified path.
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// Will also create any missing nodes in the path.
|
|
|
|
|
/// </remarks>
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="node">Node to create or update.</param>
|
|
|
|
|
/// <param name="itemPath">Path to create or update, uses : as the separator.</param>
|
|
|
|
|
/// <param name="value">The value of the node.</param>
|
|
|
|
|
private static void CreateOrUpdateJsonNode(JsonNode node, string itemPath, object value)
|
|
|
|
|
{
|
|
|
|
|
// This is required because System.Text.Json has no merge function, and doesn't support patch
|
|
|
|
|
// this is a problem because we don't know if the key(s) exists yet, so we can't simply update it,
|
|
|
|
|
// we may have to create one ore more json objects.
|
|
|
|
|
|
|
|
|
|
// First we find the inner most child that already exists.
|
|
|
|
|
var propertyNames = itemPath.Split(':');
|
|
|
|
|
JsonNode propertyNode = node;
|
|
|
|
|
var index = 0;
|
|
|
|
|
foreach (var propertyName in propertyNames)
|
|
|
|
|
{
|
|
|
|
|
JsonNode? found = FindChildNode(propertyNode, propertyName);
|
|
|
|
|
if (found is null)
|
2022-02-18 14:32:51 +01:00
|
|
|
{
|
2024-01-24 11:07:18 +01:00
|
|
|
break;
|
2022-02-18 14:32:51 +01:00
|
|
|
}
|
2020-09-08 15:50:52 +02:00
|
|
|
|
2024-01-24 11:07:18 +01:00
|
|
|
propertyNode = found;
|
|
|
|
|
index++;
|
2020-09-08 15:50:52 +02:00
|
|
|
}
|
|
|
|
|
|
2021-01-18 15:40:22 +01:00
|
|
|
|
2024-01-24 11:07:18 +01:00
|
|
|
// We can now use the index to go through the remaining keys, creating them as we go.
|
|
|
|
|
while (index < propertyNames.Length)
|
|
|
|
|
{
|
|
|
|
|
var propertyName = propertyNames[index];
|
|
|
|
|
var newNode = new JsonObject();
|
|
|
|
|
propertyNode.AsObject()[propertyName] = newNode;
|
|
|
|
|
propertyNode = newNode;
|
|
|
|
|
index++;
|
|
|
|
|
}
|
2021-01-18 15:40:22 +01:00
|
|
|
|
2024-01-24 11:07:18 +01:00
|
|
|
// System.Text.Json doesn't like just setting an Object as a value, so instead we first create the node,
|
|
|
|
|
// and then replace the value
|
|
|
|
|
propertyNode.ReplaceWith(value);
|
|
|
|
|
}
|
2021-01-18 15:40:22 +01:00
|
|
|
|
2024-01-24 11:07:18 +01:00
|
|
|
private static void RemoveJsonNode(JsonNode node, string key)
|
|
|
|
|
{
|
|
|
|
|
JsonNode? propertyNode = node;
|
|
|
|
|
foreach (var propertyName in key.Split(':'))
|
|
|
|
|
{
|
|
|
|
|
propertyNode = FindChildNode(propertyNode, propertyName);
|
2021-01-18 15:40:22 +01:00
|
|
|
}
|
|
|
|
|
|
2024-01-24 11:07:18 +01:00
|
|
|
propertyNode?.Parent?.AsObject().Remove(propertyNode.GetPropertyName());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task SaveJsonAsync(JsonConfigurationProvider? provider, JsonNode jsonNode)
|
|
|
|
|
{
|
|
|
|
|
if (provider?.Source.FileProvider is not PhysicalFileProvider physicalFileProvider)
|
2021-01-18 15:40:22 +01:00
|
|
|
{
|
2024-01-24 11:07:18 +01:00
|
|
|
return;
|
2021-01-18 15:40:22 +01:00
|
|
|
}
|
|
|
|
|
|
2024-01-24 11:07:18 +01:00
|
|
|
await _lock.WaitAsync();
|
|
|
|
|
|
|
|
|
|
try
|
2020-09-08 15:50:52 +02:00
|
|
|
{
|
2024-01-24 11:07:18 +01:00
|
|
|
var jsonFilePath = Path.Combine(physicalFileProvider.Root, provider.Source.Path!);
|
|
|
|
|
await using var jsonConfigStream = new FileStream(jsonFilePath, FileMode.Create);
|
|
|
|
|
await using var writer = new Utf8JsonWriter(jsonConfigStream, new JsonWriterOptions { Indented = true });
|
|
|
|
|
jsonNode.WriteTo(writer);
|
2020-09-08 15:50:52 +02:00
|
|
|
}
|
2024-01-24 11:07:18 +01:00
|
|
|
finally
|
2020-03-18 19:17:51 +01:00
|
|
|
{
|
2024-01-24 11:07:18 +01:00
|
|
|
_lock.Release();
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-03-18 19:17:51 +01:00
|
|
|
|
2024-01-24 11:07:18 +01:00
|
|
|
private async Task<JsonNode?> GetJsonNodeAsync(JsonConfigurationProvider? provider)
|
|
|
|
|
{
|
|
|
|
|
if (provider is null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2022-05-25 10:48:45 +01:00
|
|
|
|
2024-01-24 11:07:18 +01:00
|
|
|
await _lock.WaitAsync();
|
|
|
|
|
if (provider.Source.FileProvider is not PhysicalFileProvider physicalFileProvider)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2022-05-25 10:48:45 +01:00
|
|
|
|
2024-01-24 11:07:18 +01:00
|
|
|
var jsonFilePath = Path.Combine(physicalFileProvider.Root, provider.Source.Path!);
|
2020-03-18 19:17:51 +01:00
|
|
|
|
2024-01-24 11:07:18 +01:00
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
using var streamReader = new StreamReader(jsonFilePath);
|
2024-05-14 14:12:02 +02:00
|
|
|
return await JsonNode.ParseAsync(streamReader.BaseStream, documentOptions: _jsonDocumentOptions);
|
2020-03-18 19:17:51 +01:00
|
|
|
}
|
2024-01-24 11:07:18 +01:00
|
|
|
catch (IOException exception)
|
2020-03-18 19:17:51 +01:00
|
|
|
{
|
2024-01-24 11:07:18 +01:00
|
|
|
_logger.LogWarning(exception, "JSON configuration could not be read: {Path}", jsonFilePath);
|
|
|
|
|
return null;
|
2020-03-18 19:17:51 +01:00
|
|
|
}
|
2024-01-24 11:07:18 +01:00
|
|
|
finally
|
2020-03-18 19:17:51 +01:00
|
|
|
{
|
2024-01-24 11:07:18 +01:00
|
|
|
_lock.Release();
|
2020-03-18 19:17:51 +01:00
|
|
|
}
|
2024-01-24 11:07:18 +01:00
|
|
|
}
|
2020-03-18 19:17:51 +01:00
|
|
|
|
2024-01-24 11:07:18 +01:00
|
|
|
private JsonConfigurationProvider? GetJsonConfigurationProvider(string? requiredKey = null)
|
|
|
|
|
{
|
|
|
|
|
if (_configuration is not IConfigurationRoot configurationRoot)
|
2020-03-18 19:17:51 +01:00
|
|
|
{
|
2024-01-24 11:07:18 +01:00
|
|
|
return null;
|
2020-03-18 19:17:51 +01:00
|
|
|
}
|
|
|
|
|
|
2024-01-24 11:07:18 +01:00
|
|
|
foreach (IConfigurationProvider provider in configurationRoot.Providers)
|
2020-03-18 19:17:51 +01:00
|
|
|
{
|
2024-01-24 11:07:18 +01:00
|
|
|
if (provider is JsonConfigurationProvider jsonConfigurationProvider &&
|
|
|
|
|
(requiredKey is null || provider.TryGet(requiredKey, out _)))
|
2020-03-18 19:17:51 +01:00
|
|
|
{
|
2024-01-24 11:07:18 +01:00
|
|
|
return jsonConfigurationProvider;
|
2020-03-18 19:17:51 +01:00
|
|
|
}
|
2024-01-24 11:07:18 +01:00
|
|
|
}
|
2022-05-25 10:48:45 +01:00
|
|
|
|
2024-01-24 11:07:18 +01:00
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Finds the immediate child with the specified name, in a case insensitive manner.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// This is required since keys are case insensitive in IConfiguration.
|
|
|
|
|
/// But not in JsonNode.
|
|
|
|
|
/// </remarks>
|
|
|
|
|
/// <param name="node">The node to search.</param>
|
|
|
|
|
/// <param name="key">The key to search for.</param>
|
|
|
|
|
/// <returns>The found node, null if no match is found.</returns>
|
|
|
|
|
private static JsonNode? FindChildNode(JsonNode? node, string key)
|
|
|
|
|
{
|
|
|
|
|
if (node is null)
|
|
|
|
|
{
|
|
|
|
|
return node;
|
2020-03-18 19:17:51 +01:00
|
|
|
}
|
|
|
|
|
|
2024-01-24 11:07:18 +01:00
|
|
|
foreach (KeyValuePair<string, JsonNode?> property in node.AsObject())
|
2020-03-18 19:17:51 +01:00
|
|
|
{
|
2024-01-24 11:07:18 +01:00
|
|
|
if (property.Key.Equals(key, StringComparison.OrdinalIgnoreCase))
|
2020-03-18 19:17:51 +01:00
|
|
|
{
|
2024-01-24 11:07:18 +01:00
|
|
|
return property.Value;
|
2020-03-18 19:17:51 +01:00
|
|
|
}
|
|
|
|
|
}
|
2024-01-24 11:07:18 +01:00
|
|
|
|
|
|
|
|
return null;
|
2020-03-18 19:17:51 +01:00
|
|
|
}
|
|
|
|
|
}
|