示例#1
0
        public static void AtomEntryPositiveTest_write()
        {
            string filePath          = @"AtomEntryTest.xml";
            string serializeFilePath = Path.GetTempFileName();

            SyndicationItem item = new SyndicationItem("SyndicationFeed released for .net Core", "A lot of text describing the release of .net core feature", new Uri("http://contoso.com/news/path"));

            item.Id = "uuid:43481a10-d881-40d1-adf2-99b438c57e21;id=1";
            item.LastUpdatedTime = new DateTimeOffset(Convert.ToDateTime("2017-10-11T11:25:55Z")).UtcDateTime;

            try
            {
                using (XmlWriter writer = XmlWriter.Create(serializeFilePath))
                {
                    Atom10ItemFormatter f = new Atom10ItemFormatter(item);
                    f.WriteTo(writer);
                    writer.Close();
                }

                XmlDiff diff = new XmlDiff()
                {
                    Option = XmlDiffOption.IgnoreComments | XmlDiffOption.IgnorePrefix | XmlDiffOption.IgnoreWhitespace | XmlDiffOption.IgnoreChildOrder | XmlDiffOption.IgnoreAttributeOrder
                };
                Assert.True(diff.Compare(filePath, serializeFilePath));
            }
            finally
            {
                File.Delete(serializeFilePath);
            }
        }
示例#2
0
        public static void AtomEntryPositiveTest()
        {
            string filePath          = @"brief-entry-noerror.xml";
            string serializeFilePath = Path.GetTempFileName();

            try
            {
                SyndicationItem feedObjct = null;
                using (XmlReader reader = XmlReader.Create(filePath))
                {
                    feedObjct = SyndicationItem.Load(reader);
                    reader.Close();
                }

                using (XmlWriter writer = XmlWriter.Create(serializeFilePath))
                {
                    Atom10ItemFormatter atomformatter = new Atom10ItemFormatter(feedObjct);
                    atomformatter.WriteTo(writer);
                    writer.Close();
                }
                // compare file filePath and serializeFilePath
                XmlDiff diff = new XmlDiff()
                {
                    Option = XmlDiffOption.IgnoreComments | XmlDiffOption.IgnorePrefix | XmlDiffOption.IgnoreWhitespace | XmlDiffOption.IgnoreChildOrder | XmlDiffOption.IgnoreAttributeOrder
                };
                Assert.True(diff.Compare(filePath, serializeFilePath));
            }
            finally
            {
                File.Delete(serializeFilePath);
            }
        }
示例#3
0
        private void WriteAtomEntry(IPublication publication, Stream writeStream)
        {
            var entry = publication.Syndicate();

            var formatter = new Atom10ItemFormatter(entry);

            using (var writer = XmlWriter.Create(writeStream)) {
                formatter.WriteTo(writer);
            }
        }
示例#4
0
        public static void Snippet42()
        {
            // <Snippet42>
            SyndicationItem     item          = new SyndicationItem("Item Title", "Item Content", new Uri("http://Item/Alternate/Link"), "itemID", DateTimeOffset.Now);
            Atom10ItemFormatter atomFormatter = item.GetAtom10Formatter();
            XmlWriter           writer        = XmlWriter.Create("output.xml");

            atomFormatter.WriteTo(writer);
            writer.Close();
            // </Snippet42>
        }
示例#5
0
        public static void Snippet14()
        {
            // <Snippet14>
            SyndicationItem item = new SyndicationItem("Test Item", "This is the content for Test Item", new Uri("http://localhost/ItemOne"), "TestItemID", DateTime.Now);

            Atom10ItemFormatter atomItemFormatter = new Atom10ItemFormatter(item);
            XmlWriter           atomWriter        = XmlWriter.Create("Atom.xml");

            atomItemFormatter.WriteTo(atomWriter);
            atomWriter.Close();
            // </Snippet14>
        }
示例#6
0
 public async Task <Stream> GetStreamAsync()
 {
     return(await Task <Stream> .Run(() =>
     {
         MemoryStream ms = new MemoryStream();
         var sw = XmlWriter.Create(ms);
         Atom10ItemFormatter atomFormatter = new Atom10ItemFormatter(item);
         atomFormatter.WriteTo(sw);
         sw.Flush();
         ms.Seek(0, SeekOrigin.Begin);
         return ms as Stream;
     }));
 }
示例#7
0
        // </Snippet10>

        // <Snippet11>
        public void SerializeItem(SyndicationItem item)
        {
            Atom10ItemFormatter atomFormatter = item.GetAtom10Formatter();
            Rss20ItemFormatter  rssFormatter  = item.GetRss20Formatter();

            XmlWriter atomWriter = XmlWriter.Create("atom.xml");
            XmlWriter rssWriter  = XmlWriter.Create("rss.xml");

            atomFormatter.WriteTo(atomWriter);
            rssFormatter.WriteTo(rssWriter);
            atomWriter.Close();
            rssWriter.Close();
        }
示例#8
0
        public static void AtomEntryPositiveTest_write()
        {
            string file = @"AtomEntryTest.xml";
            string serializeFilePath = Path.GetTempFileName();
            bool   toDeletedFile     = true;

            SyndicationItem item = new SyndicationItem("SyndicationFeed released for .net Core", "A lot of text describing the release of .net core feature", new Uri("http://contoso.com/news/path"));

            item.Id = "uuid:43481a10-d881-40d1-adf2-99b438c57e21;id=1";
            item.LastUpdatedTime = new DateTimeOffset(Convert.ToDateTime("2017-10-11T11:25:55Z")).UtcDateTime;

            try
            {
                using (FileStream fileStream = new FileStream(serializeFilePath, FileMode.OpenOrCreate))
                {
                    using (XmlWriter writer = XmlDictionaryWriter.CreateTextWriter(fileStream))
                    {
                        Atom10ItemFormatter f = new Atom10ItemFormatter(item);
                        f.WriteTo(writer);
                    }
                }

                CompareHelper ch = new CompareHelper
                {
                    Diff = new XmlDiff()
                    {
                        Option = XmlDiffOption.IgnoreComments | XmlDiffOption.IgnorePrefix | XmlDiffOption.IgnoreWhitespace | XmlDiffOption.IgnoreChildOrder | XmlDiffOption.IgnoreAttributeOrder
                    }
                };

                string diffNode = string.Empty;
                if (!ch.Compare(file, serializeFilePath, out diffNode))
                {
                    toDeletedFile = false;
                    string errorMessage = $"The generated file was different from the baseline file:{Environment.NewLine}Baseline: {file}{Environment.NewLine}Actual: {serializeFilePath}{Environment.NewLine}Different Nodes:{Environment.NewLine}{diffNode}";
                    Assert.True(false, errorMessage);
                }
            }
            finally
            {
                if (toDeletedFile)
                {
                    File.Delete(serializeFilePath);
                }
            }
        }
示例#9
0
        public static void Snippet9()
        {
            // <Snippet9>
            // <Snippet10>
            MySyndicationItem item = new MySyndicationItem("Test Item", "This is the content for Test Item", new Uri("http://localhost/ItemOne"), "TestItemID", DateTime.Now);

            item.Links.Add(new SyndicationLink(new Uri("http://someuri"), "alternate", "MyItemLink", "text/html", 100));
            item.PublishDate     = new DateTime(1968, 2, 23);
            item.LastUpdatedTime = DateTime.Today;
            item.SourceFeed      = new SyndicationFeed();
            item.Summary         = new TextSyndicationContent("This the item summary");

            XmlWriter atomWriter = XmlWriter.Create("AtomItem.xml");
            Atom10ItemFormatter <MySyndicationItem> formatter = new Atom10ItemFormatter <MySyndicationItem>(item);

            // </Snippet10>
            formatter.WriteTo(atomWriter);
            atomWriter.Close();
            // </Snippet9>
        }
示例#10
0
        private Stream GetEntryStream()
        {
            XmlWriter    writer      = null;
            MemoryStream entryStream = new MemoryStream();

            try
            {
                writer = XmlWriter.Create(entryStream);
                Atom10ItemFormatter atomFormatter = AtomDocument.GetAtom10Formatter();
                atomFormatter.WriteTo(writer);
                writer.Close();
                entryStream.Seek(0, SeekOrigin.Begin);
            }
            finally
            {
                if (null != writer)
                {
                    writer.Close();
                }
            }

            return(entryStream);
        }