public void SaveSettings(PKSettingsModel settings) { if (settings == null) { return; } using (rwlock.Write()) { settingsModel = settings.Clone(); try { var serializer = new DataContractSerializer(typeof(PKSettingsModel)); 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(PKSettingsModel)); settingsModel = serializer.ReadObject(fs) as PKSettingsModel; return(settingsModel != null); } } } } catch (Exception ex) { LogProvider.Log.Error(CustomModulesNames.PKCatcher, "Could not load settings.", ex); } return(false); }