public ActionResult Rss()
        {
            var blog = Blog.GetBlogByName(CurrentWeb);
            if (blog == null)
            {
                throw new HttpException(404, Messages.BlogNotExist);
            }

            int total;
            var posts = Post.GetPostsOfBlog(blog.Id, 1, blog.PostsPerFeed, out total);
            var baseUri = MyLifeContext.AbsoluteWebRoot;
            Response.ContentType = "text/xml";
            var rssWriter = new RssWriter(Response.OutputStream, Encoding.UTF8) {Version = RssVersion.RSS20};
            var rssChanel = new RssChannel
                                {
                                    Title = blog.Name,
                                    Description = blog.Description,
                                    Link = new Uri(baseUri, blog.CreatedBy + "/blog"),
                                    LastBuildDate = DateTime.UtcNow
                                };

            foreach (var post in posts)
            {
                rssChanel.Items.Add(new RssItem
                                        {
                                            Title = post.Title,
                                            Description = post.Content,
                                            Link = new Uri(baseUri, post.RelativeUrl),
                                            Author = post.CreatedBy,
                                            PubDate = post.CreatedDate
                                        });
            }

            rssWriter.Write(rssChanel);
            rssWriter.Close();
            Response.Flush();
            return new EmptyResult();
        }
Esempio n. 2
0
        private void write(RssWriter writer)
        {
            try
            {
                if (channels.Count == 0)
                    throw new InvalidOperationException("Feed must contain at least one channel.");

                writer.Version = rssVersion;

                writer.Modules = modules;

                foreach (RssChannel channel in channels)
                {
                    if (channel.Items.Count == 0)
                        throw new InvalidOperationException("Channel must contain at least one item.");

                    writer.Write(channel);
                }
            }
            finally
            {
                if (writer != null)
                    writer.Close();
            }
        }