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


C# SyndicationFeed.SaveAsAtom10方法代码示例

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


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

示例1: GetSyndicationFeed

        public static string GetSyndicationFeed(this IEnumerable<Notification> notifications, string contentType)
        {
            var feed = new SyndicationFeed("System notification", "Publishes system notifications", new Uri("http://localhost"));
            feed.Authors.Add(new SyndicationPerson("[email protected]", "Testor Testorsson", "http://localhost"));
            feed.Links.Add(SyndicationLink.CreateSelfLink(new Uri(HttpContext.Current.Request.Url.AbsoluteUri), "application/atom+xml"));
            feed.Items = notifications.ASyndicationItems(feed);

            var stringWriter = new StringWriter();

            XmlWriter feedWriter = XmlWriter.Create(stringWriter, new XmlWriterSettings
            {
                OmitXmlDeclaration = true
            });

            feed.Copyright = SyndicationContent.CreatePlaintextContent("Copyright hygia");
            feed.Language = "en-us";

            if (contentType == ContentTypes.Atom)
                feed.SaveAsAtom10(feedWriter);
            else
                feed.SaveAsRss20(feedWriter);

            feedWriter.Close();

            return stringWriter.ToString();
        }
开发者ID:northshoreab,项目名称:Hygia,代码行数:26,代码来源:NotificationExtensions.cs

示例2: ExecuteResult

 public override void ExecuteResult(ControllerContext context)
 {
     var rss = new SyndicationFeed(
         _title,
         _desc,
         _altLink,
         _items
     );
     var settings = new XmlWriterSettings {Indent = true, NewLineHandling = NewLineHandling.Entitize};
     using (var writer = XmlWriter.Create(context.HttpContext.Response.OutputStream, settings))
     {
         rss.SaveAsAtom10(writer);
     }
 }
开发者ID:the404,项目名称:yqblog,代码行数:14,代码来源:Rss.cs

示例3: OnWriteToStream

        protected override void OnWriteToStream(Type type, object value, Stream stream, HttpContentHeaders contentHeaders, TransportContext context)
        {
            var bloglist = value as IEnumerable<Blog>;
            if (bloglist != null)
            {
                var syndicationFeed =
                    new SyndicationFeed("Blogs", "all blogs", new Uri(this.ServiceURI + "/blogs"))
                        {
                            Items = bloglist
                                .Select(blogItem => BlogAtomConverter
                                                        .BlogToSyndicationItem(blogItem, this.ServiceURI))
                        };

                using (var xmlWriter = XmlWriter.Create(stream))
                {
                    syndicationFeed.SaveAsAtom10(xmlWriter);
                }
            }
        }
开发者ID:vilhena,项目名称:PROMPT11-06-Services.vilhena,代码行数:19,代码来源:AtomFeedBlogListFormatter.cs

示例4: OnWriteToStream

        protected override void OnWriteToStream(Type type, object value, Stream stream, HttpContentHeaders contentHeaders, TransportContext context)
        {
            var post = value as Post;
            if (post == null) return;

            var syndicationFeed =
                new SyndicationFeed(post.Title, "Post " + post.Title
                                    , new Uri(this.ServiceURI + "/blogs/" + post.BlogId + "/posts/" +
                                              post.Id))
                    {
                        Items = new List<SyndicationItem>()
                                    {
                                        PostAtomConverter.PostToSyndicationItem(post, this.ServiceURI)
                                    }
                    };

            using (var xmlWriter = XmlWriter.Create(stream))
            {
                syndicationFeed.SaveAsAtom10(xmlWriter);
            }
        }
开发者ID:vilhena,项目名称:PROMPT11-06-Services.vilhena,代码行数:21,代码来源:AtomFeedPostFormatter.cs

示例5: GetAllCommits

        HttpResponseMessage GetAllCommits(HttpRequestMessage msg)
        {
            string uri1;
            IEnumerable<CommitInfo> commits;
            GetCommits(out uri1, out commits);

            var feedTree = new SyndicationFeed("Commit List", "Commits from GITHub", new Uri(uri1));
            var items = new List<SyndicationItem>();
            foreach (var commitInfo in commits)
            {
                var item = new SyndicationItem();
                item.Title = new TextSyndicationContent("item");
                item.BaseUri = new Uri(commitInfo.url);
                if (commitInfo.commit.author != null)
                {
                    item.PublishDate = System.Convert.ToDateTime(commitInfo.commit.author.date);
                    item.Authors.Add(new SyndicationPerson() { Name = commitInfo.commit.author.name });
                }
                items.Add(item);
            }
            feedTree.Items = items;

            //var str = new StringBuilder();
            //var wr = XmlWriter.Create(str);

            var mem = new MemoryStream();
            var wr = XmlWriter.Create(mem);
            
            feedTree.SaveAsAtom10(wr);
            wr.Flush();

            //var content = new StringContent(str.ToString());
            var content = new StreamContent(mem);
            content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/atom+xml");

            var resp = new HttpResponseMessage() { StatusCode = HttpStatusCode.OK, Content = content };
            //var resp = new HttpResponseMessage() { StatusCode = HttpStatusCode.OK, Content = new StringContent("teste") };
            resp.Headers.Date = DateTimeOffset.Now;
            return resp;
        }
开发者ID:sandrapatfer,项目名称:PROMPT11-06-Services.sandrapatfer,代码行数:40,代码来源:GitHubServiceImpl.cs

示例6: OnWriteToStream

        protected override void OnWriteToStream(Type type, object value, Stream stream, HttpContentHeaders contentHeaders, TransportContext context)
        {
            var postList = value as IEnumerable<Post>;
            if (postList == null) return;

            var syndicationFeed =
                new SyndicationFeed("Posts from Blog " + postList.FirstOrDefault().Blog.Title
                                    , postList.FirstOrDefault().Blog.Description
                                    ,
                                    new Uri(this.ServiceURI + "/blogs/" + postList.FirstOrDefault().BlogId +
                                            "/posts"))
                    {
                        Items = postList
                            .Select(postItem => PostAtomConverter
                                                    .PostToSyndicationItem(postItem, this.ServiceURI))
                    };

            using (var xmlWriter = XmlWriter.Create(stream))
            {
                syndicationFeed.SaveAsAtom10(xmlWriter);
            }
        }
开发者ID:vilhena,项目名称:PROMPT11-06-Services.vilhena,代码行数:22,代码来源:AtomFeedPostListFormatter.cs

示例7: Execute

        public void Execute(IList<IFilter> filters, PipelineSettings pipelineSettings)
        {
            IEnumerable<SyndicationItem> items;

            if (pipelineSettings.Inputs != null)
            {
                // Get a list of feed items
                items = from feed in ParallelCrawl(pipelineSettings.Inputs)
                                                        from i in feed.Items
                                                        select i;
            }
            else
            {
                items = new SyndicationItem[0];
            }

            // Filter
            IEnumerable<SyndicationItem> filtered = items
                .Where(x => ApplyFilters(filters, x) == FilterAction.Include);

            // Remove duplicates
            IEnumerable<SyndicationItem> merged = Dedup(filtered);

            if (pipelineSettings.Output != null)
            {
                // Save results
                var newFeed = new SyndicationFeed(merged.OrderBy(i => i.PublishDate));

                newFeed.Title = SyndicationContent.CreatePlaintextContent(pipelineSettings.Title);
                newFeed.Description = SyndicationContent.CreatePlaintextContent(pipelineSettings.Description);
                newFeed.LastUpdatedTime = DateTimeOffset.Now;

                using (XmlWriter writer = XmlWriter.Create(pipelineSettings.Output))
                {
                    newFeed.SaveAsAtom10(writer);
                }
            }
        }
开发者ID:marc-truitt,项目名称:RssPercolator,代码行数:38,代码来源:PipelineEvaluator.cs

示例8: GetUpdateFeedString

         internal string GetUpdateFeedString(SyndicationFeed feed, XmlWriterSettings xmlWriterSettings)
         {
            using (var stringWriter = new StringWriterWithEncoding(Encoding.UTF8))
            {
               using (var writer = XmlWriter.Create(stringWriter, xmlWriterSettings))
               {
                  feed.SaveAsAtom10(writer);
               }

               var feedString = stringWriter.ToString();

               return feedString;
            }
         }
开发者ID:ssh-git,项目名称:training-manager,代码行数:14,代码来源:SyndicationFeedModels.cs

示例9: GetServiceStream

        public static Stream GetServiceStream(string format, string callback, DataTable dt, SyndicationFeed sf)
        {
            MemoryStream stream = new MemoryStream();
            StreamWriter writer = new StreamWriter(stream, Encoding.UTF8);
            if (format == "xml")
            {
                XmlSerializer xmls = new XmlSerializer(typeof(DataTable));
                xmls.Serialize(writer, dt);
                WebOperationContext.Current.OutgoingResponse.ContentType = "text/xml";
            }
            else if (format == "json")
            {
                var toJSON = new JavaScriptSerializer();
                toJSON.RegisterConverters(new JavaScriptConverter[] { new JavaScriptDataTableConverter() });
                writer.Write(toJSON.Serialize(dt));
                WebOperationContext.Current.OutgoingResponse.ContentType = "text/json";
            }
            else if (format == "jsonp")
            {
                var toJSON = new JavaScriptSerializer();
                toJSON.RegisterConverters(new JavaScriptConverter[] { new JavaScriptDataTableConverter() });
                writer.Write(callback + "( " + toJSON.Serialize(dt) + " );");
                WebOperationContext.Current.OutgoingResponse.ContentType = "text/json";
            }
            else if (format == "rss")
            {
                XmlWriter xmlw = new XmlTextWriter(writer);
                sf.SaveAsRss20(xmlw);
                WebOperationContext.Current.OutgoingResponse.ContentType = "text/xml";
            }
            else if (format == "atom")
            {
                XmlWriter xmlw = new XmlTextWriter(writer);
                sf.SaveAsAtom10(xmlw);
                WebOperationContext.Current.OutgoingResponse.ContentType = "text/xml";
            }
            else if (format == "help")
            {
                StreamReader sr = new StreamReader(ConfigurationManager.AppSettings["ServiceDocumentation"].ToString());
                writer.Write(sr.ReadToEnd());
                sr.Close();
                WebOperationContext.Current.OutgoingResponse.ContentType = "text/html";
            }
            else
            {
                writer.Write("Invalid formatting specified.");
                WebOperationContext.Current.OutgoingResponse.ContentType = "text/html";
            }

            writer.Flush();
            stream.Position = 0;
            return stream;
        }
开发者ID:radius314,项目名称:wcfrest,代码行数:53,代码来源:ServiceEngine.cs

示例10: SerializeToAtom10

        /// <summary>
        /// Takes a syndication feed and returns an Atom10 string
        /// </summary>
        /// <param name="feed">Syndication Feed</param>
        /// <returns>RSS formated string</returns>
        public static string SerializeToAtom10(SyndicationFeed feed)
        {
            using (StringWriterWithEncoding writer = new StringWriterWithEncoding(Encoding.UTF8))
            {
                XmlWriterSettings settings = new XmlWriterSettings();
                settings.Encoding = new UTF8Encoding(false);
                //settings.Indent = true;

                using (XmlWriter xWriter = XmlWriter.Create(writer, settings))
                {
                    feed.SaveAsAtom10(xWriter);
                    xWriter.Flush();
                    return writer.ToString();
                }
            }
        }
开发者ID:rocketeerbkw,项目名称:DNA,代码行数:21,代码来源:StringUtils.cs

示例11: WriteFeedXml

        /// <summary>
        /// The write feed xml.
        /// </summary>
        /// <param name="feedType">
        /// The feed Type.
        /// </param>
        private void WriteFeedXml(FeedType feedType)
        {
            Settings app = SettingsComp.GetSettings();
            string url = app.Url;
            if (url == string.Empty)
            {
                Uri uri = System.Web.HttpContext.Current.Request.Url;
                string dnsPath = uri.Scheme + "://" + uri.Host;
                if (!uri.IsDefaultPort)
                {
                    dnsPath = dnsPath + ":" + uri.Port.ToString();
                }

                string appPath = System.Web.HttpContext.Current.Request.ApplicationPath;
                url = dnsPath + appPath;
            }

            if (url.Substring(url.Length - 1, 1) != "/")
            {
                url += "/";
            }

            List<PostInfo> posts = BlogComp.GetPosts();
            List<SyndicationItem> items = new List<SyndicationItem>();

            int count = 0;
            foreach (PostInfo post in posts)
            {
                if (++count > 20)
                {
                    break;
                }

                SyndicationItem item = new SyndicationItem();
                item.Title = SyndicationContent.CreatePlaintextContent(post.Title);

                TimeSpan ts = DateTime.UtcNow - DateTime.Now;
                item.PublishDate = new DateTimeOffset(post.Time, ts);

                string url2 = string.Format("{0}Post/{1}", url, post.FileID);
                SyndicationLink link = SyndicationLink.CreateAlternateLink(new Uri(url2));

                item.Links.Add(link);

                Post post2 = PostComp.GetPost(post.FileID);
                item.Content = SyndicationContent.CreateHtmlContent(post2.Contents);

                string catName = CategoryComp.GetCategoryName(post.CatID);
                item.Categories.Add(new SyndicationCategory(catName));

                items.Add(item);
            }

            SyndicationFeed feed = new SyndicationFeed(items);

            feed.Title = SyndicationContent.CreatePlaintextContent(app.Name);
            feed.Links.Add(SyndicationLink.CreateAlternateLink(new Uri(url)));

            List<Author> authors = AuthorComp.GetAuthors();
            foreach (Author author in authors)
            {
                feed.Authors.Add(new SyndicationPerson(author.Email, author.Name, author.Url));
            }

            List<Category> catList = CategoryComp.GetCategories();
            foreach (Category cat in catList)
            {
                feed.Categories.Add(new SyndicationCategory(cat.Name));
            }

            XmlWriterSettings settings = new XmlWriterSettings();
            settings.Encoding = System.Text.Encoding.UTF8;
            settings.OmitXmlDeclaration = true;
            settings.Indent = true;

            if (feedType == FeedType.RSS)
            {
                XmlWriter writer = XmlWriter.Create(this.Server.MapPath("~/App_Data/Rss.xml"), settings);
                feed.SaveAsRss20(writer);
                writer.Flush();
                writer.Close();
            }
            else
            {
                XmlWriter writer = XmlWriter.Create(this.Server.MapPath("~/App_Data/Atom.xml"), settings);
                feed.SaveAsAtom10(writer);
                writer.Flush();
                writer.Close();
            }
        }
开发者ID:pickup,项目名称:PickupBlog,代码行数:96,代码来源:BlogController.cs

示例12: Search

        public ActionResult Search(string terms, string source, string locale, int index = 1, int size = 20, string format = "")
        {
            //App.Get().SetCulture(locale);
            var src = string.IsNullOrEmpty(source) ? App.Get().Searcher.Sources.First().Name : source;
            if (terms == null)
            {
                ViewBag.Query = new SearchQuery()
                {
                    Source = src,
                    Locale = locale
                };
                return View();
            }

            var searchQuery = new SearchQuery()
            {
                Index = index - 1,
                Size = size,
                Source = src,
                Terms = terms,
                Locale = locale
            };

            var model = App.Get().Searcher.Search(searchQuery);
            var feed = new SyndicationFeed(string.Format("Search for {0}", terms), src, Request.Url, model);
            feed.Generator = "DotNetAge";

            if (format.Equals("rss", System.StringComparison.OrdinalIgnoreCase) ||
                format.Equals("atom", System.StringComparison.OrdinalIgnoreCase))
            {
                var sb = new StringBuilder();
                using (var writer = System.Xml.XmlWriter.Create(sb))
                {
                    if (format.Equals("rss", System.StringComparison.OrdinalIgnoreCase))
                    {
                        feed.SaveAsRss20(writer);
                        writer.Flush();
                        return Content(sb.ToString(), "text/xml", Encoding.UTF8);
                    }

                    if (format.Equals("atom", System.StringComparison.OrdinalIgnoreCase))
                    {
                        feed.SaveAsAtom10(writer);
                        writer.Flush();
                        return Content(sb.ToString(), "text/xml", Encoding.UTF8);
                    }
                }
            }
            ViewBag.Query = searchQuery;

            return Json(feed,JsonRequestBehavior.AllowGet);
        }
开发者ID:howej,项目名称:dotnetage,代码行数:52,代码来源:SearchController.cs

示例13: Feed

        public ActionResult Feed(string format)
        {
            var posts = _index.GetBlogPosts().OrderByDescending(x => x.PostedAt);

            // Create feed items.
            var items = new List<SyndicationItem>();
            foreach (var post in posts)
            {
                var feedItem = new SyndicationItem
                {
                    Content = new TextSyndicationContent(post.FeedBody, TextSyndicationContentKind.Html),
                    Id = post.Id,
                    PublishDate = post.PostedAt,
                    Title = new TextSyndicationContent(post.Title, TextSyndicationContentKind.Plaintext),
                };

                var url = string.Concat("http://cakebuild.net", LinkHelper.GetLink(post));
                feedItem.Links.Add(new SyndicationLink(new Uri(url)));
                items.Add(feedItem);
            }

            // Create the feed.
            var feed = new SyndicationFeed(items);
            feed.Title = new TextSyndicationContent("Cake", TextSyndicationContentKind.Plaintext);
            feed.Description = new TextSyndicationContent("The Cake blog feed", TextSyndicationContentKind.Plaintext);

            // Write the feed as a response.
            // TODO: Cache this at start up?
            using (var ms = new MemoryStream())
            {
                var writer = XmlWriter.Create(ms);

                var contentType = "application/atom+xml";
                if (string.Equals("rss", format, StringComparison.InvariantCultureIgnoreCase))
                {
                    feed.SaveAsRss20(writer);
                    contentType = "application/rss+xml";
                }
                else
                {
                    feed.SaveAsAtom10(writer);
                }

                writer.Flush();
                var text = Encoding.UTF8.GetString(ms.ToArray());
                return Content(text, contentType, Encoding.UTF8);
            }
        }
开发者ID:naasking,项目名称:website,代码行数:48,代码来源:BlogController.cs

示例14: Feed

        public ActionResult Feed(string format)
        {
            var posts = _blogRepository.GetAll().OrderByDescending(b => b.PublishedDate);
            var items = new List<SyndicationItem>();

            foreach (var post in posts)
            {
                var feedItem = new SyndicationItem
                {
                    Content = new TextSyndicationContent(post.Content),
                    Id = post.Id.ToString(),
                    PublishDate = post.PublishedDate,
                    Title = new TextSyndicationContent(post.Title),
                };

                var url = String.Format(_configuration.Settings["Blog:UrlTemplate"],
                    post.PublishedDate.Year,
                    post.PublishedDate.Month.ToString().PadLeft(2, '0'),
                    post.Slug);

                feedItem.Links.Add(new SyndicationLink(new Uri(url)));

                items.Add(feedItem);
            }

            var feed = new SyndicationFeed(items);
            feed.Title = new TextSyndicationContent("Hadouken", TextSyndicationContentKind.Plaintext);
            feed.Description = new TextSyndicationContent("The Hadouken BitTorrent client blog feed",
                TextSyndicationContentKind.Plaintext);

            using (var ms = new MemoryStream())
            {
                var writer = XmlWriter.Create(ms);
                var contentType = "application/atom+xml";

                if (String.Equals("rss", format, StringComparison.InvariantCultureIgnoreCase))
                {
                    feed.SaveAsRss20(writer);
                    contentType = "application/rss+xml";
                }
                else
                {
                    feed.SaveAsAtom10(writer);
                }

                writer.Flush();

                var text = Encoding.UTF8.GetString(ms.ToArray());

                return Content(text, contentType, Encoding.UTF8);
            }
        }
开发者ID:hadouken,项目名称:peach,代码行数:52,代码来源:BlogController.cs


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