public static async Task <AppState> LoadAppStateInitial() { var file = await TryLoadConfigFile().ConfigureAwait(false); AppState resultState = new AppState(); // app state no yet stored if (file == null) { await StoreInitialAppState(resultState); } else { try { resultState = await XMLStorage.ReadObjectFromXmlFileAsync <AppState>(file).ConfigureAwait(false); } catch (Exception ex) { // try to overwrite inconsistent state or crash await StoreInitialAppState(resultState); } } return(resultState); }
internal static async Task <AppState> LoadAppStateFromUserDefinedLocation() { AppState resultState = null; var loadConfigPicker = new FileOpenPicker(); loadConfigPicker.ViewMode = PickerViewMode.List; loadConfigPicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary; loadConfigPicker.FileTypeFilter.Add(".xml"); StorageFile file = await loadConfigPicker.PickSingleFileAsync(); if (file != null) { var token = StorageApplicationPermissions.FutureAccessList.Add(file, _userDefinedSettingsToken); LocalSettings.Values[_userDefinedSettingsToken] = token; resultState = await XMLStorage.ReadObjectFromXmlFileAsync <AppState>(file); } else { Debug.WriteLine("Loading file was cancelled."); } return(resultState); }