protected virtual SyndicationItem ReadItem(XmlReader reader, SyndicationFeed feed)
        {
            Rss20ItemFormatter formatter = new Rss20ItemFormatter();

            formatter.ReadFrom(reader);
            return(formatter.Item);
        }
Ejemplo n.º 2
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));
        }
Ejemplo n.º 3
0
        internal static TSyndicationItem LoadItem <TSyndicationItem> (XmlReader reader) where TSyndicationItem : SyndicationItem, new()
        {
            switch (DetectVersion(reader, ReaderKind.Item))
            {
            case SyndicationVersions.Atom10:
                Atom10ItemFormatter af = new Atom10ItemFormatter <TSyndicationItem> ();
                af.ReadFrom(reader);
                return((TSyndicationItem)af.Item);

            case SyndicationVersions.Rss20:
            default:             // anything else are rejected by DetectVersion
                Rss20ItemFormatter rf = new Rss20ItemFormatter <TSyndicationItem> ();
                rf.ReadFrom(reader);
                return((TSyndicationItem)rf.Item);
            }
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
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)));
        }
Ejemplo n.º 6
0
		public void ReadFrom_WrongDate1 ()
		{
			Rss20ItemFormatter f = new Rss20ItemFormatter ();
			f.ReadFrom (CreateReader ("<item><pubDate /></item>"));
		}
Ejemplo n.º 7
0
		public void SerializeExtensionsAsAtom ()
		{
			Rss20ItemFormatter f = new Rss20ItemFormatter ();
			Assert.IsTrue (f.SerializeExtensionsAsAtom, "#1");
		}
Ejemplo n.º 8
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");
		}
Ejemplo n.º 9
0
		public void ReadFromGuidPermaLink ()
		{
			const string xml1 = "<item><guid isPermaLink=\"false\">urn:myid</guid><description /></item>";
			using (XmlReader r = CreateReader (xml1)) {
				var rss = new Rss20ItemFormatter ();
				rss.ReadFrom (r);
				Assert.AreEqual ("urn:myid", rss.Item.Id);
			}

			const string xml2 = "<item><guid isPermaLink=\"true\">urn:myid</guid><description /></item>";
			using (XmlReader r = CreateReader (xml2)) {
				var rss = new Rss20ItemFormatter ();
				rss.ReadFrom (r);
				Assert.AreEqual ("urn:myid", rss.Item.Id);
			}
		}
Ejemplo n.º 10
0
		public void Version ()
		{
			Rss20ItemFormatter f = new Rss20ItemFormatter ();
			Assert.AreEqual ("Rss20", f.Version, "#1");
		}
Ejemplo n.º 11
0
		public void ReadFrom_Comments ()
		{
			Rss20ItemFormatter f = new Rss20ItemFormatter ();
			f.ReadFrom (CreateReader ("<item><comments>comment</comments></item>"));
			Assert.IsNotNull (f.Item, "#1");
			// 'comments' is treated as extensions ...
			Assert.AreEqual (1, f.Item.ElementExtensions.Count, "#2");
		}
Ejemplo n.º 12
0
		public void ReadFrom_Enclosure ()
		{
			Rss20ItemFormatter f = new Rss20ItemFormatter ();

			// .NET bug: it allows extension attributes, but rejects extension elements.
//			f.ReadFrom (CreateReader ("<item><enclosure url='urn:foo' length='50' type='text/html' wcf='wtf'><extended /></enclosure></item>"));
			f.ReadFrom (CreateReader ("<item><enclosure url='urn:foo' length='50' type='text/html' wcf='wtf'></enclosure></item>"));

			// 'enclosure' is treated as SyndicationLink
			Assert.AreEqual (1, f.Item.Links.Count, "#1");
			SyndicationLink link = f.Item.Links [0];
			Assert.AreEqual (50, link.Length, "#2");
			Assert.AreEqual ("urn:foo", link.Uri.ToString (), "#3");
			Assert.AreEqual ("text/html", link.MediaType, "#4");
			Assert.AreEqual ("enclosure", link.RelationshipType, "#5");
			Assert.AreEqual (1, link.AttributeExtensions.Count, "#6");
			//Assert.AreEqual (1, link.ElementExtensions.Count, "#7");
		}
Ejemplo n.º 13
0
		public void ReadFrom_WrongDate2 ()
		{
			Rss20ItemFormatter f = new Rss20ItemFormatter ();
			f.ReadFrom (CreateReader ("<item><pubDate>2000-01-01T00:00:00</pubDate></item>"));
		}
Ejemplo n.º 14
0
		protected virtual SyndicationItem ReadItem (XmlReader reader, SyndicationFeed feed)
		{
			Rss20ItemFormatter formatter = new Rss20ItemFormatter();
			formatter.ReadFrom (reader);
			return formatter.Item;
		}
Ejemplo n.º 15
0
		public void ReadXml_TitleOnly ()
		{
			Rss20ItemFormatter f = new Rss20ItemFormatter ();
			((IXmlSerializable) f).ReadXml (CreateReader ("<item><title>test</title></item>"));
			Assert.IsNotNull (f.Item.Title, "#1");
			Assert.AreEqual ("test", f.Item.Title.Text, "#2");

			((IXmlSerializable) f).ReadXml (CreateReader ("<dummy><title>test</title></dummy>")); // it is ok
		}
Ejemplo n.º 16
0
		public void ReadFrom2 () {
			SyndicationItem item = new SyndicationItem ();
			Rss20ItemFormatter f = new Rss20ItemFormatter (item);
			Assert.IsTrue (object.ReferenceEquals (item, f.Item), "Item #1");
			f.ReadFrom (CreateReader ("<item><title>test</title></item>"));
			Assert.IsFalse (object.ReferenceEquals(item, f.Item), "Item #2");
		}
Ejemplo n.º 17
0
		public void ReadFrom1 ()
		{
			Rss20ItemFormatter f = new Rss20ItemFormatter ();
			Assert.IsNull (f.Item, "#1");
			f.ReadFrom (CreateReader ("<item><title>test</title></item>"));
			SyndicationItem item1 = f.Item;
			Assert.IsNotNull (f.Item.Title, "#2");
			Assert.AreEqual ("test", f.Item.Title.Text, "#3");
			f.ReadFrom (CreateReader ("<item><title>test</title></item>"));
			Assert.IsFalse (object.ReferenceEquals (item1, f.Item), "#4");
		}