//Method to scrape text from html using HTMLAgility pack private async void getHtml() { //Using webview class method to execute sript on html document which will get all html data String html = await wikiView.InvokeScriptAsync("eval", new string[] { "document.documentElement.outerHTML;" }); //HtmlDoument object to load HTML from string HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(html); //variable to store html element data by it id, which in this case is "bodyContent", this text will be the info we save to storage var text = doc.GetElementbyId("bodyContent"); //variable to store file name of scrapped text, we get it by element id which is "firstHeading" var fileName = doc.GetElementbyId("firstHeading"); //If text is not null if (text != null) { //we use Storage class to store document with text and its name storage.storeDocument(fileName.InnerText, text.InnerText); //Message to inform user of succesful saving to storage var dialog = new MessageDialog("Document saved to storage."); await dialog.ShowAsync(); } //If text is null, when something went wrong and we display message else { var dialog = new MessageDialog("Document not suitable for saving."); await dialog.ShowAsync(); } }
//Save document to app local storage private async void AppBarButton_Save(object sender, RoutedEventArgs e) { //Create new Storage object storage = new StorageClass(); //Create textbox for new file name input TextBox inputTextBox = new TextBox(); inputTextBox.AcceptsReturn = false; inputTextBox.Height = 32; //Create content dialog box ContentDialog dialog = new ContentDialog(); //Load inputTextBox to dialog content dialog.Content = inputTextBox; dialog.Title = "Enter Document Name"; dialog.IsSecondaryButtonEnabled = true; dialog.PrimaryButtonText = "Ok"; //If file name text box is not empty save document to local storage with specified name and editor contents if (await dialog.ShowAsync() == ContentDialogResult.Primary && inputTextBox.Text != null && inputTextBox.Text != "") { storage.storeDocument(inputTextBox.Text, editor.Text); } //If file name is empty display error message else { var errorDialog = new MessageDialog("Please enter file name."); noFileName(); async void noFileName() { await errorDialog.ShowAsync(); } } }