FileRestrictedTipViewModel.cs 2.5 KB

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