Esempio n. 1
0
        private static void TryReadCommonProperties(XmlReader reader, AtomEntryBase entry)
        {
            if (reader.NodeType != XmlNodeType.Element)
                return;

            switch (reader.Name)
            {
                case "id":
                    VisitIdElement(reader, entry);
                    break;
                case "title":
                    VisitTextConstruct(reader, entry, "title", (c, e) => e.AddTitle(c));
                    break;
                case "updated":
                    VisitDateTime(reader, entry, "updated", (d, e) => e.AddUpdated(d));
                    break;
                case "category":
                    VisitCategoryElement(reader, entry);
                    break;
                case "link":
                    VisitLinkElement(reader, entry);
                    break;
                case "author":
                    VisitPersonConstruct(reader, entry, "author", (p, e) => e.AddAuthor(p));
                    break;
                case "contributor":
                    VisitPersonConstruct(reader, entry, "contributor", (p, e) => e.AddContributor(p));
                    break;
            }
        }
Esempio n. 2
0
        private static void VisitCategoryElement(XmlReader reader, AtomEntryBase entry)
        {
            var category = new AtomCategory
                {
                    Term = reader.GetAttribute("term"),
                    Scheme = reader.GetAttribute("scheme"),
                    Label = reader.GetAttribute("label")
                };
            entry.AddCategory(category);

            if (reader.IsEmptyElement)
                return;

            while (reader.Read())
                if (reader.Name.Equals("category") && reader.NodeType == XmlNodeType.EndElement)
                    break;
        }
Esempio n. 3
0
        private static void VisitTextConstruct(XmlReader reader,
                                               AtomEntryBase entry,
                                               String nodeName,
                                               Action<AtomTextConstruct, AtomEntryBase> action)
        {
            AtomTextConstructType t;
            var type = reader.GetAttribute("type");
            Enum.TryParse(type, true, out t);

            while (reader.Read())
            {
                if (reader.Name.Equals(nodeName) && reader.NodeType == XmlNodeType.EndElement)
                    break;

                if (reader.NodeType != XmlNodeType.Text)
                    continue;

                var construct = new AtomTextConstruct
                    {
                        Value = reader.Value,
                        Type = t
                    };
                action(construct, entry);
            }
        }
Esempio n. 4
0
        private static void VisitPersonConstruct(XmlReader reader,
                                                 AtomEntryBase entry,
                                                 String nodeName,
                                                 Action<AtomPersonConstruct, AtomEntryBase> action)
        {
            if (reader.IsEmptyElement)
                return;

            var personConstruct = new AtomPersonConstruct();

            while (reader.Read())
            {
                if (reader.Name.Equals(nodeName) && reader.NodeType == XmlNodeType.EndElement)
                    break;

                if (reader.NodeType != XmlNodeType.Element)
                    continue;

                switch (reader.Name)
                {
                    case "name":
                        VisitPersonConstructNameElement(reader, personConstruct);
                        break;
                    case "uri":
                        VisitPersonConstructUriElement(reader, personConstruct);
                        break;
                    case "email":
                        VisitPersonConstructEmailElement(reader, personConstruct);
                        break;
                }
            }

            action(personConstruct, entry);
        }
Esempio n. 5
0
        private static void VisitLinkElement(XmlReader reader, AtomEntryBase entry)
        {
            var rel = reader.GetAttribute("rel");
            var type = reader.GetAttribute("type");
            var hreflang = reader.GetAttribute("hreflang");
            var title = reader.GetAttribute("title");
            var length = reader.GetAttribute("length");
            Int64 l;
            Int64.TryParse(length, out l);
            Uri href;
            Uri.TryCreate(reader.GetAttribute("href"), UriKind.Absolute, out href);

            var link = new AtomLink
                {
                    Rel = rel,
                    Type = type,
                    HRef = href,
                    HRefLang = hreflang,
                    Title = title,
                    Length = l
                };

            entry.AddLink(link);

            if (reader.IsEmptyElement)
                return;

            while (reader.Read())
                if (reader.Name.Equals("link") && reader.NodeType == XmlNodeType.EndElement)
                    break;
        }
Esempio n. 6
0
        private static void VisitIdElement(XmlReader reader, AtomEntryBase entry)
        {
            if (reader.IsEmptyElement)
                return;

            while (reader.Read())
            {
                if (reader.Name.Equals("id") && reader.NodeType == XmlNodeType.EndElement)
                    break;

                if (reader.NodeType == XmlNodeType.Text)
                    entry.AddId(reader.Value);
            }
        }
Esempio n. 7
0
        private static void VisitDateTime(XmlReader reader,
                                          AtomEntryBase entry,
                                          String nodeName,
                                          Action<DateTime, AtomEntryBase> action)
        {
            while (reader.Read())
            {
                if (reader.Name.Equals(nodeName) && reader.NodeType == XmlNodeType.EndElement)
                    break;

                if (reader.NodeType == XmlNodeType.Text)
                {
                    var date = DateTime.Parse(reader.Value);
                    action(date, entry);
                }
            }
        }