Skip to content

Commit

Permalink
Re-ordering config/yaml structure. Adding IgnoreUnmatchedProperties
Browse files Browse the repository at this point in the history
… to YAML deserializer.
  • Loading branch information
SasaKaranovic committed Jan 17, 2024
1 parent dbecb71 commit 80fb59b
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions VU1WPF/ClassConfigurationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ class ConfigContentsDial

class ConfigContentsRoot
{
public List<ConfigContentsDial> dial_metrics { get; set; }
public float dialUpdatePeriod { get; set; } = 0.5F;
public String masterKey { get; set; } = "cTpAWYuRpA2zx75Yh961Cg";
public float dialUpdatePeriod { get; set; } = 0.5F;

public List<ConfigContentsDial> dial_metrics { get; set; }

public ConfigContentsRoot()
{
Expand Down Expand Up @@ -244,6 +245,7 @@ private void LoadConfigFile()

var deserializer = new DeserializerBuilder()
.WithNamingConvention(UnderscoredNamingConvention.Instance)
.IgnoreUnmatchedProperties()
.Build();
Trace.WriteLine(fileContents);
var p = deserializer.Deserialize<ConfigContentsRoot>(fileContents);
Expand Down Expand Up @@ -274,19 +276,29 @@ private void LoadConfigFile()

public void SaveConfigFile()
{
string path = pathConfigFile + pathFileName;
/*
var serializer = new SerializerBuilder()
.WithNamingConvention(UnderscoredNamingConvention.Instance)
.Build();
var yaml = serializer.Serialize(localConfig);
*/
// Trace.WriteLine(yaml);

Trace.WriteLine(yaml);

string path = pathConfigFile + pathFileName;
using (var fs = new FileStream(path, FileMode.OpenOrCreate))
using (var sw = new StreamWriter(fs))
{
sw.WriteLine(yaml);
using (StreamWriter streamWriter = new StreamWriter(path))
{
Serializer serializer = (Serializer)new SerializerBuilder().WithNamingConvention(UnderscoredNamingConvention.Instance).Build();
serializer.Serialize(streamWriter, localConfig);
}


/*
using (var fs = new FileStream(path, FileMode.OpenOrCreate))
using (var sw = new StreamWriter(fs))
{
sw.WriteLine(yaml);
}*/

}
}
}

0 comments on commit 80fb59b

Please sign in to comment.