public LoadXml ( System xmlElement ) : void | ||
xmlElement | System | XML element containing new state |
리턴 | void |
/// <summary> /// Load state from an XML element /// </summary> /// <param name="xmlElement">XML element containing new state</param> public void LoadXml(System.Xml.XmlElement xmlElement) { XmlNamespaceManager xmlNamespaceManager; XmlNodeList xmlNodeList; IEnumerator enumerator; XmlElement iterationXmlElement; DataObjectFormat newDataObjectFormat; CommitmentTypeIndication newCommitmentTypeIndication; TimeStamp newTimeStamp; if (xmlElement == null) { throw new ArgumentNullException(nameof(xmlElement)); } xmlNamespaceManager = new XmlNamespaceManager(xmlElement.OwnerDocument.NameTable); xmlNamespaceManager.AddNamespace("xsd", XadesSignedXml.XadesNamespaceUri); this.dataObjectFormatCollection.Clear(); xmlNodeList = xmlElement.SelectNodes("xsd:DataObjectFormat", xmlNamespaceManager); enumerator = xmlNodeList.GetEnumerator(); try { while (enumerator.MoveNext()) { iterationXmlElement = enumerator.Current as XmlElement; if (iterationXmlElement != null) { newDataObjectFormat = new DataObjectFormat(); newDataObjectFormat.LoadXml(iterationXmlElement); this.dataObjectFormatCollection.Add(newDataObjectFormat); } } } finally { if (enumerator is IDisposable disposable) disposable.Dispose(); } //this.dataObjectFormatCollection.Clear(); xmlNodeList = xmlElement.SelectNodes("xsd:CommitmentTypeIndication", xmlNamespaceManager); enumerator = xmlNodeList.GetEnumerator(); try { while (enumerator.MoveNext()) { iterationXmlElement = enumerator.Current as XmlElement; if (iterationXmlElement != null) { newCommitmentTypeIndication = new CommitmentTypeIndication(); newCommitmentTypeIndication.LoadXml(iterationXmlElement); this.commitmentTypeIndicationCollection.Add(newCommitmentTypeIndication); } } } finally { if (enumerator is IDisposable disposable) { disposable.Dispose(); } } //this.dataObjectFormatCollection.Clear(); xmlNodeList = xmlElement.SelectNodes("xsd:AllDataObjectsTimeStamp", xmlNamespaceManager); enumerator = xmlNodeList.GetEnumerator(); try { while (enumerator.MoveNext()) { iterationXmlElement = enumerator.Current as XmlElement; if (iterationXmlElement != null) { newTimeStamp = new TimeStamp("AllDataObjectsTimeStamp"); newTimeStamp.LoadXml(iterationXmlElement); this.allDataObjectsTimeStampCollection.Add(newTimeStamp); } } } finally { if (enumerator is IDisposable disposable) { disposable.Dispose(); } } //this.dataObjectFormatCollection.Clear(); xmlNodeList = xmlElement.SelectNodes("xsd:IndividualDataObjectsTimeStamp", xmlNamespaceManager); enumerator = xmlNodeList.GetEnumerator(); try { while (enumerator.MoveNext()) { iterationXmlElement = enumerator.Current as XmlElement; if (iterationXmlElement != null) { newTimeStamp = new TimeStamp("IndividualDataObjectsTimeStamp"); newTimeStamp.LoadXml(iterationXmlElement); this.individualDataObjectsTimeStampCollection.Add(newTimeStamp); } } } finally { if (enumerator is IDisposable disposable) disposable.Dispose(); } }
/// <summary> /// Load state from an XML element /// </summary> /// <param name="xmlElement">XML element containing new state</param> /// <param name="counterSignedXmlElement">Element containing parent signature (needed if there are counter signatures)</param> public void LoadXml(System.Xml.XmlElement xmlElement, XmlElement counterSignedXmlElement) { XmlNamespaceManager xmlNamespaceManager; XmlNodeList xmlNodeList; IEnumerator enumerator; XmlElement iterationXmlElement; XadesSignedXml newXadesSignedXml; TimeStamp newTimeStamp; XmlElement counterSignatureElement; if (xmlElement == null) { throw new ArgumentNullException("xmlElement"); } xmlNamespaceManager = new XmlNamespaceManager(xmlElement.OwnerDocument.NameTable); xmlNamespaceManager.AddNamespace("xades", XadesSignedXml.XadesNamespaceUri); xmlNamespaceManager.AddNamespace("xadesv141", XadesSignedXml.XadesNamespace141Uri); this.counterSignatureCollection.Clear(); xmlNodeList = xmlElement.SelectNodes("xades:CounterSignature", xmlNamespaceManager); enumerator = xmlNodeList.GetEnumerator(); try { while (enumerator.MoveNext()) { iterationXmlElement = enumerator.Current as XmlElement; if (iterationXmlElement != null) { if (counterSignedXmlElement != null) { newXadesSignedXml = new XadesSignedXml(counterSignedXmlElement); } else { newXadesSignedXml = new XadesSignedXml(); } //Skip any whitespace at start counterSignatureElement = null; for (int childNodeCounter = 0; (childNodeCounter < iterationXmlElement.ChildNodes.Count) && (counterSignatureElement == null); childNodeCounter++) { if (iterationXmlElement.ChildNodes[childNodeCounter] is XmlElement) { counterSignatureElement = (XmlElement)iterationXmlElement.ChildNodes[childNodeCounter]; } } if (counterSignatureElement != null) { newXadesSignedXml.LoadXml(counterSignatureElement); this.counterSignatureCollection.Add(newXadesSignedXml); } else { throw new CryptographicException("CounterSignature element does not contain signature"); } } } } finally { IDisposable disposable = enumerator as IDisposable; if (disposable != null) { disposable.Dispose(); } } this.signatureTimeStampCollection.Clear(); xmlNodeList = xmlElement.SelectNodes("xades:SignatureTimeStamp", xmlNamespaceManager); enumerator = xmlNodeList.GetEnumerator(); try { while (enumerator.MoveNext()) { iterationXmlElement = enumerator.Current as XmlElement; if (iterationXmlElement != null) { newTimeStamp = new TimeStamp("SignatureTimeStamp"); newTimeStamp.LoadXml(iterationXmlElement); this.signatureTimeStampCollection.Add(newTimeStamp); } } } finally { IDisposable disposable = enumerator as IDisposable; if (disposable != null) { disposable.Dispose(); } } xmlNodeList = xmlElement.SelectNodes("xades:CompleteCertificateRefs", xmlNamespaceManager); if (xmlNodeList.Count != 0) { this.completeCertificateRefs = new CompleteCertificateRefs(); this.completeCertificateRefs.LoadXml((XmlElement)xmlNodeList.Item(0)); } else { this.completeCertificateRefs = null; } xmlNodeList = xmlElement.SelectNodes("xades:CompleteRevocationRefs", xmlNamespaceManager); if (xmlNodeList.Count != 0) { this.CompleteRevocationRefs = new CompleteRevocationRefs(); this.CompleteRevocationRefs.LoadXml((XmlElement)xmlNodeList.Item(0)); } else { this.completeRevocationRefs = null; } this.sigAndRefsTimeStampCollection.Clear(); this.refsOnlyTimeStampCollection.Clear(); xmlNodeList = xmlElement.SelectNodes("xades:SigAndRefsTimeStamp", xmlNamespaceManager); if (xmlNodeList.Count > 0) { this.refsOnlyTimeStampFlag = false; enumerator = xmlNodeList.GetEnumerator(); try { while (enumerator.MoveNext()) { iterationXmlElement = enumerator.Current as XmlElement; if (iterationXmlElement != null) { newTimeStamp = new TimeStamp("SigAndRefsTimeStamp"); newTimeStamp.LoadXml(iterationXmlElement); this.sigAndRefsTimeStampCollection.Add(newTimeStamp); } } } finally { IDisposable disposable = enumerator as IDisposable; if (disposable != null) { disposable.Dispose(); } } } else { xmlNodeList = xmlElement.SelectNodes("xades:RefsOnlyTimeStamp", xmlNamespaceManager); if (xmlNodeList.Count > 0) { this.refsOnlyTimeStampFlag = true; enumerator = xmlNodeList.GetEnumerator(); try { while (enumerator.MoveNext()) { iterationXmlElement = enumerator.Current as XmlElement; if (iterationXmlElement != null) { newTimeStamp = new TimeStamp("RefsOnlyTimeStamp"); newTimeStamp.LoadXml(iterationXmlElement); this.refsOnlyTimeStampCollection.Add(newTimeStamp); } } } finally { IDisposable disposable = enumerator as IDisposable; if (disposable != null) { disposable.Dispose(); } } } else { this.refsOnlyTimeStampFlag = false; } } xmlNodeList = xmlElement.SelectNodes("xades:CertificateValues", xmlNamespaceManager); if (xmlNodeList.Count != 0) { this.certificateValues = new CertificateValues(); this.certificateValues.LoadXml((XmlElement)xmlNodeList.Item(0)); } else { this.certificateValues = null; } xmlNodeList = xmlElement.SelectNodes("xades:RevocationValues", xmlNamespaceManager); if (xmlNodeList.Count != 0) { this.revocationValues = new RevocationValues(); this.revocationValues.LoadXml((XmlElement)xmlNodeList.Item(0)); } else { this.revocationValues = null; } this.archiveTimeStampCollection.Clear(); xmlNodeList = xmlElement.SelectNodes("xades:ArchiveTimeStamp", xmlNamespaceManager); xmlNodeList = xmlElement.SelectNodes("xadesv141:ArchiveTimeStamp", xmlNamespaceManager); enumerator = xmlNodeList.GetEnumerator(); try { while (enumerator.MoveNext()) { iterationXmlElement = enumerator.Current as XmlElement; if (iterationXmlElement != null) { newTimeStamp = new TimeStamp("ArchiveTimeStamp"); newTimeStamp.LoadXml(iterationXmlElement); this.archiveTimeStampCollection.Add(newTimeStamp); } } } finally { IDisposable disposable = enumerator as IDisposable; if (disposable != null) { disposable.Dispose(); } } xmlNodeList = xmlElement.SelectNodes("xadesv141:ArchiveTimeStamp", xmlNamespaceManager); enumerator = xmlNodeList.GetEnumerator(); try { while (enumerator.MoveNext()) { iterationXmlElement = enumerator.Current as XmlElement; if (iterationXmlElement != null) { newTimeStamp = new TimeStamp("ArchiveTimeStamp", "xadesv141", XadesSignedXml.XadesNamespace141Uri); newTimeStamp.LoadXml(iterationXmlElement); this.archiveTimeStampCollection.Add(newTimeStamp); } } } finally { IDisposable disposable = enumerator as IDisposable; if (disposable != null) { disposable.Dispose(); } } }
/// <summary> /// Load state from an XML element /// </summary> /// <param name="xmlElement">XML element containing new state</param> public void LoadXml(System.Xml.XmlElement xmlElement) { XmlNamespaceManager xmlNamespaceManager; XmlNodeList xmlNodeList; IEnumerator enumerator; XmlElement iterationXmlElement; DataObjectFormat newDataObjectFormat; CommitmentTypeIndication newCommitmentTypeIndication; TimeStamp newTimeStamp; if (xmlElement == null) { throw new ArgumentNullException("xmlElement"); } xmlNamespaceManager = new XmlNamespaceManager(xmlElement.OwnerDocument.NameTable); xmlNamespaceManager.AddNamespace("xsd", XadesSignedXml.XadesNamespaceUri); this.dataObjectFormatCollection.Clear(); xmlNodeList = xmlElement.SelectNodes("xsd:DataObjectFormat", xmlNamespaceManager); enumerator = xmlNodeList.GetEnumerator(); try { while (enumerator.MoveNext()) { iterationXmlElement = enumerator.Current as XmlElement; if (iterationXmlElement != null) { newDataObjectFormat = new DataObjectFormat(); newDataObjectFormat.LoadXml(iterationXmlElement); this.dataObjectFormatCollection.Add(newDataObjectFormat); } } } finally { IDisposable disposable = enumerator as IDisposable; if (disposable != null) { disposable.Dispose(); } } this.dataObjectFormatCollection.Clear(); xmlNodeList = xmlElement.SelectNodes("xsd:CommitmentTypeIndication", xmlNamespaceManager); enumerator = xmlNodeList.GetEnumerator(); try { while (enumerator.MoveNext()) { iterationXmlElement = enumerator.Current as XmlElement; if (iterationXmlElement != null) { newCommitmentTypeIndication = new CommitmentTypeIndication(); newCommitmentTypeIndication.LoadXml(iterationXmlElement); this.commitmentTypeIndicationCollection.Add(newCommitmentTypeIndication); } } } finally { IDisposable disposable = enumerator as IDisposable; if (disposable != null) { disposable.Dispose(); } } this.dataObjectFormatCollection.Clear(); xmlNodeList = xmlElement.SelectNodes("xsd:AllDataObjectsTimeStamp", xmlNamespaceManager); enumerator = xmlNodeList.GetEnumerator(); try { while (enumerator.MoveNext()) { iterationXmlElement = enumerator.Current as XmlElement; if (iterationXmlElement != null) { newTimeStamp = new TimeStamp("AllDataObjectsTimeStamp"); newTimeStamp.LoadXml(iterationXmlElement); this.allDataObjectsTimeStampCollection.Add(newTimeStamp); } } } finally { IDisposable disposable = enumerator as IDisposable; if (disposable != null) { disposable.Dispose(); } } this.dataObjectFormatCollection.Clear(); xmlNodeList = xmlElement.SelectNodes("xsd:IndividualDataObjectsTimeStamp", xmlNamespaceManager); enumerator = xmlNodeList.GetEnumerator(); try { while (enumerator.MoveNext()) { iterationXmlElement = enumerator.Current as XmlElement; if (iterationXmlElement != null) { newTimeStamp = new TimeStamp("IndividualDataObjectsTimeStamp"); newTimeStamp.LoadXml(iterationXmlElement); this.individualDataObjectsTimeStampCollection.Add(newTimeStamp); } } } finally { IDisposable disposable = enumerator as IDisposable; if (disposable != null) { disposable.Dispose(); } } }
/// <summary> /// Load state from an XML element /// </summary> /// <param name="xmlElement">XML element containing new state</param> /// <param name="counterSignedXmlElement">Element containing parent signature (needed if there are counter signatures)</param> public void LoadXml(System.Xml.XmlElement xmlElement, XmlElement counterSignedXmlElement) { XmlNamespaceManager xmlNamespaceManager; XmlNodeList xmlNodeList; IEnumerator enumerator; XmlElement iterationXmlElement; XadesSignedXml newXadesSignedXml; TimeStamp newTimeStamp; XmlElement counterSignatureElement; if (xmlElement == null) { throw new ArgumentNullException("xmlElement"); } xmlNamespaceManager = new XmlNamespaceManager(xmlElement.OwnerDocument.NameTable); xmlNamespaceManager.AddNamespace("xsd", XadesSignedXml.XadesNamespaceUri); this.counterSignatureCollection.Clear(); xmlNodeList = xmlElement.SelectNodes("xsd:CounterSignature", xmlNamespaceManager); enumerator = xmlNodeList.GetEnumerator(); try { while (enumerator.MoveNext()) { iterationXmlElement = enumerator.Current as XmlElement; if (iterationXmlElement != null) { if (counterSignedXmlElement != null) { newXadesSignedXml = new XadesSignedXml(counterSignedXmlElement); } else { newXadesSignedXml = new XadesSignedXml(); } //Skip any whitespace at start counterSignatureElement = null; for (int childNodeCounter = 0; (childNodeCounter < iterationXmlElement.ChildNodes.Count) && (counterSignatureElement == null); childNodeCounter++) { if (iterationXmlElement.ChildNodes[childNodeCounter] is XmlElement) { counterSignatureElement = (XmlElement)iterationXmlElement.ChildNodes[childNodeCounter]; } } if (counterSignatureElement != null) { newXadesSignedXml.LoadXml(counterSignatureElement); this.counterSignatureCollection.Add(newXadesSignedXml); } else { throw new CryptographicException("CounterSignature element does not contain signature"); } } } } finally { IDisposable disposable = enumerator as IDisposable; if (disposable != null) { disposable.Dispose(); } } this.signatureTimeStampCollection.Clear(); xmlNodeList = xmlElement.SelectNodes("xsd:SignatureTimeStamp", xmlNamespaceManager); enumerator = xmlNodeList.GetEnumerator(); try { while (enumerator.MoveNext()) { iterationXmlElement = enumerator.Current as XmlElement; if (iterationXmlElement != null) { newTimeStamp = new TimeStamp("SignatureTimeStamp"); newTimeStamp.LoadXml(iterationXmlElement); this.signatureTimeStampCollection.Add(newTimeStamp); } } } finally { IDisposable disposable = enumerator as IDisposable; if (disposable != null) { disposable.Dispose(); } } xmlNodeList = xmlElement.SelectNodes("xsd:CompleteCertificateRefs", xmlNamespaceManager); if (xmlNodeList.Count != 0) { this.completeCertificateRefs = new CompleteCertificateRefs(); this.completeCertificateRefs.LoadXml((XmlElement)xmlNodeList.Item(0)); } else { this.completeCertificateRefs = null; } xmlNodeList = xmlElement.SelectNodes("xsd:CompleteRevocationRefs", xmlNamespaceManager); if (xmlNodeList.Count != 0) { this.CompleteRevocationRefs = new CompleteRevocationRefs(); this.CompleteRevocationRefs.LoadXml((XmlElement)xmlNodeList.Item(0)); } else { this.completeRevocationRefs = null; } this.sigAndRefsTimeStampCollection.Clear(); this.refsOnlyTimeStampCollection.Clear(); xmlNodeList = xmlElement.SelectNodes("xsd:SigAndRefsTimeStamp", xmlNamespaceManager); if (xmlNodeList.Count > 0) { this.refsOnlyTimeStampFlag = false; enumerator = xmlNodeList.GetEnumerator(); try { while (enumerator.MoveNext()) { iterationXmlElement = enumerator.Current as XmlElement; if (iterationXmlElement != null) { newTimeStamp = new TimeStamp("SigAndRefsTimeStamp"); newTimeStamp.LoadXml(iterationXmlElement); this.sigAndRefsTimeStampCollection.Add(newTimeStamp); } } } finally { IDisposable disposable = enumerator as IDisposable; if (disposable != null) { disposable.Dispose(); } } } else { xmlNodeList = xmlElement.SelectNodes("xsd:RefsOnlyTimeStamp", xmlNamespaceManager); if (xmlNodeList.Count > 0) { this.refsOnlyTimeStampFlag = true; enumerator = xmlNodeList.GetEnumerator(); try { while (enumerator.MoveNext()) { iterationXmlElement = enumerator.Current as XmlElement; if (iterationXmlElement != null) { newTimeStamp = new TimeStamp("RefsOnlyTimeStamp"); newTimeStamp.LoadXml(iterationXmlElement); this.refsOnlyTimeStampCollection.Add(newTimeStamp); } } } finally { IDisposable disposable = enumerator as IDisposable; if (disposable != null) { disposable.Dispose(); } } } else { this.refsOnlyTimeStampFlag = false; } } xmlNodeList = xmlElement.SelectNodes("xsd:CertificateValues", xmlNamespaceManager); if (xmlNodeList.Count != 0) { this.certificateValues = new CertificateValues(); this.certificateValues.LoadXml((XmlElement)xmlNodeList.Item(0)); } else { this.certificateValues = null; } xmlNodeList = xmlElement.SelectNodes("xsd:RevocationValues", xmlNamespaceManager); if (xmlNodeList.Count != 0) { this.revocationValues = new RevocationValues(); this.revocationValues.LoadXml((XmlElement)xmlNodeList.Item(0)); } else { this.revocationValues = null; } this.archiveTimeStampCollection.Clear(); xmlNodeList = xmlElement.SelectNodes("xsd:ArchiveTimeStamp", xmlNamespaceManager); enumerator = xmlNodeList.GetEnumerator(); try { while (enumerator.MoveNext()) { iterationXmlElement = enumerator.Current as XmlElement; if (iterationXmlElement != null) { newTimeStamp = new TimeStamp("ArchiveTimeStamp"); newTimeStamp.LoadXml(iterationXmlElement); this.archiveTimeStampCollection.Add(newTimeStamp); } } } finally { IDisposable disposable = enumerator as IDisposable; if (disposable != null) { disposable.Dispose(); } } }