Skip to content

Commit 64c59a8

Browse files
committed
7.0.12 allow json config files to have strings or json objects
- [ENHANCEMENT] allow json config files to have strings or json objects using CombineSectionValues function
1 parent b80671e commit 64c59a8

File tree

3 files changed

+35
-7
lines changed

3 files changed

+35
-7
lines changed

rls/packages/API.Library.7.0.12.nupkg

67.4 KB
Binary file not shown.

src/API.Library/API.Library.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
<PackageId>API.Library</PackageId>
1313
<Product>API Library</Product>
1414
<Copyright>Central Statistics Office, Ireland</Copyright>
15-
<Version>7.0.11</Version>
15+
<Version>7.0.12</Version>
1616
<Authors>Central Statistics Office, Ireland</Authors>
1717
<SignAssembly>False</SignAssembly>
1818
<RepositoryUrl>https://github.com/CSOIreland/Server-API-Library</RepositoryUrl>
1919
<PackageReleaseNotes>
20-
- [BUG FIX] restored microsoft.data.sqlclient to correct version
20+
- [ENHANCEMENT] allow json config files to have strings or json objects using CombineSectionValues function
2121
</PackageReleaseNotes>
2222
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
2323
<RestoreLockedMode>true</RestoreLockedMode>

src/API.Library/Config/CommonConfig.cs

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
using Microsoft.Extensions.Options;
1+
using Microsoft.Extensions.Configuration;
2+
using Microsoft.Extensions.Options;
3+
using Newtonsoft.Json.Linq;
4+
using System.Text;
25

36
namespace API
47
{
@@ -93,7 +96,9 @@ public static IDictionary<string, string> ReadJSONSettings(decimal? inMemoryVers
9396
}
9497
else
9598
{
96-
dictionary.Add(val.Key, val.Value);
99+
100+
var combinedValue = CombineSectionValues(val);
101+
dictionary.Add(val.Key, combinedValue);
97102
}
98103
}
99104
}
@@ -102,12 +107,35 @@ public static IDictionary<string, string> ReadJSONSettings(decimal? inMemoryVers
102107
return dictionary;
103108
}
104109
}
105-
106110

107-
public static void deployUpdate( decimal? inMemoryVersion, string configType)
111+
112+
// Method to recursively combine section values into a JSON string
113+
public static string CombineSectionValues(IConfigurationSection section)
108114
{
115+
// Get the children of the current section
116+
var children = section.GetChildren();
117+
118+
// If there are no children, return the section value
119+
if (!children.Any())
120+
{
121+
return section.Value;
122+
}
123+
124+
// Create a JSON object to hold the combined values
125+
var jsonObject = new JObject();
109126

110-
127+
// Recursively process each child section
128+
foreach (var child in children)
129+
{
130+
jsonObject[child.Key] = CombineSectionValues(child);
131+
}
132+
133+
// Convert the JSON object to a string and return it
134+
return jsonObject.ToString();
135+
}
136+
137+
public static void deployUpdate( decimal? inMemoryVersion, string configType)
138+
{
111139
var inputParamList = new List<ADO_inputParams>()
112140
{
113141
new ADO_inputParams() {name= "@app_settings_version", value = inMemoryVersion},

0 commit comments

Comments
 (0)