Example #1
0
        private Action<Stream> GetXmlContents(IEnumerable<BlogPost> model)
        {
            var items = new List<SyndicationItem>();

            foreach (var post in model)
            {
                // Replace all relative urls with full urls.
                var contentHtml = Regex.Replace(post.Content, UrlRegex, m => siteUrl.TrimEnd('/') + "/" + m.Value.TrimStart('/'));
                var excerptHtml = Regex.Replace(post.Summary, UrlRegex, m => siteUrl.TrimEnd('/') + "/" + m.Value.TrimStart('/'));

                var item = new SyndicationItem(
                    post.Title,
                    contentHtml,
                    new Uri(siteUrl + post.Localink)
                    )
                {
                    Id = siteUrl + post.Localink,
                    LastUpdatedTime = post.PublishedDate.ToUniversalTime(),
                    PublishDate = post.PublishedDate.ToUniversalTime(),
                    Content = new TextSyndicationContent(contentHtml, TextSyndicationContentKind.Html),
                    Summary = new TextSyndicationContent(excerptHtml, TextSyndicationContentKind.Html),

                };
                item.Authors.Add(new SyndicationPerson(post.AuthorEmail, post.Author, string.Empty));
                item.Categories.Add(new SyndicationCategory("nancy"));

                items.Add(item);
            }

            var feed = new SyndicationFeed(
                RssTitle,
                RssTitle, /* Using Title also as Description */
                new Uri(siteUrl + "/" + feedfileName),
                items);

            var formatter = new Rss20FeedFormatter(feed);

            return stream =>
            {
                var encoding = new UTF8Encoding(false);
                var streamWrapper = new UnclosableStreamWrapper(stream);

                using (var writer = new XmlTextWriter(streamWrapper, encoding))
                {
                    formatter.WriteTo(writer);
                }
            };
        }
Example #2
0
        private Action<Stream> GetXmlContents(IEnumerable<Post> model)
        {
            var items = new List<SyndicationItem>();

            foreach (var post in model)
            {
                // Replace all relative urls with full urls.
                var newHtml = Regex.Replace(post.Content, UrlRegex, m => siteUrl.TrimEnd('/') + "/" + m.Value.TrimStart('/'));

                var item = new SyndicationItem(
                    post.Title,
                    newHtml,
                    new Uri(siteUrl + post.Url)
                    )
                {
                    Id = siteUrl + post.Url,
                    LastUpdatedTime = post.Date.ToUniversalTime(),
                    PublishDate = post.Date.ToUniversalTime(),
                    Summary = new TextSyndicationContent(post.ContentExcerpt, TextSyndicationContentKind.Html)
                };

                items.Add(item);
            }

            var feed = new SyndicationFeed(
                RssTitle,
                RssTitle, /* Using Title also as Description */
                new Uri(siteUrl + "/" + feedfileName),
                items);

            var formatter = new Rss20FeedFormatter(feed);

            return stream =>
            {
                var encoding = new UTF8Encoding(false);
                var streamWrapper = new UnclosableStreamWrapper(stream);

                using (var writer = new XmlTextWriter(streamWrapper, encoding))
                {
                    formatter.WriteTo(writer);
                }
            };
        }
Example #3
0
        private Action<Stream> GetXmlContents(IEnumerable<Post> model)
        {
            var items = new List<SyndicationItem>();

            foreach (Post post in model)
            {

                var item = new SyndicationItem(
                    title: post.Title,
                    content: post.Content,
                    itemAlternateLink: new Uri(siteUrl + post.Url),
                    id: siteUrl + post.Url,
                    lastUpdatedTime: post.Date.ToUniversalTime()
                    );
                item.PublishDate = post.Date.ToUniversalTime();
                item.Summary = new TextSyndicationContent(post.ContentExcerpt, TextSyndicationContentKind.Html);
                items.Add(item);
            }

            var feed = new SyndicationFeed(
                this.RssTitle,
                this.RssTitle, /* Using Title also as Description */
                new Uri(siteUrl + "/" + feedfileName),
                items);

            var formatter = new Rss20FeedFormatter(feed);

            return stream =>
            {
                var encoding =
                    new UTF8Encoding(false);

                var streamWrapper =
                    new UnclosableStreamWrapper(stream);

                using (var writer = new XmlTextWriter(streamWrapper, encoding))
                {
                    formatter.WriteTo(writer);
                }
            };
        }
        public void Should_return_action_value_as_response_with_content_set_as_value()
        {
            // Given
            var module = new ConfigurableNancyModule(with =>
            {
                with.Get("/action", (x, m) =>
                {
                    Action<Stream> result = stream =>
                    {
                        var wrapper = new UnclosableStreamWrapper(stream);
                        using (var writer = new StreamWriter(wrapper))
                        {
                            writer.Write("Hiya Nancy!");
                        }
                    };

                    return result;
                });
            });

            var browser = new Browser(with =>
            {
                with.Module(module);
            });

            // When
            var response = browser.Get("/action");

            // Then
            Assert.Equal("Hiya Nancy!", response.Body.AsString());
        }
Example #5
0
        private Action<Stream> GetXmlContents(IEnumerable<Post> model)
        {
            var items = new List<SyndicationItem>();

            foreach (var post in model)
            {
                // Replace all relative urls with full urls.
                var newHtml = Regex.Replace(post.Content, UrlRegex, m => siteUrl.TrimEnd('/') + "/" + m.Value.TrimStart('/'));

                var item = new SyndicationItem(
                    post.Title,
                    newHtml,
                    new Uri(siteUrl + post.Url)
                    )
                {
                    Id = siteUrl + post.Url,
                    LastUpdatedTime = post.Date.ToUniversalTime(),
                    PublishDate = post.Date.ToUniversalTime(),
                    Content = new TextSyndicationContent(post.Content, TextSyndicationContentKind.Html),
                    Summary = new TextSyndicationContent(post.ContentExcerpt, TextSyndicationContentKind.Html),
                };

                items.Add(item);
            }

            var feed = new SyndicationFeed(
                AtomTitle,
                AtomTitle, /* Using Title also as Description */
                new Uri(siteUrl + "/" + feedfileName),
                items)
                {
                    Id = siteUrl + "/",
                    LastUpdatedTime = new DateTimeOffset(DateTime.Now),
                    Generator = "Sandra.Snow Atom Generator"
                };
            feed.Authors.Add(new SyndicationPerson(authorEmail, author, siteUrl));

            var link = new SyndicationLink(new Uri(siteUrl + "/" + feedfileName))
            {
                RelationshipType = "self",
                MediaType = "text/html",
                Title = AtomTitle
            };
            feed.Links.Add(link);


            var formatter = new Atom10FeedFormatter(feed);

            return stream =>
            {
                var encoding = new UTF8Encoding(false);
                var streamWrapper = new UnclosableStreamWrapper(stream);

                using (var writer = new XmlTextWriter(streamWrapper, encoding))
                {
                    formatter.WriteTo(writer);
                }
            };
        }