internal static WindowsLiveIdNamespace ParseXml(LiveIdInstanceType liveIdInstanceType, XmlDocument xml)
        {
            WindowsLiveIdNamespace windowsLiveIdNamespace = new WindowsLiveIdNamespace();

            windowsLiveIdNamespace.InstanceType = liveIdInstanceType;
            XmlNamespaceManager xmlNamespaceManager = new XmlNamespaceManager(xml.NameTable);

            LiveServicesHelper.AddNamespaces(xml, xmlNamespaceManager);
            XmlNode xmlNode = xml.SelectSingleNode("p:Namespace/p:name", xmlNamespaceManager);

            if (xmlNode != null && !string.IsNullOrEmpty(xmlNode.InnerText))
            {
                windowsLiveIdNamespace.Name = xmlNode.InnerText;
            }
            xmlNode = xml.SelectSingleNode("p:Namespace/p:ID", xmlNamespaceManager);
            if (xmlNode != null && !string.IsNullOrEmpty(xmlNode.InnerText))
            {
                windowsLiveIdNamespace.propertyBag[SimpleProviderObjectSchema.Identity] = new WindowsLiveIdIdentity(xmlNode.InnerText);
                windowsLiveIdNamespace.ID = xmlNode.InnerText;
            }
            xmlNode = xml.SelectSingleNode(WindowsLiveIdNamespace.GetPropertyXPath("SiteID"), xmlNamespaceManager);
            if (xmlNode != null && !string.IsNullOrEmpty(xmlNode.InnerText))
            {
                windowsLiveIdNamespace.SiteID = xmlNode.InnerText;
            }
            xmlNode = xml.SelectSingleNode(WindowsLiveIdNamespace.GetPropertyXPath("AppID"), xmlNamespaceManager);
            if (xmlNode != null && !string.IsNullOrEmpty(xmlNode.InnerText))
            {
                windowsLiveIdNamespace.AppID = xmlNode.InnerText;
            }
            xmlNode = xml.SelectSingleNode(WindowsLiveIdNamespace.GetPropertyXPath("URI"), xmlNamespaceManager);
            if (xmlNode != null && !string.IsNullOrEmpty(xmlNode.InnerText))
            {
                Uri uri = null;
                if (Uri.TryCreate(xmlNode.InnerText, UriKind.RelativeOrAbsolute, out uri))
                {
                    windowsLiveIdNamespace.Uri = uri;
                }
            }
            xmlNode = xml.SelectSingleNode(WindowsLiveIdNamespace.GetPropertyXPath("Certificate"), xmlNamespaceManager);
            if (xmlNode != null && !string.IsNullOrEmpty(xmlNode.InnerText))
            {
                windowsLiveIdNamespace.Certificate = WindowsLiveIdApplicationCertificate.CertificateFromBase64(xmlNode.InnerText);
            }
            xmlNode = xml.SelectSingleNode(WindowsLiveIdNamespace.GetPropertyXPath("NextCertificate"), xmlNamespaceManager);
            if (xmlNode != null && !string.IsNullOrEmpty(xmlNode.InnerText))
            {
                windowsLiveIdNamespace.NextCertificate = WindowsLiveIdApplicationCertificate.CertificateFromBase64(xmlNode.InnerText);
            }
            windowsLiveIdNamespace.RawXml = xml.DocumentElement.InnerXml;
            return(windowsLiveIdNamespace);
        }
Beispiel #2
0
        internal static WindowsLiveIdApplicationIdentity ParseXml(LiveIdInstanceType liveIdInstanceType, XmlDocument xml)
        {
            WindowsLiveIdApplicationIdentity windowsLiveIdApplicationIdentity = new WindowsLiveIdApplicationIdentity();

            windowsLiveIdApplicationIdentity.InstanceType = liveIdInstanceType;
            XmlNode xmlNode = xml.SelectSingleNode("AppidData/Application/Name");

            if (xmlNode != null && !string.IsNullOrEmpty(xmlNode.InnerText))
            {
                windowsLiveIdApplicationIdentity.Name = xmlNode.InnerText;
            }
            xmlNode = xml.SelectSingleNode("AppidData/Application/ID");
            if (xmlNode != null && !string.IsNullOrEmpty(xmlNode.InnerText))
            {
                windowsLiveIdApplicationIdentity.propertyBag[SimpleProviderObjectSchema.Identity] = new WindowsLiveIdIdentity(xmlNode.InnerText);
                windowsLiveIdApplicationIdentity.Id = xmlNode.InnerText;
            }
            xmlNode = xml.SelectSingleNode(WindowsLiveIdApplicationIdentity.GetPropertyXPath("Status"));
            if (xmlNode != null && !string.IsNullOrEmpty(xmlNode.InnerText))
            {
                windowsLiveIdApplicationIdentity.Status = xmlNode.InnerText;
            }
            using (XmlNodeList xmlNodeList = xml.SelectNodes("AppidData/Application/URIs/URI/URIAddress"))
            {
                if (xmlNodeList != null)
                {
                    foreach (object obj in xmlNodeList)
                    {
                        XmlNode xmlNode2 = (XmlNode)obj;
                        if (!string.IsNullOrEmpty(xmlNode2.InnerText))
                        {
                            Uri item = null;
                            if (Uri.TryCreate(xmlNode2.InnerText, UriKind.RelativeOrAbsolute, out item))
                            {
                                windowsLiveIdApplicationIdentity.UriCollection.Add(item);
                            }
                        }
                    }
                }
            }
            using (XmlNodeList xmlNodeList2 = xml.SelectNodes("AppidData/Application/Certificates/Certificate"))
            {
                if (xmlNodeList2 != null)
                {
                    foreach (object obj2 in xmlNodeList2)
                    {
                        XmlNode          xmlNode3        = (XmlNode)obj2;
                        string           name            = string.Empty;
                        X509Certificate2 x509Certificate = null;
                        bool             isCurrent       = false;
                        XmlNode          xmlNode4        = xmlNode3.SelectSingleNode("CertificateName");
                        if (xmlNode4 != null)
                        {
                            name = xmlNode4.InnerText;
                        }
                        xmlNode4 = xmlNode3.SelectSingleNode("CertificateData");
                        if (xmlNode4 != null && !string.IsNullOrEmpty(xmlNode4.InnerText))
                        {
                            x509Certificate = WindowsLiveIdApplicationCertificate.CertificateFromBase64(xmlNode4.InnerText);
                        }
                        xmlNode4 = xmlNode3.SelectSingleNode("CertificateIsCurrent");
                        if (xmlNode4 != null && !string.IsNullOrEmpty(xmlNode4.InnerText) && !bool.TryParse(xmlNode4.InnerText, out isCurrent))
                        {
                            isCurrent = false;
                        }
                        if (x509Certificate != null)
                        {
                            windowsLiveIdApplicationIdentity.CertificateCollection.Add(new WindowsLiveIdApplicationCertificate(name, isCurrent, x509Certificate));
                        }
                    }
                }
            }
            xmlNode = xml.SelectSingleNode(WindowsLiveIdApplicationIdentity.GetPropertyXPath("Key"));
            if (xmlNode != null && !string.IsNullOrEmpty(xmlNode.InnerText))
            {
                xmlNode.InnerText = "*****";
            }
            windowsLiveIdApplicationIdentity.RawXml = xml.DocumentElement.InnerXml;
            return(windowsLiveIdApplicationIdentity);
        }