Advertisement
Guest User

HomePage.cs > OpenDocument

a guest
Jan 20th, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. public static async Task OpenDocument(string filePath, bool? canShare, bool? canPrint) {
  2. await Mask();
  3. ctx.printButton.IsVisible = false;
  4. ctx.shareButton.IsVisible = false;
  5.  
  6. //DEBUG
  7. string loaded = LoadedFilePath;
  8.  
  9. if (LoadedFilePath == filePath) {
  10. await Unmask();
  11. return;
  12. }
  13.  
  14. string typeFile = MimeTypeMap.GetMimeType(Path.GetExtension(filePath));
  15.  
  16. if (typeFile.Equals("application/pdf")) {
  17. try {
  18. ShowPDFView(filePath, canShare, canPrint);
  19. } catch (Exception e) {
  20. Utils.Utils.Log(e.Message);
  21. await LogController.AddErrorLog(e.Message, e.StackTrace);
  22. }
  23. } else if (typeFile.Equals("application/vnd.ms-powerpoint") || (typeFile.Equals("application/vnd.openxmlformats-officedocument.presentationml.presentation"))) {
  24. try {
  25. string newPathName = filePath + "converted.pdf";
  26. System.IO.File.Move(filePath, newPathName);
  27. MemoryStream stream = await DocumentController.PptxToPdfViewerAsync(newPathName);
  28. ShowPDFView(newPathName, canShare, canPrint);
  29. } catch (Exception e) {
  30. Utils.Utils.Log(e.Message);
  31. await LogController.AddErrorLog(e.Message, e.StackTrace);
  32. }
  33. } else if (typeFile.Equals("video/mp4")) {
  34. try {
  35. ShowMediaView(filePath);
  36. } catch (Exception e) {
  37. Utils.Utils.Log(e.Message);
  38. await LogController.AddErrorLog(e.Message, e.StackTrace);
  39. }
  40. } else if (typeFile.Equals("image/jpeg") || typeFile.Equals("image/png")) {
  41. try {
  42. ShowImageView(filePath);
  43. } catch (Exception e) {
  44. Utils.Utils.Log(e.Message);
  45. await LogController.AddErrorLog(e.Message, e.StackTrace);
  46. }
  47. } else if (typeFile.Equals("application/zip")) {
  48. try {
  49.  
  50. string extractedDir = Path.GetFileName(DocumentController.ExtractZipFile(filePath));
  51. string htmlFilePath = Path.Combine(DependencyService.Get<IAppHelper>().getBaseUrl(), extractedDir + "/index.html");
  52.  
  53. ShowWebView(htmlFilePath);
  54. } catch (Exception e) {
  55. Utils.Utils.Log(e.Message);
  56. await LogController.AddErrorLog(e.Message, e.StackTrace);
  57. }
  58. }
  59.  
  60. HomePage.LoadedFilePath = filePath;
  61. await Unmask();
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement