DigitalSignatureValiditySummaaryControl.xaml.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. using System;
  2. using System.Collections.Specialized;
  3. using System.ComponentModel;
  4. using System.Linq;
  5. using System.Runtime.CompilerServices;
  6. using System.Windows.Controls;
  7. using ComPDFKit.Controls.Helper;
  8. using ComPDFKit.DigitalSign;
  9. namespace ComPDFKit.Controls.PDFControl
  10. {
  11. public partial class DigitalSignatureValiditySummaaryControl : UserControl, INotifyPropertyChanged
  12. {
  13. private string _validitySummaryString;
  14. public string ValiditySummaryString
  15. {
  16. get => _validitySummaryString;
  17. set => UpdateProper(ref _validitySummaryString, value);
  18. }
  19. public DigitalSignatureValiditySummaaryControl()
  20. {
  21. InitializeComponent();
  22. DataContext = this;
  23. }
  24. public void InitWithSignature(CPDFSignature signature)
  25. {
  26. bool isSignVerified = signature.SignerList.First().IsSignVerified;
  27. bool isCertTrusted = signature.SignerList.First().IsCertTrusted;
  28. bool isDocModified = signature.ModifyInfoList.Count > 0;
  29. bool isExpired = DateTime.Now >
  30. CommonHelper.GetDateTimeFromString(signature.SignerList.First().CertificateList.First().ValidityEnds);
  31. string validitySummaryString = "";
  32. if (isCertTrusted)
  33. {
  34. validitySummaryString += LanguageHelper.SigManager.GetString("Text_SignerValid") + "\n\n";
  35. }
  36. else
  37. {
  38. validitySummaryString += LanguageHelper.SigManager.GetString("Text_SignerInvalid") + "\n\n";
  39. }
  40. if(isDocModified || (!isSignVerified && !isCertTrusted))
  41. {
  42. validitySummaryString += LanguageHelper.SigManager.GetString("Text_SigInvalid") + "\n\n";
  43. }
  44. else if (isSignVerified && isCertTrusted)
  45. {
  46. validitySummaryString += LanguageHelper.SigManager.GetString("Text_SigValid") + "\n\n";
  47. }
  48. else if(isSignVerified && !isCertTrusted)
  49. {
  50. validitySummaryString += LanguageHelper.SigManager.GetString("Text_SigUnknown") + "\n\n";
  51. }
  52. if(isExpired)
  53. {
  54. validitySummaryString += LanguageHelper.SigManager.GetString("Text_SigExpired") + "\n\n";
  55. }
  56. if (!isDocModified)
  57. {
  58. validitySummaryString += LanguageHelper.SigManager.GetString("Text_SigNoModified") + "\n";
  59. }
  60. else
  61. {
  62. validitySummaryString += LanguageHelper.SigManager.GetString("Text_SigModified") + "\n";
  63. }
  64. ValiditySummaryString = validitySummaryString;
  65. }
  66. public event PropertyChangedEventHandler PropertyChanged;
  67. protected void UpdateProper<T>(ref T properValue,
  68. T newValue,
  69. [CallerMemberName] string properName = "")
  70. {
  71. if (object.Equals(properValue, newValue))
  72. return;
  73. properValue = newValue;
  74. OnPropertyChanged(properName);
  75. }
  76. protected void OnPropertyChanged([CallerMemberName] string propertyName = "") =>
  77. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
  78. }
  79. }