Exemplo n.º 1
0
        public static async Task <TSyndicationItem> LoadAsync <TSyndicationItem>(XmlReader reader)
            where TSyndicationItem : SyndicationItem, new()
        {
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }

            Atom10ItemFormatter <TSyndicationItem> atomSerializer = new Atom10ItemFormatter <TSyndicationItem>();

            if (atomSerializer.CanRead(reader))
            {
                atomSerializer.ReadFrom(reader);
                return(atomSerializer.Item as TSyndicationItem);
            }

            Rss20ItemFormatter <TSyndicationItem> rssSerializer = new Rss20ItemFormatter <TSyndicationItem>();

            if (rssSerializer.CanRead(reader))
            {
                await rssSerializer.ReadFromAsync(reader).ConfigureAwait(false);

                return(rssSerializer.Item as TSyndicationItem);
            }

            throw new XmlException(SR.Format(SR.UnknownItemXml, reader.LocalName, reader.NamespaceURI));
        }
Exemplo n.º 2
0
        public static TSyndicationItem Load <TSyndicationItem>(XmlReader reader) where TSyndicationItem : SyndicationItem, new()
        {
            if (reader == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("reader");
            }
            Atom10ItemFormatter <TSyndicationItem> formatter = new Atom10ItemFormatter <TSyndicationItem>();

            if (formatter.CanRead(reader))
            {
                formatter.ReadFrom(reader);
                return(formatter.Item as TSyndicationItem);
            }
            Rss20ItemFormatter <TSyndicationItem> formatter2 = new Rss20ItemFormatter <TSyndicationItem>();

            if (!formatter2.CanRead(reader))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(System.ServiceModel.SR.GetString("UnknownItemXml", new object[] { reader.LocalName, reader.NamespaceURI })));
            }
            formatter2.ReadFrom(reader);
            return(formatter2.Item as TSyndicationItem);
        }
Exemplo n.º 3
0
        public static TSyndicationItem Load <TSyndicationItem>(XmlReader reader)
            where TSyndicationItem : SyndicationItem, new()
        {
            if (reader == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(reader));
            }
            Atom10ItemFormatter <TSyndicationItem> atomSerializer = new Atom10ItemFormatter <TSyndicationItem>();

            if (atomSerializer.CanRead(reader))
            {
                atomSerializer.ReadFrom(reader);
                return(atomSerializer.Item as TSyndicationItem);
            }
            Rss20ItemFormatter <TSyndicationItem> rssSerializer = new Rss20ItemFormatter <TSyndicationItem>();

            if (rssSerializer.CanRead(reader))
            {
                rssSerializer.ReadFrom(reader);
                return(rssSerializer.Item as TSyndicationItem);
            }
            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(SR.Format(SR.UnknownItemXml, reader.LocalName, reader.NamespaceURI)));
        }
Exemplo n.º 4
0
		public void CanRead ()
		{
			Rss20ItemFormatter f = new Rss20ItemFormatter ();
			Assert.IsFalse (f.CanRead (CreateReader ("<rss>")), "#1");
			Assert.IsTrue (f.CanRead (CreateReader ("<item>")), "#2");
			Assert.IsFalse (f.CanRead (CreateReader ("<item xmlns='urn:foo'>")), "#3");
			Assert.IsFalse (f.CanRead (CreateReader ("<entry xmlns='http://www.w3.org/2005/Atom'>")), "#4");
			Assert.IsFalse (f.CanRead (CreateReader ("<hoge>")), "#5");
			XmlReader r = CreateReader ("<item></item>");
			r.Read (); // element
			r.Read (); // endelement
			Assert.IsFalse (f.CanRead (r), "#6");

			r = CreateReader ("<item><title>test</title></item>");
			r.Read (); // item
			r.Read (); // title
			Assert.IsFalse (f.CanRead (r), "#7");
		}