private DbSetSettings GetSettings(bool cached) { if (cached) { if (_settingsCached == null) { _settingsCached = GetSettings(false); } return(_settingsCached); } var fileName = _fileManager.CombineDirectories(_inDir, FileEngineDefaults.SetSettingsName); if (!_fileManager.FileExists(fileName)) { ChangeSettings(new DbSetSettings(), false); } try { var serializer = new XmlSerializer(typeof(DbSetSettings)); var settings = new XmlReaderSettings(); using (var textReader = new StreamReader(_fileManager.FileReadStream(fileName))) { var xmlReader = XmlReader.Create(textReader, settings); return((serializer.Deserialize(xmlReader) as DbSetSettings) ?? new DbSetSettings()); } } catch (InvalidOperationException) // XML niet in juiste format { //ChangeSettings(nieuw, false); return(new DbSetSettings()); } }
private void ChangeSettings(DbSetSettings newSettings, bool cached) { try { var fileName = _fileManager.CombineDirectories(_inDir, FileEngineDefaults.SetSettingsName); var serializer = new XmlSerializer(typeof(DbSetSettings)); using (var sw = new StreamWriter(_fileManager.FileWriteStream(fileName))) { serializer.Serialize(sw, newSettings); sw.Flush(); } } finally { if (cached) { _settingsCached = newSettings; } } }