DigitalSignatureValiditySummaaryControl.xaml.cs 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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_Tools.Helper;
  8. using ComPDFKit.DigitalSign;
  9. namespace Compdfkit_Tools.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_SigValid") + "\n\n";
  43. }
  44. else if (isSignVerified && isCertTrusted)
  45. {
  46. validitySummaryString += LanguageHelper.SigManager.GetString("Text_SigInvalid") + "\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. }