123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Linq;
- using System.Runtime.CompilerServices;
- using System.Windows;
- using System.Windows.Controls;
- using ComPDFKit.Controls.Helper;
- using ComPDFKit.DigitalSign;
- namespace ComPDFKit.Controls.PDFControl
- {
- public enum SignatureStatus
- {
- None,
- Valid,
- Invalid,
- MultiSig,
- Unknown,
- }
- public partial class SignatureStatusBarControl : UserControl, INotifyPropertyChanged
- {
- private string _messageString;
- public string MessageString
- {
- get => _messageString;
- set => UpdateProper(ref _messageString, value);
- }
- private string validString = LanguageHelper.SigManager.GetString("Text_SignerValid");
- private string invalidString = LanguageHelper.SigManager.GetString("Text_SignerInvalid");
- private string multiSigString = LanguageHelper.SigManager.GetString("Text_MultiSig");
- private string unknownString = LanguageHelper.SigManager.GetString("Text_SigUnknown");
- public event EventHandler OnViewSignatureButtonClicked;
-
- private SignatureStatus _status;
- public SignatureStatus Status
- {
- get => _status;
- set
- {
- _status = value;
- SetStatus(_status);
- }
- }
- public SignatureStatusBarControl()
- {
- InitializeComponent();
- DataContext = this;
- }
-
- private void SetStatus(SignatureStatus status)
- {
- ValidBorder.Visibility = Visibility.Collapsed;
- InvalidBorder.Visibility = Visibility.Collapsed;
- UnknownBorder.Visibility = Visibility.Collapsed;
- switch (status)
- {
- case SignatureStatus.None:
- MessageString = "";
- Visibility = Visibility.Collapsed;
- break;
- case SignatureStatus.Valid:
- ValidBorder.Visibility = Visibility.Visible;
- Visibility = Visibility.Visible;
- MessageString = validString;
- break;
- case SignatureStatus.Invalid:
- InvalidBorder.Visibility = Visibility.Visible;
- Visibility = Visibility.Visible;
- MessageString = invalidString;
- break;
- case SignatureStatus.MultiSig:
- InvalidBorder.Visibility = Visibility.Visible;
- Visibility = Visibility.Visible;
- MessageString = multiSigString;
- break;
- case SignatureStatus.Unknown:
- UnknownBorder.Visibility = Visibility.Visible;
- Visibility = Visibility.Visible;
- MessageString = unknownString;
- break;
- }
- }
- public void SetStatus(List<CPDFSignature> signatureList)
- {
- SignatureStatus status;
- if (signatureList.Count == 1)
- {
- bool isTrusted = true;
- bool isVerified = true;
- bool notModified = true;
- foreach (var signature in signatureList)
- {
- CPDFSigner signer = signature.SignerList.First();
- if(signer.IsSignVerified == false)
- isVerified = false;
- if (signer.IsCertTrusted == false)
- isTrusted = false;
- if (signature.ModifyInfoList.Count > 0)
- notModified = false;
- }
-
-
- if (isTrusted && isVerified && notModified)
- {
- status = SignatureStatus.Valid;
- }
- else if (!isTrusted && isVerified && notModified)
- {
- status = SignatureStatus.Unknown;
- }
- else
- {
- status = SignatureStatus.Invalid;
- }
- }
- else if (signatureList.Count > 1)
- {
- status = SignatureStatus.MultiSig;
- }
- else
- {
- status = SignatureStatus.None;
- }
- Status = status;
- }
- public event PropertyChangedEventHandler PropertyChanged;
- protected void UpdateProper<T>(ref T properValue,
- T newValue,
- [CallerMemberName] string properName = "")
- {
- if (object.Equals(properValue, newValue))
- return;
- properValue = newValue;
- OnPropertyChanged(properName);
- }
- protected void OnPropertyChanged([CallerMemberName] string propertyName = "") =>
- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
- private void ButtonViewSignature_OnClick(object sender, RoutedEventArgs e)
- {
- OnViewSignatureButtonClicked?.Invoke(this,null);
- }
- }
- }
|