当前位置: 首页>>代码示例>>C#>>正文


C# SyndicationFeed.GetRss20Formatter方法代码示例

本文整理汇总了C#中System.ServiceModel.Syndication.SyndicationFeed.GetRss20Formatter方法的典型用法代码示例。如果您正苦于以下问题:C# SyndicationFeed.GetRss20Formatter方法的具体用法?C# SyndicationFeed.GetRss20Formatter怎么用?C# SyndicationFeed.GetRss20Formatter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.ServiceModel.Syndication.SyndicationFeed的用法示例。


在下文中一共展示了SyndicationFeed.GetRss20Formatter方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SyndicationFeedResult

        public SyndicationFeedResult(SyndicationFeed feed)
        {
            this.ContentType = "application/rss+xml";

            using (StringWriter stringWriter = new Utf8StringWriter())
            {
                using (XmlWriter writer = XmlWriter.Create(stringWriter, new XmlWriterSettings
                {
                    Indent = true,
                    ConformanceLevel = ConformanceLevel.Document,
                    CheckCharacters = true,
                    NamespaceHandling = NamespaceHandling.OmitDuplicates,
                    OmitXmlDeclaration = false,
                    Encoding = Encoding.UTF8,
                }))
                {
                    Rss20FeedFormatter formatter = feed.GetRss20Formatter(serializeExtensionsAsAtom: false);
                    formatter.PreserveAttributeExtensions = true;
                    formatter.PreserveAttributeExtensions = true;
                    formatter.WriteTo(writer);
                }

                this.Content = stringWriter.ToString();
            }
        }
开发者ID:swegner,项目名称:tbot-rss,代码行数:25,代码来源:SyndicationFeedResult.cs

示例2: SerializeFeed

        public string SerializeFeed(SyndicationFeed feed, SyndicationFormat format)
        {
            using (var stream = new MemoryStream())
            {
                var writer = XmlWriter.Create(stream);

                if (format == SyndicationFormat.Atom)
                {
                    feed.GetAtom10Formatter().WriteTo(writer);
                }
                else
                {
                    feed.GetRss20Formatter().WriteTo(writer);
                }

                writer.Flush();

                stream.Position = 0;

                var reader = new StreamReader(stream, Encoding.UTF8);
                return reader.ReadToEnd();
            }
        }
开发者ID:dstarosta,项目名称:GitProjects,代码行数:23,代码来源:FeedResultTests.cs

示例3: GetPosts

        public HttpResponseMessage GetPosts(string id, HttpRequestMessage request, int pageIndex = 1, int pageSize = 10)
        {
            HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);

            try
            {
                IPostsService postsService = ObjectFactory.GetInstance<IPostsService>();
                var posts = postsService.GetAllFromBlog(String.Format("blogs/{0}", id), pageIndex, pageSize);

                if (posts != null)
                {
                    if (this.ClientAcceptsMediaType("text/html", request))
                    {
                        var postsHtml = posts.GeneratePostsHtml();
                        response.Content = new ObjectContent<string>(postsHtml, "text/html");
                    }
                    else
                    {
                        SyndicationFeed blogPostsFeed = new SyndicationFeed
                                                            {
                                                                Title =
                                                                    new TextSyndicationContent(
                                                                    String.Format("Blog {0} posts", id)),
                                                                LastUpdatedTime = new DateTimeOffset(DateTime.Now)
                                                            };

                        blogPostsFeed.Links.Add(SyndicationLink.CreateSelfLink(request.RequestUri));

                        List<SyndicationItem> itemList = new List<SyndicationItem>();
                        blogPostsFeed.Items = itemList;

                        foreach (var post in posts)
                        {
                            SyndicationItem item = new SyndicationItem
                                                       {
                                                           Id = post.Id,
                                                           LastUpdatedTime = post.updated,
                                                           PublishDate = post.published,
                                                           Title = new TextSyndicationContent(post.title)
                                                       };

                            item.Links.Add(SyndicationLink.CreateSelfLink(new Uri(String.Format("{0}/{1}/{2}", this.serviceURI, post.blogId, post.Id))));
                            item.Links.Add(SyndicationLink.CreateAlternateLink(request.RequestUri, "text/html"));

                            item.Links.Add(new SyndicationLink(new Uri(String.Format("{0}/{1}", this.serviceURI, post.blogId)), "service.blog", "Parent blog", "application/atom+xml;type=feed", 0));
                            item.Links.Add(new SyndicationLink(new Uri(String.Format("{0}/{1}/{2}", this.serviceURI, post.blogId, post.Id)), "service.edit", "Edit post", "application/atom+xml;type=feed", 0));
                            item.Links.Add(new SyndicationLink(new Uri(String.Format("{0}/{1}/{2}/{3}", this.serviceURI, post.blogId, post.Id, "service.comments")), "comments", "Post comments", "application/atom+xml;type=feed", 0));

                            var pagingLinks = this.BuildPagingLinks(postsService.Count(), pageIndex, pageSize, request.RequestUri);

                            foreach (var link in pagingLinks)
                            {
                                item.Links.Add(link);
                            }

                            item.Authors.Add(new SyndicationPerson(string.Empty, post.author, string.Empty));
                            item.Content = SyndicationContent.CreatePlaintextContent(post.content);

                            itemList.Add(item);
                        }

                        SyndicationFeedFormatter formatter = null;

                        if (this.ClientAcceptsMediaType("application/atom+xml", request))
                        {
                            formatter = blogPostsFeed.GetAtom10Formatter();
                        }
                        else
                        {
                            if (this.ClientAcceptsMediaType("application/rss+xml", request))
                            {
                                formatter = blogPostsFeed.GetRss20Formatter();
                            }
                        }

                        response.Content = new ObjectContent(typeof(SyndicationFeedFormatter), formatter);
                    }
                }
                else
                {
                    response.StatusCode = HttpStatusCode.NoContent;
                }
            }
            catch (Exception)
            {
                response.StatusCode = HttpStatusCode.InternalServerError;
            }

            return response;
        }
开发者ID:luismdcp,项目名称:PROMPT-06-Services,代码行数:90,代码来源:RESTBlogsService.cs

示例4: GetPost

        public HttpResponseMessage GetPost(string blogId, string id, HttpRequestMessage request)
        {
            HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);

            try
            {
                IPostsService postsService = ObjectFactory.GetInstance<IPostsService>();
                var post = postsService.Get(String.Format("posts/{0}", id));

                var etag = request.Headers.IfNoneMatch.FirstOrDefault();

                if (etag != null && etag.Tag == post.etag)
                {
                    response.StatusCode = HttpStatusCode.NotModified;
                }
                else
                {
                    if (post != null)
                    {
                        if (this.ClientAcceptsMediaType("text/html", request))
                        {
                            response.Content = new ObjectContent<string>(post.ToHtml(), "text/html");
                        }
                        else
                        {
                            SyndicationFeed postFeed = new SyndicationFeed
                                                           {
                                                               Title = new TextSyndicationContent("Single Post"),
                                                               LastUpdatedTime = new DateTimeOffset(DateTime.Now)
                                                           };

                            postFeed.Links.Add(SyndicationLink.CreateSelfLink(request.RequestUri));

                            SyndicationItem item = new SyndicationItem();
                            List<SyndicationItem> itemList = new List<SyndicationItem> {item};
                            postFeed.Items = itemList;

                            item.Id = post.Id;
                            item.LastUpdatedTime = post.updated;
                            item.PublishDate = post.published;
                            item.Title = new TextSyndicationContent(post.title);
                            item.Content = new TextSyndicationContent(post.content);

                            item.Links.Add(SyndicationLink.CreateSelfLink(request.RequestUri));
                            item.Links.Add(SyndicationLink.CreateAlternateLink(request.RequestUri, "text/html"));

                            item.Links.Add(new SyndicationLink(request.RequestUri, "service.edit", "Edit Post", "application/atom+xml;type=feed", 0));
                            item.Links.Add(new SyndicationLink(new Uri(String.Format("{0}/blogs/{1}/{2}/{3}", this.serviceURI, blogId, post.Id, "service.comments")), "comments", "Post comments", "application/atom+xml;type=feed", 0));
                            item.Links.Add(new SyndicationLink(new Uri(String.Format("{0}/blogs/{1}", this.serviceURI, blogId)), "service.blog", "Parent blog", "application/atom+xml;type=feed", 0));

                            item.Authors.Add(new SyndicationPerson(string.Empty, post.author, string.Empty));

                            SyndicationFeedFormatter formatter = null;

                            if (this.ClientAcceptsMediaType("application/atom+xml", request))
                            {
                                formatter = postFeed.GetAtom10Formatter();
                            }
                            else
                            {
                                if (this.ClientAcceptsMediaType("application/rss+xml", request))
                                {
                                    formatter = postFeed.GetRss20Formatter();
                                }
                            }

                            response.Content = new ObjectContent(typeof(SyndicationFeedFormatter), formatter);
                        }
                    }
                    else
                    {
                        response.StatusCode = HttpStatusCode.NotFound;
                    }
                }
            }
            catch (Exception)
            {
                response.StatusCode = HttpStatusCode.InternalServerError;
            }

            return response;
        }
开发者ID:luismdcp,项目名称:PROMPT-06-Services,代码行数:82,代码来源:RESTBlogsService.cs

示例5: GetBlogTagCloud

        public HttpResponseMessage GetBlogTagCloud(string id, HttpRequestMessage request)
        {
            HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);

            try
            {
                IBlogsService blogsService = ObjectFactory.GetInstance<IBlogsService>();
                var blog = blogsService.Get(String.Format("blogs/{0}", id));
                var tagCloud = blogsService.GetTagCloud(String.Format("blogs/{0}", id));

                if (blog != null)
                {
                    SyndicationFeed blogFeed = new SyndicationFeed
                                                   {
                                                       Title = new TextSyndicationContent("Blog tag cloud"),
                                                       LastUpdatedTime = new DateTimeOffset(DateTime.Now)
                                                   };

                    blogFeed.Links.Add(SyndicationLink.CreateSelfLink(request.RequestUri));

                    SyndicationItem item = new SyndicationItem();
                    List<SyndicationItem> itemList = new List<SyndicationItem> {item};
                    blogFeed.Items = itemList;

                    item.Id = blog.Id;
                    item.LastUpdatedTime = blog.updated;
                    item.PublishDate = blog.published;
                    item.Title = new TextSyndicationContent("Blog tag cloud");
                    item.Content = SyndicationContent.CreatePlaintextContent(BuildtagCloud(tagCloud));
                    item.Links.Add(SyndicationLink.CreateSelfLink(request.RequestUri));

                    SyndicationFeedFormatter formatter = null;

                    if (this.ClientAcceptsMediaType("application/atom+xml", request))
                    {
                        formatter = blogFeed.GetAtom10Formatter();
                    }
                    else
                    {
                        if (this.ClientAcceptsMediaType("application/rss+xml", request))
                        {
                            formatter = blogFeed.GetRss20Formatter();
                        }
                    }

                    response.Content = new ObjectContent(typeof(SyndicationFeedFormatter), formatter);
                }
                else
                {
                    response.StatusCode = HttpStatusCode.NotFound;
                }
            }
            catch (Exception)
            {
                response.StatusCode = HttpStatusCode.InternalServerError;
            }

            return response;
        }
开发者ID:luismdcp,项目名称:PROMPT-06-Services,代码行数:59,代码来源:RESTBlogsService.cs

示例6: GetBlogs

        public HttpResponseMessage GetBlogs(HttpRequestMessage request, int pageIndex = 1, int pageSize = 10)
        {
            HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);

            try
            {
                IBlogsService blogsService = ObjectFactory.GetInstance<IBlogsService>();
                List<Blog> blogs = blogsService.GetAll(pageIndex, pageSize);

                if (blogs != null)
                {
                    if (this.ClientAcceptsMediaType("text/html", request))
                    {
                        var blogsHtml = blogs.GenerateBlogsHtml();
                        response.Content = new ObjectContent<string>(blogsHtml, "text/html");
                    }
                    else
                    {
                        SyndicationFeed blogsFeed = new SyndicationFeed
                                                        {
                                                            Title = new TextSyndicationContent("Blogs List"),
                                                            LastUpdatedTime = new DateTimeOffset(DateTime.Now)
                                                        };

                        blogsFeed.Links.Add(SyndicationLink.CreateSelfLink(request.RequestUri));

                        List<SyndicationItem> itemList = new List<SyndicationItem>();
                        blogsFeed.Items = itemList;

                        foreach (var blog in blogs)
                        {
                            SyndicationItem item = new SyndicationItem
                                                       {
                                                           Id = blog.Id,
                                                           LastUpdatedTime = blog.updated,
                                                           PublishDate = blog.published,
                                                           Title = new TextSyndicationContent(blog.name),
                                                           Summary = new TextSyndicationContent(blog.description)
                                                       };

                            item.Links.Add(SyndicationLink.CreateSelfLink(new Uri(String.Format("{0}/{1}", this.serviceURI, blog.Id))));
                            item.Links.Add(SyndicationLink.CreateAlternateLink(request.RequestUri, "text/html"));

                            item.Links.Add(new SyndicationLink(new Uri(String.Format("{0}/{1}", this.serviceURI, blog.Id)), "service.edit", "Edit Blog", "application/atom+xml;type=feed", 0));
                            item.Links.Add(new SyndicationLink(new Uri(String.Format("{0}/{1}/posts", this.serviceURI, blog.Id)), "service.posts", "Blog posts", "application/atom+xml;type=feed", 0));

                            var pagingLinks = this.BuildPagingLinks(blogsService.Count(), pageIndex, pageSize, request.RequestUri);

                            foreach (var link in pagingLinks)
                            {
                                item.Links.Add(link);
                            }

                            item.Authors.Add(new SyndicationPerson(string.Empty, blog.author, string.Empty));

                            itemList.Add(item);
                        }

                        SyndicationFeedFormatter formatter = null;

                        if (this.ClientAcceptsMediaType("application/atom+xml", request))
                        {
                            formatter = blogsFeed.GetAtom10Formatter();
                        }
                        else
                        {
                            if (this.ClientAcceptsMediaType("application/rss+xml", request))
                            {
                                formatter = blogsFeed.GetRss20Formatter();
                            }
                        }

                        response.Content = new ObjectContent(typeof(SyndicationFeedFormatter), formatter);
                    }
                }
                else
                {
                    response.StatusCode = HttpStatusCode.NoContent;
                }
            }
            catch (Exception)
            {
                response.StatusCode = HttpStatusCode.InternalServerError;
            }

            return response;
        }
开发者ID:luismdcp,项目名称:PROMPT-06-Services,代码行数:87,代码来源:RESTBlogsService.cs


注:本文中的System.ServiceModel.Syndication.SyndicationFeed.GetRss20Formatter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。