private void SavePreferenceContainer(PreferenceContainer container) { if (!preferenceSetFile.Directory.Exists) { preferenceSetFile.Directory.Create(); } using (var writer = new StreamWriter(preferenceSetFile.Open(FileMode.Create, FileAccess.Write, FileShare.None))) { XmlSerializer.Serialize(writer, container); } }
public void Commit() { if (modified) { PreferenceContainer container = new PreferenceContainer(); foreach (var pair in contents) { container.Settings.Add(new PreferenceSetting(pair.Key, pair.Value)); } SavePreferenceContainer(container); cachedTimestamp = GetTimestamp(); modified = false; } }
private void EnsureLoaded() { if (!cachedTimestamp.HasValue) { cachedTimestamp = GetTimestamp(); if (cachedTimestamp.HasValue) { PreferenceContainer container = LoadPreferenceContainer(); if (container != null) { foreach (var setting in container.Settings) { contents[setting.Name] = setting.Value; } } } } }