private void ReadFromIniFile([NotNull] string path)
{
try
{
using (var reader = new StreamReader(path, Encoding.UTF8))
_iniData = new StreamIniDataParser().ReadData(reader);
}
#region Error handling
catch (ParsingException ex)
{
// Wrap exception to add context information
throw new InvalidDataException(string.Format(Resources.ProblemLoadingConfigFile, path), ex);
}
#endregion
if (!_iniData.Sections.ContainsSection(GlobalSection)) return;
var global = _iniData[GlobalSection];
foreach (var property in _metaData)
{
string key = property.Key;
if (property.Value.NeedsEncoding) key += Base64Suffix;
if (global.ContainsKey(key))
{
try
{
property.Value.Value = property.Value.NeedsEncoding
? global[key].Base64Utf8Decode()
: global[key];
}
#region Error handling
catch (FormatException ex)
{
// Wrap exception to add context information
throw new InvalidDataException(string.Format(Resources.ProblemLoadingConfigValue, property.Key, path), ex);
}
#endregion
}
}
}