/// <summary> /// See IDigitalSignatureProvider /// </summary> void IDigitalSignatureProvider.RemoveRequestSignature(Guid spotId) { AssertIsSignable(); XpsSignatureDefinition definition = FindSignatureDefinition(spotId); if (definition != null) { FixedDocument.RemoveSignatureDefinition(definition); FixedDocument.CommitSignatureDefinition(); } // Loop through the signature list and remove the entry for the // requested signature foreach (DigitalSignature signature in DigitalSignatureList) { if (signature.GuidID == spotId) { // We only want to remove unsigned signature definitions // (requested signatures) and not actual signatures. if (signature.SignatureState == SignatureStatus.NotSigned) { DigitalSignatureList.Remove(signature); } // It is safe to remove an element from the list that we're // currently enumerating because we stop enumerating as soon // as we find the element we're looking for. break; } } }
/// <summary> /// See IDigitalSignatureProvider /// </summary> Guid IDigitalSignatureProvider.AddRequestSignature(DigitalSignature digitalSignature) { AssertIsSignable(); // Create guid used for signature ID Guid guidID = Guid.NewGuid(); // Create a new SignatureDefinition XpsSignatureDefinition xpsSignatureDefinition = new XpsSignatureDefinition(); // Use the digSig to setup the SignatureDefinition. xpsSignatureDefinition.RequestedSigner = digitalSignature.SubjectName; xpsSignatureDefinition.Intent = digitalSignature.Reason; xpsSignatureDefinition.SigningLocale = digitalSignature.Location; xpsSignatureDefinition.SignBy = digitalSignature.SignedOn; // Use our new guid to setup the ID xpsSignatureDefinition.SpotId = guidID; // Add the signature definition to the document FixedDocument.AddSignatureDefinition(xpsSignatureDefinition); FixedDocument.CommitSignatureDefinition(); // Set the signature's status to Not Signed before adding to our list digitalSignature.SignatureState = SignatureStatus.NotSigned; // Add the new signature to our list of signatures and definitions DigitalSignatureList.Add(digitalSignature); return(guidID); }