FileRestrictedTipViewModel.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using ComPDFKitViewer.PdfViewer;
  2. using PDF_Office.EventAggregators;
  3. using PDF_Office.Helper;
  4. using PDF_Office.Model;
  5. using Prism.Commands;
  6. using Prism.Events;
  7. using Prism.Mvvm;
  8. using Prism.Regions;
  9. using Prism.Services.Dialogs;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.ComponentModel;
  13. using System.Linq;
  14. using System.Text;
  15. using System.Threading.Tasks;
  16. using static Dropbox.Api.Files.ThumbnailMode;
  17. using static PDF_Office.Model.Dialog.ToolsDialogs.SaftyDialogs.DeleteSafetySettintgsModel;
  18. namespace PDF_Office.ViewModels.TipContent
  19. {
  20. public class FileRestrictedTipViewModel : BindableBase, INavigationAware
  21. {
  22. public string unicode = null;
  23. public IEventAggregator eventAggregator;
  24. public IDialogService DialogService;
  25. private CPDFViewer PDFViewer;
  26. public DelegateCommand CloseTipCommand { get; set; }
  27. public DelegateCommand RestrictCommand { get; set; }
  28. public FileRestrictedTipViewModel(IEventAggregator eventAggregator, IDialogService dialogService)
  29. {
  30. this.eventAggregator = eventAggregator;
  31. this.DialogService = dialogService;
  32. unicode = App.mainWindowViewModel.SelectedItem.Unicode;
  33. CloseTipCommand = new DelegateCommand(CloseTip);
  34. RestrictCommand = new DelegateCommand(Restrict);
  35. }
  36. public void CloseTip()
  37. {
  38. this.eventAggregator.GetEvent<ShowTipEvent>().Publish(new ShowTipEventArgs() { enumTipKind = EnumTipKind.StatusNone, Unicode = unicode });
  39. }
  40. public void Restrict()
  41. {
  42. VerifyPasswordResult result = SecurityHelper.VerifyPasswordByPasswordKind(PDFViewer.Document, EnumPasswordKind.StatusPermissionsPassword, DialogService);
  43. if (result.IsDiscryptied)
  44. {
  45. if (result.Password != null)
  46. {
  47. string filePath = PDFViewer.Document.FilePath;
  48. PDFViewer.ReloadDocument();
  49. PDFViewer.Document.UnlockWithPassword(result.Password);
  50. }
  51. ///TODO:
  52. ///此处填入需要执行的代码
  53. this.eventAggregator.GetEvent<ShowTipEvent>().Publish(new ShowTipEventArgs() { enumTipKind = EnumTipKind.StatusNone, Unicode = unicode });
  54. }
  55. }
  56. public bool IsNavigationTarget(NavigationContext navigationContext)
  57. {
  58. return true;
  59. }
  60. public void OnNavigatedFrom(NavigationContext navigationContext)
  61. {
  62. }
  63. public void OnNavigatedTo(NavigationContext navigationContext)
  64. {
  65. navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
  66. }
  67. }
  68. }