ScanPropertyPanelViewModel.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. using ComPDFKitViewer.PdfViewer;
  2. using PDF_Master.EventAggregators;
  3. using PDF_Master.Model;
  4. using Prism.Commands;
  5. using Prism.Events;
  6. using Prism.Mvvm;
  7. using Prism.Regions;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Collections.ObjectModel;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. namespace PDF_Master.ViewModels.PropertyPanel.Scan
  15. {
  16. class ScanPropertyPanelViewModel : BindableBase, INavigationAware
  17. {
  18. private int pageCount;
  19. public int PageCount
  20. {
  21. get { return pageCount; }
  22. set
  23. {
  24. SetProperty(ref pageCount, value);
  25. }
  26. }
  27. private List<int> setPageRange;
  28. public List<int> SetPageRange
  29. {
  30. get { return setPageRange; }
  31. set
  32. {
  33. SetProperty(ref setPageRange, value);
  34. }
  35. }
  36. private CPDFViewer PDFViewer;
  37. public IEventAggregator events;
  38. public DelegateCommand OCRCommand { get; set; }
  39. public DelegateCommand AreaCommand { get; set; }
  40. public DelegateCommand UnknownCommand { get; set; }
  41. public bool IsNavigationTarget(NavigationContext navigationContext)
  42. {
  43. return true;
  44. }
  45. public void OnNavigatedFrom(NavigationContext navigationContext)
  46. {
  47. return;
  48. }
  49. public void OnNavigatedTo(NavigationContext navigationContext)
  50. {
  51. navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
  52. if (PDFViewer == null)
  53. {
  54. return;
  55. }
  56. else
  57. {
  58. PageCount = PDFViewer.Document.PageCount;
  59. }
  60. }
  61. public ScanPropertyPanelViewModel(IEventAggregator eventAggregator)
  62. {
  63. setPageRange = new List<int>();
  64. events = eventAggregator;
  65. OCRCommand = new DelegateCommand(OCR);
  66. AreaCommand = new DelegateCommand(Area);
  67. UnknownCommand = new DelegateCommand(Unknown);
  68. }
  69. private void OCR()
  70. {
  71. try
  72. {
  73. events.GetEvent<ScanEvent>().Publish(new ScanEventArgs()
  74. {
  75. Unicode = App.mainWindowViewModel.SelectedItem.Unicode,
  76. PageRange = SetPageRange,
  77. Mode = ScanMode.OCR,
  78. ScanLanguage = ScanLanguageMode.ChineseS
  79. }
  80. );
  81. }
  82. catch
  83. {
  84. }
  85. }
  86. private void Area()
  87. {
  88. try
  89. {
  90. events.GetEvent<ScanEvent>().Publish(new ScanEventArgs()
  91. {
  92. Unicode = App.mainWindowViewModel.SelectedItem.Unicode,
  93. PageRange = SetPageRange,
  94. Mode = ScanMode.Area,
  95. ScanLanguage = ScanLanguageMode.ChineseS
  96. }
  97. );
  98. }
  99. catch
  100. {
  101. }
  102. }
  103. private void Unknown()
  104. {
  105. try
  106. {
  107. events.GetEvent<ScanEvent>().Publish(new ScanEventArgs()
  108. {
  109. Unicode = App.mainWindowViewModel.SelectedItem.Unicode,
  110. PageRange = SetPageRange,
  111. Mode = ScanMode.Unknown,
  112. ScanLanguage = ScanLanguageMode.ChineseS
  113. }
  114. );
  115. }
  116. catch
  117. {
  118. }
  119. }
  120. }
  121. }