/// <summary>
        /// Add typed object to the collection
        /// </summary>
        /// <param name="objectToAdd">Typed object to be added to collection</param>
        /// <returns>The object that has been added to collection</returns>
        public OtherCertificate Add(OtherCertificate objectToAdd)
        {
            base.Add(objectToAdd);

            return(objectToAdd);
        }
Esempio n. 2
0
        /// <summary>
        /// Load state from an XML element
        /// </summary>
        /// <param name="xmlElement">XML element containing new state</param>
        public void LoadXml(XmlElement xmlElement)
        {
            XmlNamespaceManager xmlNamespaceManager;
            IEnumerator         enumerator = null;
            XmlElement          iterationXmlElement;

            if (xmlElement == null)
            {
                throw new ArgumentNullException("xmlElement");
            }
            if (xmlElement.HasAttribute("Id"))
            {
                _id = xmlElement.GetAttribute("Id");
            }
            else
            {
                _id = "";
            }

            xmlNamespaceManager = new XmlNamespaceManager(xmlElement.OwnerDocument.NameTable);
            xmlNamespaceManager.AddNamespace("xades", XadesSignedXml.XadesNamespaceUri);

            _encapsulatedX509CertificateCollection.Clear();
            _otherCertificateCollection.Clear();

            var xmlNodeList = xmlElement.SelectNodes("xades:EncapsulatedX509Certificate", xmlNamespaceManager);

            if (xmlNodeList != null)
            {
                enumerator = xmlNodeList.GetEnumerator();
                try
                {
                    while (enumerator != null && enumerator.MoveNext())
                    {
                        iterationXmlElement = enumerator.Current as XmlElement;
                        if (iterationXmlElement == null)
                        {
                            continue;
                        }
                        var newEncapsulatedX509Certificate = new EncapsulatedX509Certificate();
                        newEncapsulatedX509Certificate.LoadXml(iterationXmlElement);
                        _encapsulatedX509CertificateCollection.Add(newEncapsulatedX509Certificate);
                    }
                }
                finally
                {
                    var disposable = enumerator as IDisposable;
                    if (disposable != null)
                    {
                        disposable.Dispose();
                    }
                }
            }

            xmlNodeList = xmlElement.SelectNodes("xades:OtherCertificate", xmlNamespaceManager);
            if (xmlNodeList != null)
            {
                enumerator = xmlNodeList.GetEnumerator();
            }
            try
            {
                while (enumerator != null && enumerator.MoveNext())
                {
                    iterationXmlElement = enumerator.Current as XmlElement;
                    if (iterationXmlElement == null)
                    {
                        continue;
                    }
                    var newOtherCertificate = new OtherCertificate();
                    newOtherCertificate.LoadXml(iterationXmlElement);
                    _otherCertificateCollection.Add(newOtherCertificate);
                }
            }
            finally
            {
                var disposable = enumerator as IDisposable;
                if (disposable != null)
                {
                    disposable.Dispose();
                }
            }
        }