Improving AppSettings Processing - Synergex/HarmonyCore GitHub Wiki
The Harmony Core SolutionTemplates include code and sample configuration files for a mechanism that allows environment variables that are required at runtime to be specified via the special appsettings.json file. This mechanism is described in detail in the Environment Variables documentation.
Earlier versions of the solution templates contained code that did not operate as intended, and this document contains instructions on how to alter the supplied code to provide a fully working solution.
To determine if your code needs this fix to be applied, look in your Services.Models project directory and edit the file called AppSettings.dbl. If you look towards the end of that file and find a class named AppEnvironmentVariable that looks like this:
;;; <summary>
;;; Represents a aingle environment variable.
;;; </summary>
public class AppEnvironmentVariable
;;; <summary>
;;; The name of the environment variable.
;;; </summary>
public readwrite property Name, string
;;; <summary>
;;; The value of the environment variable.
;;; </summary>
public readwrite property Value, string
endclass
Then your code needs updating. If the class is not present then your code has already been fixed.
-
Edit
Services.Models\AppSettings.dbland remove the definition of theAppEnvironmentVariableclass (shown above). -
Change the definition of the
EnvironmentVariablesproperty from this:
public readwrite property EnvironmentVariables, @List<AppEnvironmentVariable>, new List<AppEnvironmentVariable>()
To this
public readwrite property EnvironmentVariables, @Dictionary<string,string>, new Dictionary<string, string>()
- Change the code in the public method
ProcessEnvironmentVariablesfrom this:
data ev, @AppEnvironmentVariable
foreach ev in EnvironmentVariables
begin
data sts, int
xcall setlog(ev.Name,ev.Value,sts)
end
To this:
data ev, @KeyValuePair<string,string>
foreach ev in EnvironmentVariables
begin
data sts, int
xcall setlog(ev.Key,ev.Value,sts)
end
- Save and close the source file.
- Edit the file
Services.Host\appsettings.json
The file as originally shipped looked like this:
{
"AppSettings": {
"HttpPort": 80,
"HttpsPort": 443,
"EnvironmentVariables": [
{
"Name": "HARMONY_TOKEN_DURATION",
"Value": "1"
},
{
"Name": "HARMONY_LOG_LEVEL",
"Value": "2"
}
]
}
}
The HttpPort and HttpsPort settings were never used and can be removed, and the EnvironmentVariables section must now be changed from being an array of objects with Name and Value properties to an array of named string properties.
- Alter the content of the file to look like this:
{
"AppSettings": {
"EnvironmentVariables": {
"HARMONY_TOKEN_DURATION": "1",
"HARMONY_LOG_LEVEL": "2"
}
}
}
If your environment includes configuration files for other environments (e.g. appsettings.Development.json or appsettings.Production.json) then apply similar changes to those files also.
For example, in the sample environment created from the Harmony Core solution templates, you would have a file named appsettings.Development.json and would need to change this:
{
"AppSettings": {
"HttpPort": 8085,
"HttpsPort": 8086,
"EnvironmentVariables": [
{
"Name": "HARMONY_TOKEN_DURATION",
"Value": "8767"
},
{
"Name": "HARMONY_LOG_LEVEL",
"Value": "6"
}
]
}
}
To this:
{
"AppSettings": {
"EnvironmentVariables": {
"HARMONY_TOKEN_DURATION": "8767",
"HARMONY_LOG_LEVEL": "6"
}
}
}