Compare commits

..

No commits in common. "dad0f9b3767a2062fd03149c058e3961223d1eaa" and "1033d2977d0ea1a6bf8aac49b52fb6d1644eb4e5" have entirely different histories.

4 changed files with 39 additions and 69 deletions

4
.vscode/launch.json vendored
View File

@ -10,9 +10,9 @@
"request": "launch", "request": "launch",
"preLaunchTask": "build", "preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path. // If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/deployment.tests/bin/Debug/net8.0/deployment.tests.dll", "program": "${workspaceFolder}/deploy-test/bin/Debug/net8.0/deploy-test.dll",
"args": [], "args": [],
"cwd": "${workspaceFolder}/deployment.tests", "cwd": "${workspaceFolder}/deploy-test",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console // For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
"console": "internalConsole", "console": "internalConsole",
"stopAtEntry": false "stopAtEntry": false

6
.vscode/tasks.json vendored
View File

@ -7,7 +7,7 @@
"type": "process", "type": "process",
"args": [ "args": [
"build", "build",
"${workspaceFolder}/deployment.tests/deployment.tests.csproj", "${workspaceFolder}/deploy-test/deploy-test.csproj",
"/property:GenerateFullPaths=true", "/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary;ForceNoAlign" "/consoleloggerparameters:NoSummary;ForceNoAlign"
], ],
@ -19,7 +19,7 @@
"type": "process", "type": "process",
"args": [ "args": [
"publish", "publish",
"${workspaceFolder}/deployment.tests/deployment.tests.csproj", "${workspaceFolder}/deploy-test/deploy-test.csproj",
"/property:GenerateFullPaths=true", "/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary;ForceNoAlign" "/consoleloggerparameters:NoSummary;ForceNoAlign"
], ],
@ -33,7 +33,7 @@
"watch", "watch",
"run", "run",
"--project", "--project",
"${workspaceFolder}/deployment.tests/deployment.tests.csproj" "${workspaceFolder}/deploy-test/deploy-test.csproj"
], ],
"problemMatcher": "$msCompile" "problemMatcher": "$msCompile"
} }

View File

@ -24,7 +24,7 @@ namespace greyn.Deployment
*/ */
var actualConfig = JsonConvert.DeserializeObject<ExpandoObject>(File.ReadAllText(confpath)) ?? new ExpandoObject(); var actualConfig = JsonConvert.DeserializeObject<ExpandoObject>(File.ReadAllText(confpath)) ?? new ExpandoObject();
var toReturn = new T(); var toReturn = new T();
PopulateExpando(toReturn, ref actualConfig); populateExpando(toReturn, ref actualConfig);
File.WriteAllText(confpath, JsonConvert.SerializeObject(actualConfig, Formatting.Indented)); File.WriteAllText(confpath, JsonConvert.SerializeObject(actualConfig, Formatting.Indented));
readFromExpando(ref toReturn, actualConfig); readFromExpando(ref toReturn, actualConfig);
@ -39,71 +39,43 @@ namespace greyn.Deployment
} }
} }
//TODO: make private but get tests to cooperate... I think that's a c# limitation //TODO: make private but get tests to cooperate
internal static void PopulateExpando<T>(T config, ref ExpandoObject fromFile) public static void populateExpando<T>(T config, ref ExpandoObject fromFile)
{ {
if (config == null) return; if (config == null) return;
if (fromFile == null) if (fromFile == null)
{ {
fromFile = new ExpandoObject(); var expandoPopulated = new ExpandoObject();
var dictionaryFromExpandoPopulated = (IDictionary<string, object?>)expandoPopulated;
foreach (var property in config.GetType().GetProperties())
dictionaryFromExpandoPopulated.Add(property.Name, property.GetValue(config));
expandoPopulated = (ExpandoObject)dictionaryFromExpandoPopulated;
fromFile = expandoPopulated;
return;
} }
var dictionaryFromExpandoFromFile = (IDictionary<string, object?>)fromFile; var dictionaryFromExpandoFromFile = (IDictionary<string, object?>)fromFile;
foreach (var property in config.GetType().GetProperties())
foreach (var memberInfo in config.GetType().GetMembers())
{ {
if(memberInfo.DeclaringType == typeof(System.Object)) if (dictionaryFromExpandoFromFile.TryGetValue(property.Name, out object? value))
{ {
continue; if (value != null)
}
if(memberInfo.MemberType != MemberTypes.Field && memberInfo.MemberType != MemberTypes.Property)
{
continue;
}
if (dictionaryFromExpandoFromFile.TryGetValue(memberInfo.Name, out object? valueFromDict))
{
if (valueFromDict != null)
{ {
switch (memberInfo.MemberType) if (property.PropertyType.GetMembers() == null)
{ {
case MemberTypes.Field: var childProperty = (ExpandoObject)property.GetValue(fromFile);
var asField = (FieldInfo)memberInfo; populateExpando(property.GetValue(config), ref childProperty);
if (dictionaryFromExpandoFromFile[asField.Name] is ExpandoObject childMemberField) property.SetValue(fromFile, childProperty);
{
PopulateExpando(asField.GetValue(config), ref childMemberField);
}
break;
case MemberTypes.Property:
var asProperty = (PropertyInfo)memberInfo;
if (dictionaryFromExpandoFromFile[asProperty.Name] is ExpandoObject childMemberProperty)
{
PopulateExpando(asProperty.GetValue(config), ref childMemberProperty);
}
break;
default:
break;
} }
} }
} }
else else
{ {
switch (memberInfo.MemberType) fromFile.TryAdd(property.Name, property.GetValue(config));
{
case MemberTypes.Field:
fromFile.TryAdd(memberInfo.Name, ((FieldInfo)memberInfo).GetValue(config));
break;
case MemberTypes.Property:
fromFile.TryAdd(memberInfo.Name, ((PropertyInfo)memberInfo).GetValue(config));
break;
default:
break;
}
} }
} }
} }
internal static void readFromExpando<T>(ref T config, ExpandoObject readFromFile) public static void readFromExpando<T>(ref T config, ExpandoObject readFromFile)
{ {
//TODO: read from Expando //TODO: read from Expando
} }

View File

@ -108,7 +108,7 @@ public class ConfigTests
{ {
var toReturn = new AConfigurationType(); var toReturn = new AConfigurationType();
var actualConfig = parse(PerfectConfiguration); var actualConfig = parse(PerfectConfiguration);
greyn.Deployment.ConfigurationBootstrapper.PopulateExpando(toReturn, ref actualConfig); greyn.Deployment.ConfigurationBootstrapper.populateExpando(toReturn, ref actualConfig);
Assert.Pass(); Assert.Pass();
} }
#endregion #endregion
@ -139,8 +139,7 @@ public class ConfigTests
] ]
} }
}"); }");
greyn.Deployment.ConfigurationBootstrapper.PopulateExpando(new AConfigurationType(), ref actualConfig); greyn.Deployment.ConfigurationBootstrapper.populateExpando(new AConfigurationType(), ref actualConfig);
Console.WriteLine("survived populate expando");
var casted = (IDictionary<string, object?>)actualConfig; var casted = (IDictionary<string, object?>)actualConfig;
Console.WriteLine(casted["aValueTypeButNotAField"]); Console.WriteLine(casted["aValueTypeButNotAField"]);
Assert.Pass(); Assert.Pass();
@ -172,7 +171,7 @@ public class ConfigTests
] ]
} }
}"); }");
greyn.Deployment.ConfigurationBootstrapper.PopulateExpando(new AConfigurationType(), ref actualConfig); greyn.Deployment.ConfigurationBootstrapper.populateExpando(new AConfigurationType(), ref actualConfig);
var casted = (IDictionary<string, object?>)actualConfig; var casted = (IDictionary<string, object?>)actualConfig;
Console.WriteLine(casted["aField"]); Console.WriteLine(casted["aField"]);
Assert.Pass(); Assert.Pass();
@ -194,7 +193,7 @@ public class ConfigTests
] ]
} }
}"); }");
greyn.Deployment.ConfigurationBootstrapper.PopulateExpando(new AConfigurationType(), ref actualConfig); greyn.Deployment.ConfigurationBootstrapper.populateExpando(new AConfigurationType(), ref actualConfig);
var casted = (IDictionary<string, object?>)actualConfig; var casted = (IDictionary<string, object?>)actualConfig;
Console.WriteLine(casted["subtyped"]); Console.WriteLine(casted["subtyped"]);
Assert.Pass(); Assert.Pass();
@ -225,7 +224,7 @@ public class ConfigTests
] ]
} }
}"); }");
greyn.Deployment.ConfigurationBootstrapper.PopulateExpando(new AConfigurationType(), ref actualConfig); greyn.Deployment.ConfigurationBootstrapper.populateExpando(new AConfigurationType(), ref actualConfig);
var casted = (IDictionary<string, object?>)actualConfig; var casted = (IDictionary<string, object?>)actualConfig;
var subtypeCasted = (IDictionary<string, object?>)casted["subtyped"]; var subtypeCasted = (IDictionary<string, object?>)casted["subtyped"];
Console.WriteLine(subtypeCasted["aValueType"]); Console.WriteLine(subtypeCasted["aValueType"]);
@ -257,7 +256,7 @@ public class ConfigTests
] ]
} }
}"); }");
greyn.Deployment.ConfigurationBootstrapper.PopulateExpando(new AConfigurationType(), ref actualConfig); greyn.Deployment.ConfigurationBootstrapper.populateExpando(new AConfigurationType(), ref actualConfig);
var casted = (IDictionary<string, object?>)actualConfig; var casted = (IDictionary<string, object?>)actualConfig;
var subtypeCasted = (IDictionary<string, object?>)casted["subtyped"]; var subtypeCasted = (IDictionary<string, object?>)casted["subtyped"];
Console.WriteLine(subtypeCasted["aValueTypeButNotAField"]); Console.WriteLine(subtypeCasted["aValueTypeButNotAField"]);
@ -285,7 +284,7 @@ public class ConfigTests
] ]
} }
}"); }");
greyn.Deployment.ConfigurationBootstrapper.PopulateExpando(new AConfigurationType(), ref actualConfig); greyn.Deployment.ConfigurationBootstrapper.populateExpando(new AConfigurationType(), ref actualConfig);
var casted = (IDictionary<string, object?>)actualConfig; var casted = (IDictionary<string, object?>)actualConfig;
var subtypeCasted = (IDictionary<string, object?>)casted["subtyped"]; var subtypeCasted = (IDictionary<string, object?>)casted["subtyped"];
Console.WriteLine(subtypeCasted["anEnumerableType"]); Console.WriteLine(subtypeCasted["anEnumerableType"]);
@ -309,7 +308,7 @@ public class ConfigTests
] ]
} }
}"); }");
greyn.Deployment.ConfigurationBootstrapper.PopulateExpando(new AConfigurationType(), ref actualConfig); greyn.Deployment.ConfigurationBootstrapper.populateExpando(new AConfigurationType(), ref actualConfig);
var casted = (IDictionary<string, object?>)actualConfig; var casted = (IDictionary<string, object?>)actualConfig;
Assert.IsNull(casted["subtyped"]); Assert.IsNull(casted["subtyped"]);
} }
@ -341,7 +340,7 @@ public class ConfigTests
] ]
} }
}"); }");
greyn.Deployment.ConfigurationBootstrapper.PopulateExpando(new AConfigurationType(), ref actualConfig); greyn.Deployment.ConfigurationBootstrapper.populateExpando(new AConfigurationType(), ref actualConfig);
var casted = (IDictionary<string, object?>)actualConfig; var casted = (IDictionary<string, object?>)actualConfig;
Assert.IsNotNull(casted["hiImHereToo"]); Assert.IsNotNull(casted["hiImHereToo"]);
} }
@ -349,11 +348,10 @@ public class ConfigTests
public void populateExpando_populatesblank() public void populateExpando_populatesblank()
{ {
var actualConfig = parse("{}"); var actualConfig = parse("{}");
greyn.Deployment.ConfigurationBootstrapper.PopulateExpando(new AConfigurationType(), ref actualConfig); greyn.Deployment.ConfigurationBootstrapper.populateExpando(new AConfigurationType(), ref actualConfig);
dynamic casted = actualConfig; var casted = (IDictionary<string, object?>)actualConfig;
Console.WriteLine(JsonConvert.SerializeObject(casted, Formatting.Indented)); var subtypeCasted = (IDictionary<string, object?>)casted["subtyped"];
Console.WriteLine(subtypeCasted["aValueTypeButNotAField"]);
Console.WriteLine(casted.subtyped.aValueTypeButNotAField);
Assert.Pass(); Assert.Pass();
} }
[Test] [Test]