public static string SerializeXml(SPMSettings s) { try { return(SerializationHelper.SerializeXml(s)); } catch (Exception e) { // TODO: log return(null); } }
public async Task <bool> SaveCurrentSettings() { try { var file = await ApplicationData.Current.LocalFolder.CreateFileAsync(SETTINGS_FILE, CreationCollisionOption.ReplaceExisting); string content = SPMSettings.SerializeXml(settings); await FileIO.WriteTextAsync(file, content); } catch (Exception e) { // TODO: log return(false); } return(true); }
public async Task LoadSettings() { // determine whether a settings file already exists // if not, create it bool exists = false; StorageFile file = null; try { file = await ApplicationData.Current.LocalFolder.GetFileAsync(SETTINGS_FILE); exists = true; } catch (FileNotFoundException) { } catch (Exception e) { // TODO: log } // read the settings, or create a default one if (exists) { string content = await FileIO.ReadTextAsync(file); settings = SPMSettings.DeserializeXml(content); if (settings == null) { // TODO: log settings = new SPMSettings(); } } else { settings = new SPMSettings(); } }