コード例 #1
0
ファイル: Xrd.cs プロジェクト: thoys/simian
        private void Parse()
        {
            XmlNamespaceManager nsMgr = new XmlNamespaceManager(cursor.NameTable);
            nsMgr.AddNamespace("xrd", "http://docs.oasis-open.org/ns/xri/xrd-1.0");

            var expires = cursor.SelectSingleNode("/xrd:XRD/xrd:Expires", nsMgr);
            var subject = cursor.SelectSingleNode("/xrd:XRD/xrd:Subject", nsMgr);
            var aliases = GetAll(cursor.Select("/xrd:XRD/xrd:Alias", nsMgr));

            if (subject == null)
                throw new XrdParseException("Missing Subject");

            Uri subjectUri;
            if (Uri.TryCreate(subject.Value, UriKind.Absolute, out subjectUri))
            {
                DateTime? expirationDate = null;
                if (expires != null)
                    expirationDate = expires.ValueAsDateTime;

                List<XrdLink> links = new List<XrdLink>();

                XPathNodeIterator linkIter = cursor.Select("/xrd:XRD/xrd:Link", nsMgr);
                while (linkIter.MoveNext())
                {
                    var rel = linkIter.Current.SelectSingleNode("@rel", nsMgr);
                    var type = linkIter.Current.SelectSingleNode("@type", nsMgr);
                    var href = linkIter.Current.SelectSingleNode("@href", nsMgr);
                    var template = linkIter.Current.SelectSingleNode("@template", nsMgr);

                    Uri relUrl;
                    if (rel != null && Uri.TryCreate(rel.Value, UriKind.Absolute, out relUrl))
                    {
                        string typeStr = null;
                        if (type != null)
                            typeStr = type.Value;

                        string hrefUrl = null;
                        if (href != null)
                            hrefUrl = href.Value;

                        string templateStr = null;
                        if (template != null)
                            templateStr = template.Value;

                        XrdLink link = new XrdLink(relUrl, typeStr, hrefUrl, templateStr);
                        links.Add(link);
                    }
                }

                // Only keep the aliases that can be parsed as valid absolute URIs
                List<Uri> validAliases = new List<Uri>(aliases.Count);
                foreach (string alias in aliases)
                {
                    Uri aliasUri;
                    if (Uri.TryCreate(alias, UriKind.Absolute, out aliasUri))
                        validAliases.Add(aliasUri);
                }

                result = new XrdDocument(subjectUri, expirationDate, validAliases, links);
            }
        }
コード例 #2
0
ファイル: Xrd.cs プロジェクト: jhurliman/simian
        private void Parse()
        {
            XmlNamespaceManager nsMgr = new XmlNamespaceManager(cursor.NameTable);

            nsMgr.AddNamespace("xrd", "http://docs.oasis-open.org/ns/xri/xrd-1.0");

            var expires = cursor.SelectSingleNode("/xrd:XRD/xrd:Expires", nsMgr);
            var subject = cursor.SelectSingleNode("/xrd:XRD/xrd:Subject", nsMgr);
            var aliases = GetAll(cursor.Select("/xrd:XRD/xrd:Alias", nsMgr));

            if (subject == null)
            {
                throw new XrdParseException("Missing Subject");
            }

            Uri subjectUri;

            if (Uri.TryCreate(subject.Value, UriKind.Absolute, out subjectUri))
            {
                DateTime?expirationDate = null;
                if (expires != null)
                {
                    expirationDate = expires.ValueAsDateTime;
                }

                List <XrdLink> links = new List <XrdLink>();

                XPathNodeIterator linkIter = cursor.Select("/xrd:XRD/xrd:Link", nsMgr);
                while (linkIter.MoveNext())
                {
                    var rel      = linkIter.Current.SelectSingleNode("@rel", nsMgr);
                    var type     = linkIter.Current.SelectSingleNode("@type", nsMgr);
                    var href     = linkIter.Current.SelectSingleNode("@href", nsMgr);
                    var template = linkIter.Current.SelectSingleNode("@template", nsMgr);

                    Uri relUrl;
                    if (rel != null && Uri.TryCreate(rel.Value, UriKind.Absolute, out relUrl))
                    {
                        string typeStr = null;
                        if (type != null)
                        {
                            typeStr = type.Value;
                        }

                        string hrefUrl = null;
                        if (href != null)
                        {
                            hrefUrl = href.Value;
                        }

                        string templateStr = null;
                        if (template != null)
                        {
                            templateStr = template.Value;
                        }

                        XrdLink link = new XrdLink(relUrl, typeStr, hrefUrl, templateStr);
                        links.Add(link);
                    }
                }

                // Only keep the aliases that can be parsed as valid absolute URIs
                List <Uri> validAliases = new List <Uri>(aliases.Count);
                foreach (string alias in aliases)
                {
                    Uri aliasUri;
                    if (Uri.TryCreate(alias, UriKind.Absolute, out aliasUri))
                    {
                        validAliases.Add(aliasUri);
                    }
                }

                result = new XrdDocument(subjectUri, expirationDate, validAliases, links);
            }
        }