Ejemplo n.º 1
0
        private async Task <ISyndicationFeedWriter> GetWriter(string type, XmlWriter xmlWriter, DateTime updated)
        {
            string host = Request.Scheme + "://" + Request.Host + "/";

            if (type.Equals("rss", StringComparison.OrdinalIgnoreCase))
            {
                var rss = new RssFeedWriter(xmlWriter);
                await rss.WriteTitle(_settings.Value.EnglishSiteName);

                await rss.WriteDescription(_settings.Value.Description);

                await rss.WriteGenerator(_settings.Value.EnglishSiteName);

                await rss.WriteValue("link", host);

                return(rss);
            }

            var atom = new AtomFeedWriter(xmlWriter);
            await atom.WriteTitle(_settings.Value.EnglishSiteName);

            await atom.WriteId(host);

            await atom.WriteSubtitle(_settings.Value.Description);

            await atom.WriteGenerator(_settings.Value.EnglishSiteName, _settings.Value.SiteUrl, "1.0");

            await atom.WriteValue("updated", updated.ToString("yyyy-MM-ddTHH:mm:ssZ"));

            return(atom);
        }
Ejemplo n.º 2
0
        private async Task <ISyndicationFeedWriter> GetWriter(string type, XmlWriter xmlWriter, DateTime updated)
        {
            var host = Request.Scheme + "://" + Request.Host + "/";

            if (type.Equals("rss", StringComparison.OrdinalIgnoreCase))
            {
                var rss = new RssFeedWriter(xmlWriter);
                await rss.WriteTitle(_settings.Brand);

                await rss.WriteDescription(_settings.Description);

                await rss.WriteGenerator("Bagombo Blog Engine");

                await rss.WriteValue("link", host);

                return(rss);
            }

            var atom = new AtomFeedWriter(xmlWriter);
            await atom.WriteTitle(_settings.Brand);

            await atom.WriteId(host);

            await atom.WriteSubtitle(_settings.Description);

            await atom.WriteGenerator("Bagombo Blog Engine", "https://github.com/tylerlrhodes/bagobo", "0.2.5a");

            await atom.WriteValue("updated", updated.ToString("yyyy-MM-ddTHH:mm:ssZ"));

            return(atom);
        }
Ejemplo n.º 3
0
        public async Task StatusFeed()
        {
            var item = new SyndicationItem {
                Title = "status"
            };

            item.AddLink(new SyndicationLink(new Uri("http://www.w3.org/2005/Atom")));

            using (var writer = new StringWriter())
            {
                using (var xmlWriter = XmlWriter.Create(writer,
                                                        new XmlWriterSettings()
                {
                    Async = true, Indent = true, Encoding = Encoding.UTF8
                }))
                {
                    var rssWriter = new RssFeedWriter(xmlWriter);

                    await rssWriter.WriteTitle("This is the title");

                    await rssWriter.WriteDescription("description");

                    await rssWriter.Write(item);
                }

                var text = writer.ToString();
            }
        }
Ejemplo n.º 4
0
        public async Task <MemoryStream> Write()
        {
            var sw = new MemoryStream();

            using (var xmlWriter = XmlWriter.Create(sw,
                                                    new XmlWriterSettings()
            {
                Async = true, Indent = true
            }))
            {
                var writer = new RssFeedWriter(xmlWriter);

                await writer.WriteTitle(Title);

                await writer.WriteDescription(Description);

                await writer.Write(Link);

                var languageElement = new SyndicationContent("language")
                {
                    Value = Language
                };
                await writer.Write(languageElement);

                foreach (var item in Items)
                {
                    await writer.Write(item);
                }
                await writer.WritePubDate(LastUpdatedTime);

                await xmlWriter.FlushAsync();
            }

            return(sw);
        }
Ejemplo n.º 5
0
        private async Task <ISyndicationFeedWriter> GetWriter(string type, XmlWriter xmlWriter, DateTime updated)
        {
            var host = Request.Scheme + "://" + Request.Host + "/";

            if (type.Equals("rss", StringComparison.OrdinalIgnoreCase))
            {
                var rss = new RssFeedWriter(xmlWriter);
                await rss.WriteTitle(this.settings.Value.Name);

                await rss.WriteDescription(this.settings.Value.Description);

                await rss.WriteGenerator("mini_blog");

                await rss.WriteValue("link", host);

                return(rss);
            }

            var atom = new AtomFeedWriter(xmlWriter);
            await atom.WriteTitle(this.settings.Value.Name);

            await atom.WriteId(host);

            await atom.WriteSubtitle(this.settings.Value.Description);

            await atom.WriteGenerator("mini_blog", "https://github.com/madskristensen/mini_blog", "1.0");

            await atom.WriteValue("updated", updated.ToString("yyyy-MM-ddTHH:mm:ssZ"));

            return(atom);
        }
        private async Task <ISyndicationFeedWriter> GetWriter(string?type, XmlWriter xmlWriter, DateTime updated)
        {
            var host = $"{this.Request.Scheme}://{this.Request.Host}/";

            if (type?.Equals("rss", StringComparison.OrdinalIgnoreCase) ?? false)
            {
                var rss = new RssFeedWriter(xmlWriter);
                await rss.WriteTitle(this.manifest.Name).ConfigureAwait(false);

                await rss.WriteDescription(this.manifest.Description).ConfigureAwait(false);

                await rss.WriteGenerator("Miniblog.Core").ConfigureAwait(false);

                await rss.WriteValue("link", host).ConfigureAwait(false);

                return(rss);
            }

            var atom = new AtomFeedWriter(xmlWriter);
            await atom.WriteTitle(this.manifest.Name).ConfigureAwait(false);

            await atom.WriteId(host).ConfigureAwait(false);

            await atom.WriteSubtitle(this.manifest.Description).ConfigureAwait(false);

            await atom.WriteGenerator("Miniblog.Core", "https://github.com/madskristensen/Miniblog.Core", "1.0").ConfigureAwait(false);

            await atom.WriteValue("updated", updated.ToString("yyyy-MM-ddTHH:mm:ssZ", CultureInfo.InvariantCulture)).ConfigureAwait(false);

            return(atom);
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> Feed()
        {
            var builder = new StringBuilder();
            var sw      = new StringWriter(builder);

            using (XmlWriter xmlWriter = XmlWriter.Create(sw, new XmlWriterSettings()
            {
                Async = true, Indent = true, OmitXmlDeclaration = true
            }))
            {
                var writer = new RssFeedWriter(xmlWriter);
                await writer.WriteTitle("Test Feed");

                await writer.WriteDescription("Test description of the feed");

                foreach (var item in Enumerable.Range(0, 9))
                {
                    var feedItem = new SyndicationItem();
                    feedItem.Title       = $"Setting-{item}";
                    feedItem.Description = $"Value {item}";
                    await writer.Write(feedItem);
                }

                xmlWriter.Flush();
            }

            return(new ContentResult {
                Content = builder.ToString(), ContentType = "application/rss+xml"
            });
        }
Ejemplo n.º 8
0
        public async Task WriteContent()
        {
            ISyndicationContent content = null;

            //
            // Read
            using (var xmlReader = XmlReader.Create(@"..\..\..\TestFeeds\CustomXml.xml"))
            {
                RssFeedReader reader = new RssFeedReader(xmlReader);
                content = await reader.ReadContent();
            }

            //
            // Write
            StringBuilder sb = new StringBuilder();

            using (var xmlWriter = XmlWriter.Create(sb))
            {
                var writer = new RssFeedWriter(xmlWriter);

                await writer.Write(content);

                await writer.Flush();
            }

            string res = sb.ToString();

            Assert.True(res == "<?xml version=\"1.0\" encoding=\"utf-16\"?><rss version=\"2.0\"><channel><NewItem><enclosure url=\"http://www.scripting.com/mp3s/weatherReportSuite.mp3\" length=\"12216320\" type=\"audio/mpeg\" /><title>Lorem ipsum 2017-07-06T20:25:00+00:00</title><description>Exercitation sit dolore mollit et est eiusmod veniam aute officia veniam ipsum.</description><link>http://example.com/test/1499372700</link><guid isPermaLink=\"true\">http://example.com/test/1499372700</guid><pubDate>Thu, 06 Jul 2017 20:25:00 GMT</pubDate></NewItem></channel></rss>");
        }
Ejemplo n.º 9
0
        public async Task <IActionResult> Execute()
        {
            var feedItems = await _feedRepository.GetAll();

            var sw = new StringWriterWithEncoding(Encoding.UTF8);

            using (var xmlWriter = XmlWriter.Create(sw, new XmlWriterSettings {
                Async = true, Indent = true
            }))
            {
                var writer = new RssFeedWriter(xmlWriter);
                foreach (var feedItem in feedItems)
                {
                    var item = new SyndicationItem
                    {
                        Title       = feedItem.Title,
                        Description = feedItem.Description,
                        Id          = feedItem.Id,
                        Published   = feedItem.CreateDateTime
                    };
                    item.AddContributor(new SyndicationPerson(feedItem.Author, "*****@*****.**"));
                    await writer.Write(item);
                }

                xmlWriter.Flush();
            }

            return(new ObjectResult(sw.ToString()));
        }
Ejemplo n.º 10
0
        public async Task ProcessRequest(IDotvvmRequestContext context)
        {
            var items = await this.GetSyndicationItemsAsync(15);

            using (var sw = new StreamWriter(this.context.HttpContext.Response.Body, Encoding.UTF8, 1024, true))
            {
                var settings = new XmlWriterSettings
                {
                    Async              = true,
                    Indent             = true,
                    Encoding           = Encoding.UTF8,
                    OmitXmlDeclaration = true
                };
                using (var xmlWriter = XmlWriter.Create(sw, settings))
                {
                    var writer = new RssFeedWriter(xmlWriter);
                    await writer.WriteTitle("ASKme");

                    await writer.WriteDescription("Zeptej se mě na co chceš, já na co chci odpovím");

                    await writer.Write(new SyndicationLink(this.GetAbsoluteUri()));

                    await writer.WritePubDate(DateTimeOffset.UtcNow);

                    foreach (var item in items)
                    {
                        await writer.Write(item);
                    }

                    await writer.Flush();

                    xmlWriter.Flush();
                }
            }
        }
Ejemplo n.º 11
0
        public async Task WriteRss20FileAsync(string absolutePath)
        {
            var feed     = GetSyndicationItemCollection(FeedItemCollection);
            var settings = new XmlWriterSettings
            {
                Async    = true,
                Encoding = Encoding.UTF8,
                Indent   = true
            };

            using var xmlWriter = XmlWriter.Create(absolutePath, settings);
            var writer = new RssFeedWriter(xmlWriter);

            await writer.WriteTitle(HeadTitle);

            await writer.WriteDescription(HeadDescription);

            await writer.Write(new SyndicationLink(new Uri(TrackBackUrl)));

            await writer.WritePubDate(DateTimeOffset.UtcNow);

            await writer.WriteCopyright(Copyright);

            await writer.WriteGenerator(Generator);

            foreach (var item in feed)
            {
                await writer.Write(item);
            }

            await xmlWriter.FlushAsync();

            xmlWriter.Close();
        }
Ejemplo n.º 12
0
        public async Task <ActionResult> Rss()
        {
            var sw = new StringWriter();

            using (XmlWriter xmlWriter = XmlWriter.Create(sw, new XmlWriterSettings()
            {
                Async = true, Indent = true
            }))
            {
                var writer = new RssFeedWriter(xmlWriter);

                foreach (var art in BlogArticle.Queryable())
                {
                    // Create item
                    var item = new SyndicationItem()
                    {
                        Title       = art.Title,
                        Description = art.TextPreview,
                        Id          = $"https://matteofabbri.org/read/{art.Link}",
                        Published   = new DateTimeOffset(art.DateTime)
                    };

                    item.AddCategory(new SyndicationCategory(art.Category));
                    item.AddContributor(new SyndicationPerson("Matteo Fabbri", "*****@*****.**"));

                    await writer.Write(item);
                }

                xmlWriter.Flush();
            }
            return(Content(sw.ToString(), "application/rss+xml"));
        }
Ejemplo n.º 13
0
        public async Task WriteCategory()
        {
            var sw = new StringWriterWithEncoding(Encoding.UTF8);

            var cat1 = new SyndicationCategory("Test Category 1")
            {
                Scheme = "http://example.com/test"
            };

            var cat2 = new SyndicationCategory("Test Category 2");

            using (var xmlWriter = XmlWriter.Create(sw))
            {
                var writer = new RssFeedWriter(xmlWriter);

                await writer.Write(cat1);

                await writer.Write(cat2);

                await writer.Flush();
            }

            string res = sw.ToString();

            Assert.True(res == $"<?xml version=\"1.0\" encoding=\"utf-8\"?><rss version=\"2.0\"><channel><category domain=\"{cat1.Scheme}\">{cat1.Name}</category><category>{cat2.Name}</category></channel></rss>");
        }
Ejemplo n.º 14
0
        private async Task <ISyndicationFeedWriter> GetWriter(string type, XmlWriter xmlWriter, DateTime updated)
        {
            if (type.Equals("rss", StringComparison.OrdinalIgnoreCase))
            {
                var rss = new RssFeedWriter(xmlWriter);
                await rss.WriteTitle(SiteSettings.Name);

                await rss.WriteDescription(SiteSettings.Description);

                await rss.WriteGenerator("Miniblog.Core");

                await rss.WriteValue("link", $"{Request.Scheme}://{Request.Host}");

                return(rss);
            }

            var atom = new AtomFeedWriter(xmlWriter);
            await atom.WriteTitle(SiteSettings.Name);

            await atom.WriteId($"{Request.Scheme}://{Request.Host}");

            await atom.WriteSubtitle(SiteSettings.Description);

            await atom.WriteGenerator("Miniblog.Core", "https://github.com/madskristensen/Miniblog.Core", "1.0");

            await atom.WriteValue("updated", updated.ToString("yyyy-MM-ddTHH:mm:ssZ"));

            return(atom);
        }
Ejemplo n.º 15
0
        public async Task <IActionResult> RssFeed()
        {
            var homepageUrl = this.Url.Page("/Index", pageHandler: null, values: null, protocol: this.Request.Scheme);
            var items       = await this.GetSyndicationItemsAsync(this.Request.Scheme, 15);

            using (var sw = new StringWriter()) {
                var settings = new XmlWriterSettings {
                    Async              = true,
                    Indent             = true,
                    Encoding           = Encoding.UTF8,
                    OmitXmlDeclaration = true
                };
                using (var xmlWriter = XmlWriter.Create(sw, settings)) {
                    var writer = new RssFeedWriter(xmlWriter);
                    await writer.WriteTitle("ASKme");

                    await writer.WriteDescription("Zeptej se mě na co chceš, já na co chci odpovím");

                    await writer.Write(new SyndicationLink(new Uri(homepageUrl)));

                    await writer.WritePubDate(DateTimeOffset.UtcNow);

                    foreach (var item in items)
                    {
                        await writer.Write(item);
                    }

                    xmlWriter.Flush();
                }
                return(this.File(Encoding.UTF8.GetBytes(sw.ToString()), "application/rss+xml;charset=utf-8"));
            }
        }
Ejemplo n.º 16
0
 private async Task writeSyndicationItemsAsync(RssFormatter formatter, RssFeedWriter rssFeedWriter)
 {
     foreach (var item in getSyndicationItems())
     {
         var content = new SyndicationContent(formatter.CreateContent(item));
         content.AddField(new SyndicationContent("atom:updated", Atom10Namespace, item.LastUpdated.ToString("r")));
         await rssFeedWriter.Write(content);
     }
 }
Ejemplo n.º 17
0
        private async Task addChannelLastUpdatedTimeAsync(RssFeedWriter rssFeedWriter)
        {
            if (_feedChannel.RssItems == null || !_feedChannel.RssItems.Any())
            {
                return;
            }

            await rssFeedWriter.WriteLastBuildDate(
                _feedChannel.RssItems.OrderByDescending(x => x.LastUpdatedTime).First().LastUpdatedTime);
        }
Ejemplo n.º 18
0
        private async Task <RssFeedWriter> getRssFeedWriterAsync(XmlWriter xmlWriter)
        {
            var rssFeedWriter = new RssFeedWriter(xmlWriter, _attributes);

            await addChannelIdentityAsync(rssFeedWriter);
            await addChannelLastUpdatedTimeAsync(rssFeedWriter);
            await addChannelImageAsync(rssFeedWriter);

            return(rssFeedWriter);
        }
Ejemplo n.º 19
0
        private XmlFeedWriter InitializeRssFeedWriter(XmlWriter xmlWriter)
        {
            var result = new RssFeedWriter(xmlWriter);

            result.WriteTitle(_siteSettings.SiteName);
            result.WriteDescription(_siteSettings.Description);
            result.WriteCopyright(_siteSettings.Copyright);
            result.WriteGenerator(_siteSettings.Nickname);
            result.WritePubDate(_blogPostsConfig.Blogs.Where(x => x.Published).First().CreateDate.Date);
            return(result);
        }
Ejemplo n.º 20
0
        public async Task CompareContents()
        {
            string filePath = @"..\..\..\TestFeeds\internetRssFeed.xml";
            string res      = null;

            using (var xmlReader = XmlReader.Create(filePath, new XmlReaderSettings()
            {
                Async = true
            }))
            {
                var reader = new RssFeedReader(xmlReader);

                var sw = new StringWriterWithEncoding(Encoding.UTF8);

                using (var xmlWriter = XmlWriter.Create(sw))
                {
                    var writer = new RssFeedWriter(xmlWriter);

                    while (await reader.Read())
                    {
                        switch (reader.ElementType)
                        {
                        case SyndicationElementType.Item:
                            await writer.Write(await reader.ReadItem());

                            break;

                        case SyndicationElementType.Person:
                            await writer.Write(await reader.ReadPerson());

                            break;

                        case SyndicationElementType.Image:
                            await writer.Write(await reader.ReadImage());

                            break;

                        default:
                            await writer.Write(await reader.ReadContent());

                            break;
                        }
                    }

                    await writer.Flush();
                }

                res = sw.ToString();
            }

            await CompareFeeds(new RssFeedReader(XmlReader.Create(filePath)),
                               new RssFeedReader(XmlReader.Create(new StringReader(res))));
        }
Ejemplo n.º 21
0
        public async Task Echo()
        {
            string res = null;

            using (var xmlReader = XmlReader.Create(@"..\..\..\TestFeeds\rss20-2items.xml", new XmlReaderSettings()
            {
                Async = true
            }))
            {
                var reader = new RssFeedReader(xmlReader);

                var sw = new StringWriterWithEncoding(Encoding.UTF8);

                using (var xmlWriter = XmlWriter.Create(sw))
                {
                    var writer = new RssFeedWriter(xmlWriter);

                    while (await reader.Read())
                    {
                        switch (reader.ElementType)
                        {
                        case SyndicationElementType.Item:
                            await writer.Write(await reader.ReadItem());

                            break;

                        case SyndicationElementType.Person:
                            await writer.Write(await reader.ReadPerson());

                            break;

                        case SyndicationElementType.Image:
                            await writer.Write(await reader.ReadImage());

                            break;

                        default:
                            await writer.Write(await reader.ReadContent());

                            break;
                        }
                    }

                    await writer.Flush();
                }

                res = sw.ToString();
                Assert.True(res == "<?xml version=\"1.0\" encoding=\"utf-8\"?><rss version=\"2.0\"><channel><title asd=\"123\">Lorem ipsum feed for an interval of 1 minutes</title><description>This is a constantly updating lorem ipsum feed</description><link length=\"123\" type=\"testType\">http://example.com/</link><image><url>http://2.bp.blogspot.com/-NA5Jb-64eUg/URx8CSdcj_I/AAAAAAAAAUo/eCx0irI0rq0/s1600/bg_Microsoft_logo3-20120824073001907469-620x349.jpg</url><title>Microsoft News</title><link>http://www.microsoft.com/news</link><description>Test description</description></image><generator>RSS for Node</generator><lastBuildDate>Thu, 06 Jul 2017 20:25:17 GMT</lastBuildDate><managingEditor>John Smith</managingEditor><pubDate>Thu, 06 Jul 2017 20:25:00 GMT</pubDate><copyright>Michael Bertolacci, licensed under a Creative Commons Attribution 3.0 Unported License.</copyright><ttl>60</ttl><item><title>Lorem ipsum 2017-07-06T20:25:00+00:00</title><enclosure url=\"http://www.scripting.com/mp3s/weatherReportSuite.mp3\" length=\"12216320\" type=\"audio/mpeg\" /><link>http://example.com/test/1499372700</link><guid>http://example.com/test/1499372700</guid><description>Exercitation sit dolore mollit et est eiusmod veniam aute officia veniam ipsum.</description><author>John Smith</author><pubDate>Thu, 06 Jul 2017 20:25:00 GMT</pubDate></item><item><title>Lorem ipsum 2017-07-06T20:24:00+00:00</title><link>http://example.com/test/1499372640</link><guid>http://example.com/test/1499372640</guid><enclosure url=\"http://www.scripting.com/mp3s/weatherReportSuite.mp3\" length=\"12216320\" type=\"audio/mpeg\" /><description>Do ipsum dolore veniam minim est cillum aliqua ea.</description><author>John Smith</author><pubDate>Thu, 06 Jul 2017 20:24:00 GMT</pubDate></item></channel></rss>");
            }

            await RssReader.TestReadFeedElements(XmlReader.Create(new StringReader(res)));
        }
Ejemplo n.º 22
0
        private async Task addChannelIdentityAsync(RssFeedWriter rssFeedWriter)
        {
            await rssFeedWriter.WriteDescription(_feedChannel.FeedDescription.ApplyRle().RemoveHexadecimalSymbols());

            await rssFeedWriter.WriteCopyright(_feedChannel.FeedCopyright.ApplyRle().RemoveHexadecimalSymbols());

            await rssFeedWriter.WriteTitle(_feedChannel.FeedTitle.ApplyRle().RemoveHexadecimalSymbols());

            await rssFeedWriter.WriteLanguage(new CultureInfo(_feedChannel.CultureName));

            await rssFeedWriter.WriteRaw($"<atom:link href=\"{_httpContextInfo.GetRawUrl()}\" rel=\"self\" type=\"application/rss+xml\" />");

            await rssFeedWriter.Write(new SyndicationLink(_httpContextInfo.GetBaseUri(), relationshipType : RssElementNames.Link));
        }
Ejemplo n.º 23
0
        private async Task addChannelImageAsync(RssFeedWriter rssFeedWriter)
        {
            if (string.IsNullOrWhiteSpace(_feedChannel.FeedImageContentPath))
            {
                return;
            }

            var syndicationImage = new SyndicationImage(_httpContextInfo.AbsoluteContent(_feedChannel.FeedImageContentPath))
            {
                Title = _feedChannel.FeedImageTitle,
                Link  = new SyndicationLink(_httpContextInfo.AbsoluteContent(_feedChannel.FeedImageContentPath))
            };
            await rssFeedWriter.Write(syndicationImage);
        }
Ejemplo n.º 24
0
        public async Task WriteItem()
        {
            var url = new Uri("https://contoso.com/");

            //
            // Construct item
            var item = new SyndicationItem()
            {
                Id          = "https://contoso.com/28af09b3-86c7-4dd6-b56f-58aaa17cff62",
                Title       = "First item on ItemWriter",
                Description = "Brief description of an item",
                Published   = DateTimeOffset.UtcNow
            };

            item.AddLink(new SyndicationLink(url));
            item.AddLink(new SyndicationLink(url, RssLinkTypes.Enclosure)
            {
                Title     = "https://contoso.com/",
                Length    = 4123,
                MediaType = "audio/mpeg"
            });
            item.AddLink(new SyndicationLink(url, RssLinkTypes.Comments));
            item.AddLink(new SyndicationLink(url, RssLinkTypes.Source)
            {
                Title = "Anonymous Blog"
            });

            item.AddLink(new SyndicationLink(new Uri(item.Id), RssLinkTypes.Guid));

            item.AddContributor(new SyndicationPerson("John Doe", "*****@*****.**"));

            item.AddCategory(new SyndicationCategory("Test Category"));

            //
            // Write
            var sw = new StringWriterWithEncoding(Encoding.UTF8);

            using (var xmlWriter = XmlWriter.Create(sw))
            {
                var writer = new RssFeedWriter(xmlWriter);

                await writer.Write(item);

                await writer.Flush();
            }

            string res = sw.ToString();

            Assert.True(res == $"<?xml version=\"1.0\" encoding=\"utf-8\"?><rss version=\"2.0\"><channel><item><title>First item on ItemWriter</title><link>{url}</link><enclosure url=\"{url}\" length=\"4123\" type=\"audio/mpeg\" /><comments>{url}</comments><source url=\"{url}\">Anonymous Blog</source><guid>{item.Id}</guid><description>Brief description of an item</description><author>[email protected] (John Doe)</author><category>Test Category</category><pubDate>{item.Published.ToRfc1123()}</pubDate></item></channel></rss>", res);
        }
Ejemplo n.º 25
0
        public async Task Podcast()
        {
            Response.ContentType = "application/rss+xml";

            List <SyndicationItem>        items    = new List <SyndicationItem>();
            List <Podcast.Models.Podcast> podcasts = _dbContext.Podcasts.Where(p => p.Published).OrderByDescending(p => p.Episode).ToList();

            if (podcasts != null)
            {
                foreach (Podcast.Models.Podcast podcast in podcasts)
                {
                    SyndicationItem item = new SyndicationItem()
                    {
                        Id          = podcast.Episode.ToString(),
                        Title       = podcast.Title,
                        Description = MarkdownHelper.Markdown(podcast.Description).Value,
                        Published   = podcast.DatePublished
                    };

                    item.AddLink(new SyndicationLink(new Uri(Url.SubRouteUrl("podcast", "Podcast.View", new { episode = podcast.Episode }))));

                    foreach (Podcast.Models.PodcastFile file in podcast.Files)
                    {
                        SyndicationLink enclosure = new SyndicationLink(new Uri(Url.SubRouteUrl("podcast", "Podcast.Download", new { episode = podcast.Episode, fileName = file.FileName })));
                        item.AddLink(enclosure);
                    }

                    items.Add(item);
                }
            }

            using (var xmlWriter = CreateXmlWriter())
            {
                var feedWriter = new RssFeedWriter(xmlWriter);

                await feedWriter.WriteTitle(_config.PodcastConfig.Title);

                await feedWriter.WriteDescription(_config.PodcastConfig.Description);

                await feedWriter.Write(new SyndicationLink(new Uri(Url.SubRouteUrl("podcast", "Podcast.Index"))));

                foreach (SyndicationItem item in items)
                {
                    await feedWriter.Write(item);
                }

                await xmlWriter.FlushAsync();
            }
        }
Ejemplo n.º 26
0
        public async Task ExecuteResultAsync(ActionContext context)
        {
            var response = context.HttpContext.Response;
            var request  = context.HttpContext.Request;

            response.ContentType = "application/xml";

            var host = request.Scheme + "://" + request.Host;

            using (var xmlWriter = XmlWriter.Create(response.Body, new XmlWriterSettings()
            {
                Async = true, Indent = true, Encoding = new UTF8Encoding(true)
            }))
            {
                var rss = new RssFeedWriter(xmlWriter);
                await rss.WriteTitle(_options.Value.Title);

                await rss.WriteDescription(_options.Value.Description);

                await rss.WriteGenerator(_options.Value.GeneratorDescription);

                await rss.WriteValue("link", host);

                foreach (var post in _page.Items)
                {
                    var item = new AtomEntry
                    {
                        Title       = post.Title,
                        Description = post.GetContentWithoutDataSrc(),
                        Id          = post.Id.ToString(),
                        Published   = post.PublishedDate.Value,
                        LastUpdated = post.ModifiedDate,
                        ContentType = "html",
                    };

                    foreach (var tag in post.BlogStoryTags)
                    {
                        item.AddCategory(new SyndicationCategory(tag.Tag.Name));
                    }

                    item.AddContributor(new SyndicationPerson(_options.Value.AuthorName, _options.Value.FullEmail, "author"));
                    item.AddLink(new SyndicationLink(new Uri($"{host}/{post.Alias}")));

                    await rss.Write(item);
                }
            }
        }
Ejemplo n.º 27
0
    public static async Task WriteCustomItem()
    {
        const string ExampleNs = "http://contoso.com/syndication/feed/examples";
        var          sw        = new StringWriterWithEncoding(Encoding.UTF8);

        using (XmlWriter xmlWriter = XmlWriter.Create(sw, new XmlWriterSettings()
        {
            Async = true, Indent = true
        }))
        {
            var attributes = new List <SyndicationAttribute>()
            {
                new SyndicationAttribute("xmlns:example", ExampleNs)
            };

            var formatter = new RssFormatter(attributes, xmlWriter.Settings);
            var writer    = new RssFeedWriter(xmlWriter, attributes, formatter);

            // Create item
            var item = new SyndicationItem()
            {
                Title       = "Rss Writer Available",
                Description = "The new RSS Writer is now available as a NuGet package!",
                Id          = "https://www.nuget.org/packages/Microsoft.SyndicationFeed",
                Published   = DateTimeOffset.UtcNow
            };

            item.AddCategory(new SyndicationCategory("Technology"));
            item.AddContributor(new SyndicationPerson("test", "*****@*****.**"));

            //
            // Format the item as SyndicationContent
            var content = new SyndicationContent(formatter.CreateContent(item));

            // Add custom fields/attributes
            content.AddField(new SyndicationContent("customElement", ExampleNs, "Custom Value"));

            // Write
            await writer.Write(content);

            // Done
            xmlWriter.Flush();
        }

        Console.WriteLine(sw.ToString());
    }
Ejemplo n.º 28
0
        public async Task WriteSkipDays()
        {
            var sw = new StringWriterWithEncoding(Encoding.UTF8);

            using (XmlWriter xmlWriter = XmlWriter.Create(sw))
            {
                var writer = new RssFeedWriter(xmlWriter);

                await writer.WriteSkipDays(new DayOfWeek[] { DayOfWeek.Friday, DayOfWeek.Monday });

                await writer.Flush();
            }

            string res = sw.ToString();

            Assert.True(res == "<?xml version=\"1.0\" encoding=\"utf-8\"?><rss version=\"2.0\"><channel><skipDays><day>Friday</day><day>Monday</day></skipDays></channel></rss>");
        }
Ejemplo n.º 29
0
        public async Task WriteCloud()
        {
            var sw = new StringWriterWithEncoding(Encoding.UTF8);

            using (XmlWriter xmlWriter = XmlWriter.Create(sw))
            {
                var writer = new RssFeedWriter(xmlWriter);

                await writer.WriteCloud(new Uri("http://podcast.contoso.com/rpc"), "xmlStorageSystem.rssPleaseNotify", "xml-rpc");

                await writer.Flush();
            }

            string res = sw.ToString();

            Assert.True(res == "<?xml version=\"1.0\" encoding=\"utf-8\"?><rss version=\"2.0\"><channel><cloud domain=\"podcast.contoso.com\" port=\"80\" path=\"/rpc\" registerProcedure=\"xmlStorageSystem.rssPleaseNotify\" protocol=\"xml-rpc\" /></channel></rss>");
        }
Ejemplo n.º 30
0
        public async Task WriteSkipHours()
        {
            var sw = new StringWriterWithEncoding(Encoding.UTF8);

            using (XmlWriter xmlWriter = XmlWriter.Create(sw))
            {
                var writer = new RssFeedWriter(xmlWriter);

                await writer.WriteSkipHours(new byte[] { 0, 4, 1, 11, 23, 20 });

                await writer.Flush();
            }

            string res = sw.ToString();

            Assert.True(res == "<?xml version=\"1.0\" encoding=\"utf-8\"?><rss version=\"2.0\"><channel><skipHours><hour>0</hour><hour>4</hour><hour>1</hour><hour>11</hour><hour>23</hour><hour>20</hour></skipHours></channel></rss>");
        }