public void SaveSettings(PMSettingsModel settings) { if (settings == null) { return; } using (rwlock.Write()) { settingsModel = settings.Clone(); try { var serializer = new DataContractSerializer(typeof(PMSettingsModel)); using (var fs = File.Open(settingsFileName, FileMode.Create)) { using (var writer = new XmlTextWriter(fs, Encoding.UTF8)) { writer.Formatting = Formatting.Indented; serializer.WriteObject(writer, settingsModel); } } } catch (Exception e) { LogProvider.Log.Error(this, e); } } }
private bool TryLoad() { try { using (rwlock.Write()) { if (File.Exists(settingsFileName)) { using (var fs = File.Open(settingsFileName, FileMode.Open)) { var serializer = new DataContractSerializer(typeof(PMSettingsModel)); settingsModel = serializer.ReadObject(fs) as PMSettingsModel; return(settingsModel != null); } } } } catch (Exception ex) { LogProvider.Log.Error(CustomModulesNames.PMCatcher, "Could not load settings.", ex); } return(false); }