Exemplo n.º 1
0
        public void ReadFrom1()
        {
            Atom10ItemFormatter f = new Atom10ItemFormatter();

            Assert.IsNull(f.Item, "#1");
            f.ReadFrom(CreateReader("<entry xmlns='http://www.w3.org/2005/Atom'><title>test</title></entry>"));
            SyndicationItem item1 = f.Item;

            Assert.IsNotNull(f.Item.Title, "#2");
            Assert.AreEqual("test", f.Item.Title.Text, "#3");
            f.ReadFrom(CreateReader("<entry xmlns='http://www.w3.org/2005/Atom'><title>test</title></entry>"));
            Assert.IsFalse(object.ReferenceEquals(item1, f.Item), "#4");
        }
Exemplo n.º 2
0
        public override object ReadFromStream(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger)
        {
            HttpContentHeaders contentHeaders = content == null ? null : content.Headers;

            // If content length is 0 then return default value for this type
            if (contentHeaders != null && contentHeaders.ContentLength == null)
            {
                return(GetDefaultValueForType(type));
            }

            try {
                using (readStream) {
                    using (var reader = XmlReader.Create(readStream)) {
                        var formatter = new Atom10ItemFormatter();
                        formatter.ReadFrom(reader);

                        var command = Activator.CreateInstance(type);
                        ((IPublicationCommand)command).ReadSyndicationItem(formatter.Item);

                        return(command);
                    }
                }
            }
            catch (Exception e) {
                if (formatterLogger == null)
                {
                    throw;
                }
                formatterLogger.LogError(String.Empty, e);
                return(GetDefaultValueForType(type));
            }
        }
Exemplo n.º 3
0
        public void ReadFrom_Id()
        {
            Atom10ItemFormatter f = new Atom10ItemFormatter();

            f.ReadFrom(CreateReader("<entry xmlns='http://www.w3.org/2005/Atom'><id>urn:myid</id></entry>"));
            Assert.IsNotNull(f.Item, "#1");
            Assert.AreEqual("urn:myid", f.Item.Id, "#2");
        }
Exemplo n.º 4
0
        public void ReadFrom_Extension()
        {
            Atom10ItemFormatter f = new Atom10ItemFormatter();

            f.ReadFrom(CreateReader("<entry xmlns='http://www.w3.org/2005/Atom'><ext>external</ext></entry>"));
            Assert.IsNotNull(f.Item, "#1");
            Assert.AreEqual(1, f.Item.ElementExtensions.Count, "#2");
        }
Exemplo n.º 5
0
        public static void Snippet15()
        {
            // <Snippet15>
            Atom10ItemFormatter myItemAtomFormatter = new Atom10ItemFormatter(typeof(MySyndicationItem));
            XmlReader           atomReader          = XmlReader.Create("http://Contoso/Feeds/MyFeed/Items");

            myItemAtomFormatter.ReadFrom(atomReader);
            atomReader.Close();
            // </Snippet15>
        }
        public T DeserializeResourceDescription <T>(string resourceDescription)
        {
            DataContractSerializer serializer = new DataContractSerializer(typeof(T));
            Atom10ItemFormatter    formater   = new Atom10ItemFormatter();

            formater.ReadFrom(new XmlTextReader(new StringReader(resourceDescription)));
            XmlSyndicationContent content = formater.Item.Content as XmlSyndicationContent;

            return(content.ReadContent <T>(serializer));
        }
Exemplo n.º 7
0
        public static void Snippet13()
        {
            // <Snippet13>
            Atom10ItemFormatter itemFormatter = new Atom10ItemFormatter();
            XmlReader           atomReader    = XmlReader.Create("http://Contoso/Feeds/MyFeed/Item");

            if (itemFormatter.CanRead(atomReader))
            {
                itemFormatter.ReadFrom(atomReader);
                atomReader.Close();
            }
            // </Snippet13>
        }
Exemplo n.º 8
0
        public void ReadFrom_Link()
        {
            Atom10ItemFormatter f = new Atom10ItemFormatter();

            f.ReadFrom(CreateReader("<entry xmlns='http://www.w3.org/2005/Atom'><link href='urn:foo' rel='enclosure' length='50' type='text/html' wcf='wtf'><extended /></link></entry>"));

            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");
        }
Exemplo n.º 9
0
        public void ReadFrom_WrongDate()
        {
            Atom10ItemFormatter f = new Atom10ItemFormatter();

            f.ReadFrom(CreateReader("<entry xmlns='http://www.w3.org/2005/Atom'><published>Sat, 01 Jan 2000 00:00:00 Z</pubDate></entry>"));
        }
Exemplo n.º 10
0
        // It is not rejected. Though I think it is .NET bug.
        public void ReadFrom_EmptyDate()
        {
            Atom10ItemFormatter f = new Atom10ItemFormatter();

            f.ReadFrom(CreateReader("<entry xmlns='http://www.w3.org/2005/Atom'><pubDate /></entry>"));
        }