public static async Task <PersonalMinimums> LoadAsync() { var roamingFolder = Windows.Storage.ApplicationData.Current.RoamingFolder; var deleteFile = false; PersonalMinimums result = new PersonalMinimums(); try { var file = await roamingFolder.GetFileAsync(PersonalMinimumsFile); using (var stream = await file.OpenStreamForReadAsync()) { var serializer = new DataContractSerializer(typeof(PersonalMinimums)); result = serializer.ReadObject(stream) as PersonalMinimums; } } catch (FileNotFoundException) { Debug.WriteLine("No minimums file."); } catch (SerializationException) { Debug.WriteLine("Personal Minimums file corruption detected - deleting."); deleteFile = true; } if (deleteFile) { try { var file = await roamingFolder.GetFileAsync(PersonalMinimumsFile); await file.DeleteAsync(); } catch (Exception ex) { Debug.WriteLine("Could not delete Minimums file: " + ex.Message); } } return(result); }
public static async Task<PersonalMinimums> LoadAsync() { var roamingFolder = Windows.Storage.ApplicationData.Current.RoamingFolder; var deleteFile = false; PersonalMinimums result = new PersonalMinimums(); try { var file = await roamingFolder.GetFileAsync(PersonalMinimumsFile); using (var stream = await file.OpenStreamForReadAsync()) { var serializer = new DataContractSerializer(typeof(PersonalMinimums)); result = serializer.ReadObject(stream) as PersonalMinimums; } } catch (FileNotFoundException) { Debug.WriteLine("No minimums file."); } catch (SerializationException) { Debug.WriteLine("Personal Minimums file corruption detected - deleting."); deleteFile = true; } if (deleteFile) { try { var file = await roamingFolder.GetFileAsync(PersonalMinimumsFile); await file.DeleteAsync(); } catch (Exception ex) { Debug.WriteLine("Could not delete Minimums file: " + ex.Message); } } return result; }
public async Task LoadAsync() { this.DataSources = new ObservableCollection<DataSourceViewModel>(App.DataSourceManager.DataSources.Select(s => new DataSourceViewModel(App.DataSourceManager, s.Key))); this.Minimums = await PersonalMinimums.LoadAsync(); }