ConfidenceControl.xaml.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Globalization;
  5. using System.Linq;
  6. using System.Runtime.CompilerServices;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows;
  10. using System.Windows.Controls;
  11. using System.Windows.Data;
  12. using System.Windows.Documents;
  13. using System.Windows.Input;
  14. using System.Windows.Media;
  15. using System.Windows.Media.Imaging;
  16. using System.Windows.Navigation;
  17. using System.Windows.Shapes;
  18. using ComPDFKit.Controls.DigitalSignature.CPDFSignatureListControl;
  19. using ComPDFKit.Controls.Properties;
  20. using ComPDFKit.DigitalSign;
  21. namespace ComPDFKit.Controls.PDFControl
  22. {
  23. /// <summary>
  24. /// Interaction logic for ConfidenceControl.xaml
  25. /// </summary>
  26. public partial class ConfidenceControl : UserControl, INotifyPropertyChanged
  27. {
  28. public static ResourceDictionary ResourceDictionary { get; set; }
  29. private bool isTrusted;
  30. private CPDFSignatureCertificate cpdfCertificate;
  31. public event EventHandler TrustCertificateEvent;
  32. public bool IsTrusted
  33. {
  34. get => isTrusted;
  35. set => UpdateProper(ref isTrusted, value);
  36. }
  37. public ConfidenceControl()
  38. {
  39. InitializeComponent();
  40. DataContext = this;
  41. ResourceDictionary = this.Resources;
  42. }
  43. public void LoadConfidenceInfo(CPDFSignatureCertificate certificate)
  44. {
  45. cpdfCertificate = certificate;
  46. VerifyCertificate();
  47. }
  48. public void VerifyCertificate()
  49. {
  50. if (cpdfCertificate != null)
  51. {
  52. cpdfCertificate.CheckCertificateIsTrusted();
  53. IsTrusted = cpdfCertificate.IsTrusted;
  54. }
  55. }
  56. public event PropertyChangedEventHandler PropertyChanged;
  57. protected void UpdateProper<T>(ref T properValue,
  58. T newValue,
  59. [CallerMemberName] string properName = "")
  60. {
  61. if (object.Equals(properValue, newValue))
  62. return;
  63. properValue = newValue;
  64. OnPropertyChanged(properName);
  65. }
  66. protected void OnPropertyChanged([CallerMemberName] string propertyName = "") =>
  67. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
  68. private void TrustCertificateButton_OnClick(object sender, RoutedEventArgs e)
  69. {
  70. cpdfCertificate.AddToTrustedCertificates();
  71. VerifyCertificate();
  72. TrustCertificateEvent?.Invoke(this, null);
  73. }
  74. }
  75. public class ConfidenceStatusToPathConverter : IValueConverter
  76. {
  77. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  78. {
  79. ResourceDictionary resourceDictionary = ConfidenceControl.ResourceDictionary;
  80. if (value is bool isTrusted)
  81. {
  82. if (isTrusted)
  83. {
  84. return resourceDictionary["ValidPath"];
  85. }
  86. else
  87. {
  88. return resourceDictionary["InvalidPath"];
  89. }
  90. }
  91. return null;
  92. }
  93. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  94. {
  95. return null;
  96. }
  97. }
  98. }