/// <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.");
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Create new Notebook
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void btnAddNBClick(object sender, RoutedEventArgs e)
        {
            var addNbPop = this.FindName("popupAddNoteBook") as Popup;
            var nbText   = this.FindName("txtNbName") as TextBox;

            if (string.IsNullOrEmpty(nbText.Text))
            {
                Helpers.ShowMessageAsync("Notebook Title can't be empty", "Create Notebook");
                return;
            }

            //Creates new Notebook with user text
            var nb = new NoteBook(nbText.Text);

            //Adding notebook to main collection
            NotesDataSource.AddNoteBook(nb);

            //Saving new notebook.
            DataManager.Save(nb);
            addNbPop.IsOpen = false;
            this.Frame.Navigate(typeof(GroupDetailPage), nb.UniqueId);
        }