public async Task LoadBook(FileData file) { try { await _loadingPopup.Show(); var(book, _) = await _bookshelfService.AddBook(file); await LoadBook(book); } catch (Exception e) { var ext = string.Empty; if (!string.IsNullOrEmpty(file.FileName)) { ext = Path.GetExtension(file.FileName); } Analytics.TrackEvent("Failed to open book", new Dictionary <string, string> { { "Extension", ext } }); Crashes.TrackError(e, new Dictionary <string, string> { { "Filename", file.FileName } }); Debug.WriteLine(e.Message); Debug.WriteLine(e.StackTrace); await DisplayAlert("Error", "Failed to open this ebook file.", "OK"); } await _loadingPopup.Hide(); }
private async Task OpenPickedBook(FileData pickedFile) { await Navigation.PushPopupAsync(_loadingPopup); try { var(book, isNew) = await _bookshelfService.AddBook(pickedFile); if (isNew) { Bookshelf.Children.Add(new BookCard(book)); } await Navigation.RemovePopupPageAsync(_loadingPopup); SendBookToReader(book); } catch (Exception e) { var ext = string.Empty; if (!string.IsNullOrEmpty(pickedFile.FileName)) { ext = System.IO.Path.GetExtension(pickedFile.FileName); } Analytics.TrackEvent("Failed to open book", new Dictionary <string, string> { { "Extension", ext } }); Crashes.TrackError(e, new Dictionary <string, string> { { "Filename", pickedFile.FileName } }); Debug.WriteLine(e.Message); Debug.WriteLine(e.StackTrace); await DisplayAlert("Error", "Failed to open this ebook file.", "OK"); } await _loadingPopup.Hide(); }
private async void AddBook(AddBookClickedMessage msg) { var permissionStatus = await PermissionHelper.CheckAndRequestPermission(Plugin.Permissions.Abstractions.Permission.Storage); if (permissionStatus == Plugin.Permissions.Abstractions.PermissionStatus.Granted) { var pickedFile = await CrossFilePicker.Current.PickFile(); if (pickedFile != null) { try { var book = await _bookshelfService.AddBook(pickedFile); if (book.Item2) { Bookshelf.Children.Add(new BookCard(book.Item1)); } this.SendBookToReader(book.Item1); } catch (Exception e) { var ext = string.Empty; if (!string.IsNullOrEmpty(pickedFile.FileName)) { ext = pickedFile.FileName.Split('.').LastOrDefault(); } Analytics.TrackEvent("Failed to open book", new Dictionary <string, string> { { "Extension", ext } }); Crashes.TrackError(e, new Dictionary <string, string> { { "Filename", pickedFile.FileName } }); await DisplayAlert("Error", "File failed to open", "OK"); } } } else { await DisplayAlert("Permission not granted", "Cannot open book without storage permissions.", "OK"); } }