SummaryControl.xaml.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Linq;
  5. using System.Runtime.CompilerServices;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows;
  9. using System.Windows.Controls;
  10. using System.Windows.Data;
  11. using System.Windows.Documents;
  12. using System.Windows.Input;
  13. using System.Windows.Media;
  14. using System.Windows.Media.Imaging;
  15. using System.Windows.Navigation;
  16. using System.Windows.Shapes;
  17. using ComPDFKit.Controls.Helper;
  18. using ComPDFKit.DigitalSign;
  19. namespace ComPDFKit.Controls.PDFControl
  20. {
  21. /// <summary>
  22. /// Interaction logic for SummaryControl.xaml
  23. /// </summary>
  24. public partial class SummaryControl : UserControl,INotifyPropertyChanged
  25. {
  26. private string award;
  27. public string Award
  28. {
  29. get => award;
  30. set => UpdateProper(ref award, value);
  31. }
  32. private string grantor;
  33. public string Grantor
  34. {
  35. get => grantor;
  36. set => UpdateProper(ref grantor, value);
  37. }
  38. private string validityFrom;
  39. public string ValidityFrom
  40. {
  41. get => validityFrom;
  42. set => UpdateProper(ref validityFrom, value);
  43. }
  44. private string validityTo;
  45. public string ValidityTo
  46. {
  47. get => validityTo;
  48. set => UpdateProper(ref validityTo, value);
  49. }
  50. private string intendedUsage;
  51. public string IntendedUsage
  52. {
  53. get => intendedUsage;
  54. set => UpdateProper(ref intendedUsage, value);
  55. }
  56. public SummaryControl()
  57. {
  58. InitializeComponent();
  59. DataContext = this;
  60. }
  61. public void LoadSummaryInfo(CPDFSignatureCertificate certificate)
  62. {
  63. string awardText;
  64. string grantorText = DictionaryValueConverter.GetGrantorFromDictionary(certificate.SubjectDict);
  65. string email = DictionaryValueConverter.GetEmailFormDictionary(certificate.SubjectDict);
  66. var usageList = DictionaryValueConverter.GetUsage(certificate);
  67. string keyUsageText = "";
  68. if(email != null)
  69. {
  70. awardText = grantorText + " <" + email + ">";
  71. }
  72. else
  73. {
  74. awardText = grantorText;
  75. }
  76. for(int i = 0; i < usageList.Count; i++)
  77. {
  78. keyUsageText += usageList[i];
  79. keyUsageText += (i == usageList.Count - 1) ? "" : ", ";
  80. }
  81. Award = awardText;
  82. Grantor = grantorText;
  83. ValidityFrom = CommonHelper.GetExactDateFromString(certificate.ValidityStarts);
  84. ValidityTo = CommonHelper.GetExactDateFromString(certificate.ValidityEnds);
  85. IntendedUsage = keyUsageText;
  86. }
  87. public event PropertyChangedEventHandler PropertyChanged;
  88. protected void UpdateProper<T>(ref T properValue,
  89. T newValue,
  90. [CallerMemberName] string properName = "")
  91. {
  92. if (object.Equals(properValue, newValue))
  93. return;
  94. properValue = newValue;
  95. OnPropertyChanged(properName);
  96. }
  97. protected void OnPropertyChanged([CallerMemberName] string propertyName = "") =>
  98. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
  99. }
  100. }