SettingsCollection loadSettingsType(string type)
{
var filePath = getFileFromType(type);
if(!File.Exists(filePath))
{
return new SettingsCollection();
}
// cover case where SDK in another process might be writing to settings file,
// yielding IO contention exceptons
var retryAttempt = 0;
while (true)
{
try
{
string content;
using (var stream = File.OpenRead(filePath))
using (var reader = new StreamReader(stream))
{
content = reader.ReadToEnd();
}
var settings = JsonMapper.ToObject<Dictionary<string, Dictionary<string, object>>>(content);
if (settings == null)
settings = new Dictionary<string, Dictionary<string, object>>();
decryptAnyEncryptedValues(settings);
return new SettingsCollection(settings);
}
catch
{
if (retryAttempt < 5)
{
Thread.Sleep(1000);
retryAttempt++;
}
else
return new SettingsCollection(); // give up
}
}
}