Compare commits
No commits in common. "dad0f9b3767a2062fd03149c058e3961223d1eaa" and "1033d2977d0ea1a6bf8aac49b52fb6d1644eb4e5" have entirely different histories.
dad0f9b376
...
1033d2977d
4
.vscode/launch.json
vendored
4
.vscode/launch.json
vendored
@ -10,9 +10,9 @@
|
||||
"request": "launch",
|
||||
"preLaunchTask": "build",
|
||||
// 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": [],
|
||||
"cwd": "${workspaceFolder}/deployment.tests",
|
||||
"cwd": "${workspaceFolder}/deploy-test",
|
||||
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
|
||||
"console": "internalConsole",
|
||||
"stopAtEntry": false
|
||||
|
6
.vscode/tasks.json
vendored
6
.vscode/tasks.json
vendored
@ -7,7 +7,7 @@
|
||||
"type": "process",
|
||||
"args": [
|
||||
"build",
|
||||
"${workspaceFolder}/deployment.tests/deployment.tests.csproj",
|
||||
"${workspaceFolder}/deploy-test/deploy-test.csproj",
|
||||
"/property:GenerateFullPaths=true",
|
||||
"/consoleloggerparameters:NoSummary;ForceNoAlign"
|
||||
],
|
||||
@ -19,7 +19,7 @@
|
||||
"type": "process",
|
||||
"args": [
|
||||
"publish",
|
||||
"${workspaceFolder}/deployment.tests/deployment.tests.csproj",
|
||||
"${workspaceFolder}/deploy-test/deploy-test.csproj",
|
||||
"/property:GenerateFullPaths=true",
|
||||
"/consoleloggerparameters:NoSummary;ForceNoAlign"
|
||||
],
|
||||
@ -33,7 +33,7 @@
|
||||
"watch",
|
||||
"run",
|
||||
"--project",
|
||||
"${workspaceFolder}/deployment.tests/deployment.tests.csproj"
|
||||
"${workspaceFolder}/deploy-test/deploy-test.csproj"
|
||||
],
|
||||
"problemMatcher": "$msCompile"
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ namespace greyn.Deployment
|
||||
*/
|
||||
var actualConfig = JsonConvert.DeserializeObject<ExpandoObject>(File.ReadAllText(confpath)) ?? new ExpandoObject();
|
||||
var toReturn = new T();
|
||||
PopulateExpando(toReturn, ref actualConfig);
|
||||
populateExpando(toReturn, ref actualConfig);
|
||||
File.WriteAllText(confpath, JsonConvert.SerializeObject(actualConfig, Formatting.Indented));
|
||||
|
||||
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
|
||||
internal static void PopulateExpando<T>(T config, ref ExpandoObject fromFile)
|
||||
//TODO: make private but get tests to cooperate
|
||||
public static void populateExpando<T>(T config, ref ExpandoObject fromFile)
|
||||
{
|
||||
if (config == null) return;
|
||||
|
||||
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;
|
||||
|
||||
foreach (var memberInfo in config.GetType().GetMembers())
|
||||
foreach (var property in config.GetType().GetProperties())
|
||||
{
|
||||
if(memberInfo.DeclaringType == typeof(System.Object))
|
||||
if (dictionaryFromExpandoFromFile.TryGetValue(property.Name, out object? value))
|
||||
{
|
||||
continue;
|
||||
if (value != null)
|
||||
{
|
||||
if (property.PropertyType.GetMembers() == null)
|
||||
{
|
||||
var childProperty = (ExpandoObject)property.GetValue(fromFile);
|
||||
populateExpando(property.GetValue(config), ref childProperty);
|
||||
property.SetValue(fromFile, childProperty);
|
||||
}
|
||||
if(memberInfo.MemberType != MemberTypes.Field && memberInfo.MemberType != MemberTypes.Property)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (dictionaryFromExpandoFromFile.TryGetValue(memberInfo.Name, out object? valueFromDict))
|
||||
{
|
||||
if (valueFromDict != null)
|
||||
{
|
||||
switch (memberInfo.MemberType)
|
||||
{
|
||||
case MemberTypes.Field:
|
||||
var asField = (FieldInfo)memberInfo;
|
||||
if (dictionaryFromExpandoFromFile[asField.Name] is ExpandoObject childMemberField)
|
||||
{
|
||||
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
|
||||
{
|
||||
switch (memberInfo.MemberType)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
fromFile.TryAdd(property.Name, property.GetValue(config));
|
||||
}
|
||||
}
|
||||
}
|
||||
internal static void readFromExpando<T>(ref T config, ExpandoObject readFromFile)
|
||||
public static void readFromExpando<T>(ref T config, ExpandoObject readFromFile)
|
||||
{
|
||||
//TODO: read from Expando
|
||||
}
|
||||
|
@ -108,7 +108,7 @@ public class ConfigTests
|
||||
{
|
||||
var toReturn = new AConfigurationType();
|
||||
var actualConfig = parse(PerfectConfiguration);
|
||||
greyn.Deployment.ConfigurationBootstrapper.PopulateExpando(toReturn, ref actualConfig);
|
||||
greyn.Deployment.ConfigurationBootstrapper.populateExpando(toReturn, ref actualConfig);
|
||||
Assert.Pass();
|
||||
}
|
||||
#endregion
|
||||
@ -139,8 +139,7 @@ public class ConfigTests
|
||||
]
|
||||
}
|
||||
}");
|
||||
greyn.Deployment.ConfigurationBootstrapper.PopulateExpando(new AConfigurationType(), ref actualConfig);
|
||||
Console.WriteLine("survived populate expando");
|
||||
greyn.Deployment.ConfigurationBootstrapper.populateExpando(new AConfigurationType(), ref actualConfig);
|
||||
var casted = (IDictionary<string, object?>)actualConfig;
|
||||
Console.WriteLine(casted["aValueTypeButNotAField"]);
|
||||
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;
|
||||
Console.WriteLine(casted["aField"]);
|
||||
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;
|
||||
Console.WriteLine(casted["subtyped"]);
|
||||
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 subtypeCasted = (IDictionary<string, object?>)casted["subtyped"];
|
||||
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 subtypeCasted = (IDictionary<string, object?>)casted["subtyped"];
|
||||
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 subtypeCasted = (IDictionary<string, object?>)casted["subtyped"];
|
||||
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;
|
||||
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;
|
||||
Assert.IsNotNull(casted["hiImHereToo"]);
|
||||
}
|
||||
@ -349,11 +348,10 @@ public class ConfigTests
|
||||
public void populateExpando_populatesblank()
|
||||
{
|
||||
var actualConfig = parse("{}");
|
||||
greyn.Deployment.ConfigurationBootstrapper.PopulateExpando(new AConfigurationType(), ref actualConfig);
|
||||
dynamic casted = actualConfig;
|
||||
Console.WriteLine(JsonConvert.SerializeObject(casted, Formatting.Indented));
|
||||
|
||||
Console.WriteLine(casted.subtyped.aValueTypeButNotAField);
|
||||
greyn.Deployment.ConfigurationBootstrapper.populateExpando(new AConfigurationType(), ref actualConfig);
|
||||
var casted = (IDictionary<string, object?>)actualConfig;
|
||||
var subtypeCasted = (IDictionary<string, object?>)casted["subtyped"];
|
||||
Console.WriteLine(subtypeCasted["aValueTypeButNotAField"]);
|
||||
Assert.Pass();
|
||||
}
|
||||
[Test]
|
||||
|
Loading…
Reference in New Issue
Block a user