/// <summary> /// Load local notebooks /// </summary> /// <returns></returns> static async public Task LoadAsync() { var storage = Windows.Storage.ApplicationData.Current.LocalFolder; var folder = await storage.CreateFolderAsync(FolderNames.Notebooks.ToString(), CreationCollisionOption.OpenIfExists); var notebooks = new ObservableCollection <NoteDataCommon>(); List <Type> types = new List <Type>(); types.Add(typeof(FoodDataItem)); types.Add(typeof(NoteDataItem)); types.Add(typeof(ToDoDataItem)); types.Add(typeof(NoteBook)); NotesDataSource.Unload(); DataContractJsonSerializer des = new DataContractJsonSerializer(typeof(NoteDataCommon), types); var files = await folder.GetFilesAsync(); foreach (var file in files) { try { using (var stream = await file.OpenReadAsync()) { var noteB = (NoteDataCommon)des.ReadObject(stream.AsStreamForRead()); NotesDataSource.AddNoteBook(noteB); } } catch { Helpers.ShowErrorMessageAsync("Load Notebooks", "The application found data corruption."); } } }
/// <summary> /// Populates the page with content passed during navigation. Any saved state is also /// provided when recreating a page from a prior session. /// </summary> /// <param name="navigationParameter">The parameter value passed to /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested. /// </param> /// <param name="pageState">A dictionary of state preserved by this page during an earlier /// session. This will be null the first time a page is visited.</param> protected override void LoadState(Object navigationParameter, Dictionary <String, Object> pageState) { if (navigationParameter != null) { InitializeFirstTimeData(); } else { NotesDataSource.Unload(); } }