SignatureStatusBarControl.xaml.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Linq;
  5. using System.Runtime.CompilerServices;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using ComPDFKit.Controls.Helper;
  9. using ComPDFKit.DigitalSign;
  10. namespace ComPDFKit.Controls.PDFControl
  11. {
  12. public enum SignatureStatus
  13. {
  14. None,
  15. Valid,
  16. Invalid,
  17. MultiSig,
  18. Unknown,
  19. }
  20. public partial class SignatureStatusBarControl : UserControl, INotifyPropertyChanged
  21. {
  22. private string _messageString;
  23. public string MessageString
  24. {
  25. get => _messageString;
  26. set => UpdateProper(ref _messageString, value);
  27. }
  28. private string validString = LanguageHelper.SigManager.GetString("Text_SignerValid");
  29. private string invalidString = LanguageHelper.SigManager.GetString("Text_SignerInvalid");
  30. private string multiSigString = LanguageHelper.SigManager.GetString("Text_MultiSig");
  31. private string unknownString = LanguageHelper.SigManager.GetString("Text_SigUnknown");
  32. public event EventHandler OnViewSignatureButtonClicked;
  33. private SignatureStatus _status;
  34. public SignatureStatus Status
  35. {
  36. get => _status;
  37. set
  38. {
  39. _status = value;
  40. SetStatus(_status);
  41. }
  42. }
  43. public SignatureStatusBarControl()
  44. {
  45. InitializeComponent();
  46. DataContext = this;
  47. }
  48. private void SetStatus(SignatureStatus status)
  49. {
  50. ValidBorder.Visibility = Visibility.Collapsed;
  51. InvalidBorder.Visibility = Visibility.Collapsed;
  52. UnknownBorder.Visibility = Visibility.Collapsed;
  53. switch (status)
  54. {
  55. case SignatureStatus.None:
  56. MessageString = "";
  57. Visibility = Visibility.Collapsed;
  58. break;
  59. case SignatureStatus.Valid:
  60. ValidBorder.Visibility = Visibility.Visible;
  61. Visibility = Visibility.Visible;
  62. MessageString = validString;
  63. break;
  64. case SignatureStatus.Invalid:
  65. InvalidBorder.Visibility = Visibility.Visible;
  66. Visibility = Visibility.Visible;
  67. MessageString = invalidString;
  68. break;
  69. case SignatureStatus.MultiSig:
  70. InvalidBorder.Visibility = Visibility.Visible;
  71. Visibility = Visibility.Visible;
  72. MessageString = multiSigString;
  73. break;
  74. case SignatureStatus.Unknown:
  75. UnknownBorder.Visibility = Visibility.Visible;
  76. Visibility = Visibility.Visible;
  77. MessageString = unknownString;
  78. break;
  79. }
  80. }
  81. public void SetStatus(List<CPDFSignature> signatureList)
  82. {
  83. SignatureStatus status;
  84. if (signatureList.Count == 1)
  85. {
  86. bool isTrusted = true;
  87. bool isVerified = true;
  88. bool notModified = true;
  89. foreach (var signature in signatureList)
  90. {
  91. CPDFSigner signer = signature.SignerList.First();
  92. if(signer.IsSignVerified == false)
  93. isVerified = false;
  94. if (signer.IsCertTrusted == false)
  95. isTrusted = false;
  96. if (signature.ModifyInfoList.Count > 0)
  97. notModified = false;
  98. }
  99. if (isTrusted && isVerified && notModified)
  100. {
  101. status = SignatureStatus.Valid;
  102. }
  103. else if (!isTrusted && isVerified && notModified)
  104. {
  105. status = SignatureStatus.Unknown;
  106. }
  107. else
  108. {
  109. status = SignatureStatus.Invalid;
  110. }
  111. }
  112. else if (signatureList.Count > 1)
  113. {
  114. status = SignatureStatus.MultiSig;
  115. }
  116. else
  117. {
  118. status = SignatureStatus.None;
  119. }
  120. Status = status;
  121. }
  122. public event PropertyChangedEventHandler PropertyChanged;
  123. protected void UpdateProper<T>(ref T properValue,
  124. T newValue,
  125. [CallerMemberName] string properName = "")
  126. {
  127. if (object.Equals(properValue, newValue))
  128. return;
  129. properValue = newValue;
  130. OnPropertyChanged(properName);
  131. }
  132. protected void OnPropertyChanged([CallerMemberName] string propertyName = "") =>
  133. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
  134. private void ButtonViewSignature_OnClick(object sender, RoutedEventArgs e)
  135. {
  136. OnViewSignatureButtonClicked?.Invoke(this,null);
  137. }
  138. }
  139. }