示例#1
0
        public static SyndicationFeed GetSyndycationHelper()
        {
            //Uri uri = new Uri("http://localhost/WebApplication1/");
            SyndicationFeed syndicationFeed = new SyndicationFeed(
                "AAA ラジオ",
                "",
                //uri,
                null,
                "",
                DateTime.Now);
            List <SyndicationItem> items     = new List <SyndicationItem>();
            List <Blog>            oBlogList = Blog.GetMyBlogList();

            foreach (Blog oBlog in oBlogList)
            {
                SyndicationItem oItem = new SyndicationItem(
                    oBlog.Title,
                    SyndicationContent.CreateHtmlContent(oBlog.Description),
                    new Uri(oBlog.Url),
                    oBlog.BlogId.ToString(),
                    oBlog.LastUpdated);
                SyndicationLink syndicationLink =
                    SyndicationLink.CreateMediaEnclosureLink(new Uri(oBlog.Url), "audio/mpeg", 0);
                oItem.Links.Add(syndicationLink);
                items.Add(oItem);
            }
            syndicationFeed.Items = items;
            return(syndicationFeed);
        }
示例#2
0
        public ActionResult RssFeed(long id)
        {
            NewsBusiness newsBusiness = new NewsBusiness();
            List <Common.SearchNewByGroupID_Result> model = new List <Common.SearchNewByGroupID_Result>();
            int totalRecord = 0;

            model = _newsBusiness.ListByNewsIdNewsGroup(id, ref totalRecord, 1, 10000);

            var items = new List <SyndicationItem>();

            foreach (SearchNewByGroupID_Result re in model)
            {
                var item = new SyndicationItem()
                {
                    Id          = re.Id.ToString(),
                    Title       = SyndicationContent.CreatePlaintextContent(re.Title),
                    Content     = SyndicationContent.CreateHtmlContent(re.Descriptions),
                    PublishDate = re.CreateDate
                };
                string url = Util.ReturnLinkFull(re.FriendlyUrl);
                item.Links.Add(SyndicationLink.CreateAlternateLink(new Uri(url)));//Nothing alternate about it. It is the MAIN link for the item.
                items.Add(item);
            }

            return(new RssFeed(title: "Greatness",
                               items: items,
                               contentType: "application/rss+xml",
                               description: String.Format("Sooper Dooper {0}", Guid.NewGuid())));
        }
示例#3
0
        private static SyndicationContent GetItemContent(Node node, string browseUriString)
        {
            var sb = new StringBuilder();

            sb.Append("<html><body>");

            var headerProp = (from pt in node.PropertyTypes where pt.Name == "Subtitle" && (pt.DataType == DataType.String || pt.DataType == DataType.Text) select pt).FirstOrDefault();

            if (headerProp != null)
            {
                sb.Append(node.GetProperty <string>(headerProp)).Append("<br />");
            }

            WriteTypeInfo(node, sb);

            var folder   = node as IFolder;
            var trashBag = node as TrashBag;

            //skip trash bags and non-folders
            if (trashBag == null && folder != null)
            {
                sb.Append("<br /><a href=\"").Append(browseUriString).Append("?").Append(PortalContext.ActionParamName).Append("=RSS").Append("\">view children</a>");
            }

            sb.Append("</body></html>");
            return(SyndicationContent.CreateHtmlContent(sb.ToString()));
        }
        private SyndicationItem FormatLogEntry(LogEntry entry, string repo)
        {
            var markdownParser = new Markdown(true);
            var item           = new SyndicationItem();

            item.Id              = entry.CommitHash;
            item.Title           = new TextSyndicationContent(entry.Subject);
            item.Content         = SyndicationContent.CreateHtmlContent(markdownParser.Transform(entry.Subject + "\n\n" + entry.Body));
            item.LastUpdatedTime = entry.AuthorDate;
            item.PublishDate     = entry.CommitterDate;

            item.Links.Add(SyndicationLink.CreateAlternateLink(new Uri(Url.Action("ViewCommit", "Browse", new { repo, @object = entry.CommitHash }), UriKind.Relative)));

            item.Categories.Add(new SyndicationCategory("commit"));
            if (entry.Parents.Count > 1)
            {
                item.Categories.Add(new SyndicationCategory("merge"));
            }

            item.Authors.Add(new SyndicationPerson(entry.AuthorEmail, entry.Author, null));
            if (entry.Author != entry.Committer || entry.AuthorEmail != entry.CommitterEmail)
            {
                item.Contributors.Add(new SyndicationPerson(entry.CommitterEmail, entry.Committer, null));
            }

            return(item);
        }
示例#5
0
        /// <summary>
        /// Creates the fake item with the given id and a couple of example links and author.
        /// Every item with an even ID gets a feedsync extension
        /// </summary>
        /// <param name="id">The id.</param>
        public static SyndicationItem CreateExampleItemWithId(int id)
        {
            var item = new SynchronizableArticle(String.Format("A title with ID {0}", id),
                                                 String.Empty, null,
                                                 id.ToString(),
                                                 DateTime.Now.Subtract(TimeSpan.FromDays(Random.Next(30))));

            if (id % 2 == 0)
            {
                item.FeedSync = new FeedSync
                {
                    Deleted     = false,
                    Id          = id.ToString(),
                    NoConflicts = true,
                    Updates     = 6
                }
            }
            ;

            item.Authors.Add(GetRandomAuthor());
            if (id % 3 == 0)
            {
                item.Authors.Add(GetRandomAuthor());
            }

            item.Links.Add(GetLink(1));
            item.Links.Add(GetLink(2));

            item.Content = SyndicationContent.CreateHtmlContent(
                "<html><head></head><body><p>Some test text & escaping test</p><body></html>");

            return(item);
        }
示例#6
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentEncoding = Encoding.UTF8;

            var portalContext  = PortalContext.Current;
            var serviceContext = PortalCrmConfigurationManager.CreateServiceContext();

            serviceContext.MergeOption = MergeOption.NoTracking;

            var newsRootPage = serviceContext.GetPageBySiteMarkerName(portalContext.Website, "News");

            if (newsRootPage == null)
            {
                context.Response.StatusCode  = 404;
                context.Response.ContentType = "text/plain";
                context.Response.Write("Not Found");

                return;
            }

            var feed = new SyndicationFeed(GetSyndicationItems(serviceContext, newsRootPage.ToEntityReference()))
            {
                Title       = SyndicationContent.CreatePlaintextContent(newsRootPage.GetAttributeValue <string>("adx_title") ?? newsRootPage.GetAttributeValue <string>("adx_name")),
                Description = SyndicationContent.CreateHtmlContent(newsRootPage.GetAttributeValue <string>("adx_summary") ?? string.Empty),
                BaseUri     = new Uri(context.Request.Url.GetLeftPart(UriPartial.Authority))
            };

            context.Response.ContentType = "application/atom+xml";

            using (var writer = new XmlTextWriter(context.Response.OutputStream, Encoding.UTF8))
            {
                feed.SaveAsAtom10(writer);
            }
        }
示例#7
0
        private List <SyndicationItem> GetItems(IEnumerable <UserMessage> messages)
        {
            var items = new List <SyndicationItem>();

            foreach (var message in messages)
            {
                var content = message.Text;
                if (message.ParentMessageID == null)
                {
                    content += "<br/>" + H.Anchor(
                        RootUrl + Url.Action <RssController>(c =>
                                                             c.Messages(null, message.UserMessageID)), "rss");
                }
                var uri = RootUrl +
                          Url.Action <MessageController>(c =>
                                                         c.Details(message.ParentMessageID.HasValue
                                                        ? message.ParentMessageID.Value
                                                        : message.UserMessageID, 1));
                var item =
                    new SyndicationItem(GetTitle(message),
                                        SyndicationContent.CreateHtmlContent(content),
                                        new Uri(uri),
                                        message.UserMessageID.ToString(),
                                        message.CreateDate);
                if (message.ParentMessageID == null)
                {
                    item.ElementExtensions.Add(new XElement("comments",
                                                            RootUrl + Url.Action <RssController>(c =>
                                                                                                 c.Messages(null, message.UserMessageID))));
                }
                items.Add(item);
            }
            return(items);
        }
示例#8
0
        /// <summary>
        /// Builds the syndication item from the <paramref name="galleryObject" /> and having the properties specified
        /// in <paramref name="options" />.
        /// </summary>
        /// <param name="galleryObject">The gallery object.</param>
        /// <param name="options">The options that direct the creation of HTML and URLs for a media object.</param>
        /// <returns>An instance of <see cref="SyndicationItem" />.</returns>
        private static SyndicationItem BuildSyndicationItem(IGalleryObject galleryObject, MediaObjectHtmlBuilderOptions options)
        {
            options.GalleryObject = galleryObject;
            options.DisplayType   = (galleryObject.GalleryObjectType == GalleryObjectType.External ? DisplayObjectType.External : DisplayObjectType.Optimized);

            var moBuilder = new MediaObjectHtmlBuilder(options);

            var pageUrl = moBuilder.GetPageUrl();

            var content = GetGalleryObjectContent(galleryObject, pageUrl, moBuilder);

            var item = new SyndicationItem(
                RssEncode(HtmlValidator.RemoveHtml(galleryObject.Title, false)),
                SyndicationContent.CreateHtmlContent(content),
                new Uri(pageUrl),
                galleryObject.Id.ToString(CultureInfo.InvariantCulture),
                galleryObject.DateLastModified);

            item.PublishDate = galleryObject.DateAdded;
            item.Authors.Add(new SyndicationPerson()
            {
                Name = galleryObject.CreatedByUserName
            });
            item.Categories.Add(new SyndicationCategory(galleryObject.GalleryObjectType.ToString()));

            return(item);
        }
        public SyndicationFeed BuildFeed(IEnumerable <JobResponse> jobs, Uri requestUri, string referrer, bool formatIsHtml)
        {
            var feed = new SyndicationFeed
            {
                Title = new TextSyndicationContent(_mandatorResponse.Name)
            };
            var items = new List <SyndicationItem>();

            foreach (var job in jobs)
            {
                var url = _urlBuilder.GetAbsolutJobUrl(job.Id, requestUri, referrer);

                var item = new SyndicationItem
                {
                    Title   = SyndicationContent.CreatePlaintextContent(job.Title),
                    Content = SyndicationContent.CreateHtmlContent(BuildContent(job, requestUri, referrer, formatIsHtml))
                };
                item.Authors.Add(new SyndicationPerson(job.UserEmail, job.UserFullName, null));
                item.Id = url;
                item.AddPermalink(new Uri(url));
                item.LastUpdatedTime = job.OnlineDateCorrected;
                items.Add(item);
            }

            feed.Items = items;
            return(feed);
        }
示例#10
0
        public ActionResult Rss()
        {
            List <SyndicationItem> items1 = new List <SyndicationItem>();
            List <Models.MyBook>   items2 = ns.GetNewBooks();

            for (int i = 0; i < 9; i++)
            {
                string imgURL = "<img src=\"";
                imgURL += "http://localhost/Image/Sach/" + items2[i].AnhBia + "\"style=\"width:180px; height:230px; margin-top:9px;\"/><br>";
                SyndicationItem item = new SyndicationItem()
                {
                    Id    = items2[i].MaSach.ToString(),
                    Title = SyndicationContent.CreatePlaintextContent(String.Format("{0}", items2[i].TenSach)),

                    Content = SyndicationContent.CreateHtmlContent(String.Format("{0} Giá bán: {1} <br>", imgURL, items2[i].GiaBan.ToString())),
                };
                string mylink = "http://localhost/Product/Product/" + ns.Encode("id=" + items2[i].MaSach.ToString());
                item.Links.Add(SyndicationLink.CreateAlternateLink(new Uri(mylink)));//link to item
                items1.Add(item);
            }
            var feed = new SyndicationFeed("Usagi's Store", "Cửa hàng sách Usagi", new Uri("http://localhost"), items1)
            {
                Copyright = new TextSyndicationContent("© 2015 - Usagi's Store"),
                Language  = "vi-VN"
            };

            Response.ContentType = "text/xml";
            return(new FeedResult(new Rss20FeedFormatter(feed)));
        }
示例#11
0
        public SyndicationFeedFormatter GetProcesses(string format)
        {
            IEnumerable <Process> processes = new List <Process>(Process.GetProcesses());

            //SyndicationFeed also has convenience constructors
            //that take in common elements like Title and Content.
            SyndicationFeed f = new SyndicationFeed();


            f.LastUpdatedTime = DateTimeOffset.Now;
            f.Title           = SyndicationContent.CreatePlaintextContent("Currently running processes");
            f.Links.Add(SyndicationLink.CreateSelfLink(OperationContext.Current.IncomingMessageHeaders.To));

            f.Items = from p in processes
                      select new SyndicationItem()
            {
                LastUpdatedTime = DateTimeOffset.Now,
                Title           = SyndicationContent.CreatePlaintextContent(p.ProcessName),
                Summary         = SyndicationContent.CreateHtmlContent(String.Format("<b>{0}</b>", p.MainWindowTitle)),
                Content         = SyndicationContent.CreateXmlContent(new ProcessData(p))
            };


            // Choose a formatter according to the query string passed.
            if (format == "rss")
            {
                return(new Rss20FeedFormatter(f));
            }
            else
            {
                return(new Atom10FeedFormatter(f));
            }
        }
示例#12
0
        public virtual ActionResult CommentFeed()
        {
            var comments = Repository.Find(new GetCommentsQuery(), 0, 20);

            var baseUri = Request.GetOriginalUrl();
            var items   =
                from e in comments
                let itemUri = new Uri(baseUri, Url.Action("Page", "Wiki", new { page = e.Entry.Name }) + "#comment-" + e.Id)
                              select new SyndicationItem
            {
                Id              = itemUri.ToString(),
                Title           = SyndicationContent.CreatePlaintextContent(e.AuthorName + " on " + e.Entry.Title),
                Summary         = SyndicationContent.CreateHtmlContent(Renderer.RenderUntrusted(e.Body, Formats.Markdown, CreateHelper())),
                Content         = SyndicationContent.CreateHtmlContent(Renderer.RenderUntrusted(e.Body, Formats.Markdown, CreateHelper())),
                LastUpdatedTime = e.Posted,
                PublishDate     = e.Posted,
                Links           =
                {
                    new SyndicationLink(itemUri)
                },
                Authors =
                {
                    new SyndicationPerson {
                        Name = e.AuthorName, Uri = e.AuthorUrl
                    }
                },
            };

            return(FeedResult(items.ToList()));
        }
示例#13
0
        public static async Task <SyndicationFeed> BuildSyndication(this IBlogService service, string baseAddress)
        {
            ClientUrlGenerator generator = new ClientUrlGenerator
            {
                BaseAddress = baseAddress
            };
            BlogOptions blogOptions = await service.GetOptions();

            SyndicationFeed   feed   = new SyndicationFeed(blogOptions.Name, blogOptions.Description, new Uri(baseAddress));
            SyndicationPerson author = new SyndicationPerson("", blogOptions.Onwer, baseAddress);

            feed.Authors.Add(author);
            Dictionary <string, SyndicationCategory> categoryMap = new Dictionary <string, SyndicationCategory>();

            {
                /*var cates = await BlogService.CategoryService.GetCategories(await BlogService.CategoryService.All());
                 * foreach (var p in cates)
                 * {
                 *  var cate = new SyndicationCategory(p.Name);
                 *  categoryMap.Add(p.Id, cate);
                 *  feed.Categories.Add(cate);
                 * }*/
            }
            {
                var posts = await service.PostService.GetPosts(await service.PostService.All());

                List <SyndicationItem> items = new List <SyndicationItem>();
                foreach (var p in posts)
                {
                    if (p is null)
                    {
                        continue;
                    }
                    var s = new SyndicationItem(p.Title,
                                                SyndicationContent.CreateHtmlContent(Markdown.ToHtml(p.Content.Raw, Pipeline)),
                                                new Uri(generator.Post(p.Id)), p.Id, p.ModificationTime);
                    s.Authors.Add(author);

                    string summary;
                    if (await service.PostService.Protector.IsProtected(p.Content))
                    {
                        summary = "Protected Post";
                    }
                    else
                    {
                        summary = Markdown.ToPlainText(p.Content.Raw, Pipeline);
                    }
                    s.Summary = SyndicationContent.CreatePlaintextContent(summary.Length <= 100 ? summary : summary.Substring(0, 100));
                    s.Categories.Add(new SyndicationCategory(p.Category.ToString()));

                    /*if (categoryMap.TryGetValue(p.CategoryId, out var cate))
                     *  s.Categories.Add(cate);*/
                    s.PublishDate = p.CreationTime;
                    items.Add(s);
                }
                feed.Items = items.AsEnumerable();
            }

            return(feed);
        }
            private async Task <IEnumerable <SyndicationItem> > GetItemsAsync(GetSyndicationFeedQuery request, CancellationToken cancellationToken)
            {
                var posts = await _uow.Posts.GetPublishedAsync(25, cancellationToken);

                var items = new List <SyndicationItem>();

                foreach (var post in posts.AsQueryable().Select(p => _postUrlHelper.ReplaceUrlFormatWithBaseUrl(p)))
                {
                    var absoluteUrl = new Uri(request.BaseUri, $"{request.PostBasePath}/{post.Slug}");
                    var content     = SyndicationContent.CreateHtmlContent(Markdig.Markdown.ToHtml(post.Content));

                    var item = new SyndicationItem(post.Title, content, absoluteUrl, absoluteUrl.ToString(), post.Modified)
                    {
                        PublishDate = post.Published.Value
                    };

                    if (!string.IsNullOrWhiteSpace(post.Description))
                    {
                        item.Summary = new TextSyndicationContent(post.Description);
                    }

                    if (!string.IsNullOrWhiteSpace(post.Categories))
                    {
                        foreach (var category in post.Categories.Split(','))
                        {
                            item.Categories.Add(new SyndicationCategory(category));
                        }
                    }

                    item.Authors.Add(new SyndicationPerson("", post.Author.DisplayName, request.BaseUri.ToString()));
                    items.Add(item);
                }

                return(items);
            }
示例#15
0
        protected override void Run()
        {
            base.Run();
            if (IsFirstRun)
            {
                if (database == null)
                {
                    waitToken.WaitHandle.WaitOne(10000); //WaitFor 10 seconds
                }
                if (database == null)
                {
                    Console.WriteLine("No DiffDatabase connected,Service Terminate");
                }
            }
            DateTime updateTime = DateTime.Now;

            //Rebuild RssData
            try
            {
                var iter = (from p in database.Table <DiffData>()
                            orderby p.OutputTime descending
                            select p).Take(50);
                List <SyndicationItem> item = new List <SyndicationItem>();
                bool isFirst = true;
                foreach (var val in iter)
                {
                    if (isFirst)
                    {
                        isFirst    = false;
                        updateTime = val.OutputTime;
                    }
                    var             destTime = TimeZoneInfo.ConvertTime(val.OutputTime, _timeZone);
                    SyndicationItem sitem    = new SyndicationItem()
                    {
                        Title = new TextSyndicationContent(val.Summary),
                        //Summary = SyndicationContent.CreatePlaintextContent(val.Summary),
                        Content         = SyndicationContent.CreateHtmlContent(val.Content),
                        PublishDate     = destTime,
                        LastUpdatedTime = destTime,
                        Links           = { new SyndicationLink(new Uri(val.RelatedAddress)) },
                        Id = GetStringHash(val.Summary)
                    };
                    item.Add(sitem);
                }
                feed.Items           = item;
                feed.LastUpdatedTime = updateTime;
                //Console.WriteLine("RssData Updated");
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                string outputstr   = e.ToString() + "\n";
                string anotherPart = "模块RssTerminal发生了异常!\n"
                                     + e.StackTrace
                                     + "\n"
                                     + e.InnerException;
                File.AppendAllText("ErrorDump.txt", outputstr + anotherPart);
            }
        }
        public void CreateHtmlContent_Invoke_ReturnsExpected(string content)
        {
            TextSyndicationContent syndicationContent = SyndicationContent.CreateHtmlContent(content);

            Assert.Empty(syndicationContent.AttributeExtensions);
            Assert.Equal(content, syndicationContent.Text);
            Assert.Equal("html", syndicationContent.Type);
        }
示例#17
0
 internal static SyndicationItem CreateSyndicationItem(IEntry entry, string uriString)
 {
     return(new SyndicationItem(entry.SeoTitle,
                                SyndicationContent.
                                CreateHtmlContent(entry.EntryBody),
                                new Uri(uriString),
                                string.Format("item-id-{0}", entry.Id),
                                entry.CreatedAt));
 }
示例#18
0
        private static SyndicationContent GetSyndicationContent(string content, string contentType)
        {
            if (content.IsNullOrEmpty() || contentType.ToLowerInvariant() == PublicationContentTypes.Text)
            {
                return(SyndicationContent.CreatePlaintextContent(content ?? string.Empty));
            }

            return(SyndicationContent.CreateHtmlContent(content));
        }
示例#19
0
        private SyndicationItem TransformPost(PostEntry entry)
        {
            entry = RenderEntry(entry);
            SyndicationItem item = new SyndicationItem();

            item.Id      = entry.Name;
            item.Title   = SyndicationContent.CreatePlaintextContent(entry.Title);
            item.Content = SyndicationContent.CreateHtmlContent(Transformer.Transform(entry.Content));
            item.AddPermalink(new Uri("http://otakustay.com/" + entry.Name + "/"));
            item.PublishDate     = new DateTimeOffset(entry.PostDate);
            item.LastUpdatedTime = new DateTimeOffset(entry.UpdateDate);
            item.Authors.Add(Author.Clone());
            return(item);
        }
示例#20
0
        public virtual ActionResult Feed()
        {
            var settings = Settings.GetSettings <FunnelWebSettings>();

            var entries = Repository.Find(new GetFullEntriesQuery(entryStatus: EntryStatus.PublicBlog), 0, 20);

            var baseUri = Request.GetOriginalUrl();

            var items =
                from e in entries
                let itemUri = new Uri(baseUri, Url.Action("Page", "Wiki", new { page = e.Name }))
                              let viaFeedUri = new Uri(baseUri, "/via-feed" + Url.Action("Page", "Wiki", new { page = e.Name }))
                                               orderby e.Published descending
                                               let content = SyndicationContent.CreateHtmlContent(BuildFeedItemBody(itemUri, viaFeedUri, e))
                                                             select new
            {
                Item = new SyndicationItem
                {
                    Id              = itemUri.ToString(),
                    Title           = SyndicationContent.CreatePlaintextContent(e.Title),
                    Summary         = content,
                    Content         = content,
                    LastUpdatedTime = TimeZoneInfo.ConvertTimeFromUtc(e.Revised, TimeZoneInfo.Local),
                    PublishDate     = e.Published,
                    Links           =
                    {
                        new SyndicationLink(itemUri)
                    },
                    Authors =
                    {
                        new SyndicationPerson {
                            Name = settings.Author
                        }
                    },
                },
                Keywords = e.TagsCommaSeparated.Split(',')
            };

            return(FeedResult(items.Select(i =>
            {
                var item = i.Item;
                foreach (var k in i.Keywords)
                {
                    item.Categories.Add(new SyndicationCategory(k.Trim()));
                }

                return item;
            }).ToList()));
        }
示例#21
0
 private static List<SyndicationItem> MapToSyndicationItem(IEnumerable<FeedItemViewModel> rssItems)
 {
     var results = new List<SyndicationItem>();
     foreach (var item in rssItems)
     {
         var uri = new Uri(item.Url);
         var feedItem = new SyndicationItem(item.Title.CorrectRtl(),
             SyndicationContent.CreateHtmlContent(item.Content.CorrectRtlBody()), uri, item.Url.SHA1(),
             item.LastUpdatedTime
             ) { PublishDate = item.PublishDate };
         feedItem.Authors.Add(new SyndicationPerson(item.AuthorName, item.AuthorName, uri.Host));
         results.Add(feedItem);
     }
     return results;
 }
        public SyndicationFeed CreateFeed(IPortalContext portal, HttpContext context, string selfRouteName, int maximumItems)
        {
            if (portal == null)
            {
                throw new ArgumentNullException("portal");
            }

            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            var blog = _dataAdapter.Select();

            if (blog == null)
            {
                throw new InvalidOperationException("Blog not found.");
            }

            var posts = _dataAdapter.SelectPosts(0, maximumItems).ToArray();

            var feedLastUpdatedTime = posts.Any() ? new DateTimeOffset(posts.First().PublishDate) : DateTimeOffset.UtcNow;
            var blogHtmlUri         = new Uri(context.Request.Url, blog.ApplicationPath.AbsolutePath);

            var feed = new SyndicationFeed(posts.Select(p => GetFeedItem(p, context)))
            {
                Id              = "uuid:{0};{1}".FormatWith(blog.Id, feedLastUpdatedTime.Ticks),
                Title           = SyndicationContent.CreatePlaintextContent(blog.Title),
                Description     = SyndicationContent.CreateHtmlContent(blog.Summary.ToString()),
                LastUpdatedTime = feedLastUpdatedTime,
                BaseUri         = new Uri(context.Request.Url, "/")
            };

            var selfPath = RouteTable.Routes.GetVirtualPath(context.Request.RequestContext, selfRouteName, new RouteValueDictionary
            {
                { "__portalScopeId__", portal.Website.Id },
                { "id", blog.Id }
            });

            if (selfPath != null)
            {
                feed.Links.Add(SyndicationLink.CreateSelfLink(new Uri(context.Request.Url, ApplicationPath.FromPartialPath(selfPath.VirtualPath).AbsolutePath), "application/atom+xml"));
            }

            feed.Links.Add(SyndicationLink.CreateAlternateLink(blogHtmlUri, "text/html"));

            return(feed);
        }
示例#23
0
        /// <summary>
        /// Build the feed using the IPublishable items.
        /// </summary>
        /// <param name="feedAuthor">The author of the feed.</param>
        /// <param name="feedTitle">The title of the feed</param>
        /// <param name="feedDescription">The description of the feed.</param>
        /// <param name="feedUrl">The url of the feed</param>
        /// <param name="posts">The feed entries.</param>
        public static SyndicationFeed Build(string feedAuthor, string feedTitle, string feedDescription, string feedUrl, IList <IPublishable> posts)
        {
            Uri             feedUri = new Uri(feedUrl);
            SyndicationFeed feed    = new SyndicationFeed(feedTitle, feedDescription, feedUri, feedTitle, DateTime.Now);

            feed.Authors.Add(new SyndicationPerson(string.Empty, feedAuthor, string.Empty));
            IList <SyndicationItem> items = new List <SyndicationItem>();

            foreach (var post in posts)
            {
                SyndicationItem item = new SyndicationItem(post.Title, SyndicationContent.CreateHtmlContent(post.Description), null, post.GuidId, post.UpdateDate);
                item.Authors.Add(new SyndicationPerson(string.Empty, post.Author, string.Empty));
                items.Add(item);
            }
            feed.Items = items;
            return(feed);
        }
示例#24
0
        //public ActionResult TestRssFeed()
        //{
        //	var items = new List<SyndicationItem>();
        //	for (int i = 0; i < 20; i++)
        //	{
        //		var item = new SyndicationItem()
        //		{
        //			Id = Guid.NewGuid().ToString(),
        //			Title = SyndicationContent.CreatePlaintextContent(String.Format("My Title {0}", Guid.NewGuid())),
        //			Content = SyndicationContent.CreateHtmlContent("Content The stuff."),
        //			PublishDate = DateTime.Now
        //		};
        //		item.Links.Add(SyndicationLink.CreateAlternateLink(new Uri("http://www.google.com")));//Nothing alternate about it. It is the MAIN link for the item.
        //		items.Add(item);
        //	}


        //	return new RssFeed(title: "Test rss",
        //					   items: items,
        //					   contentType: "application/rss+xml",
        //					   description: String.Format("rss de test  {0}", Guid.NewGuid()));

        //}

        public ActionResult RssFeed()
        {
            var fundInvestments = InvestmentStream.GetNewFundInvestmentList();
            var news            = new List <SyndicationItem>();

            foreach (var fundInvestment in fundInvestments)
            {
                foreach (var investment in fundInvestment.Investments)
                {
                    SyndicationItem newInvestment = new SyndicationItem()
                    {
                        Title       = SyndicationContent.CreatePlaintextContent(string.Format("{0} {1} {2}", fundInvestment.Fund.Name, Constants.INVEST_IN, investment.Startup.Name)),
                        Content     = SyndicationContent.CreateHtmlContent(investment.Description),
                        PublishDate = DateTime.Parse(investment.DateActivityFeed),
                    };
                    newInvestment.Links.Add(SyndicationLink.CreateAlternateLink(new Uri(investment.Startup.Url)));
                    news.Add(newInvestment);
                }
            }

            var fundIncubations = IncubationStream.GetNewFundIncubationList();

            foreach (var fundIncubation in fundIncubations)
            {
                foreach (var incubation in fundIncubation.Incubations)
                {
                    SyndicationItem newInvestment = new SyndicationItem()
                    {
                        Title       = SyndicationContent.CreatePlaintextContent(string.Format("{0} {1} {2}", fundIncubation.Fund.Name, Constants.INCUBATE, incubation.Startup.Name)),
                        PublishDate = DateTime.Parse(incubation.DateActivityFeed),
                    };
                    newInvestment.Links.Add(SyndicationLink.CreateAlternateLink(new Uri(incubation.Startup.Url)));
                    news.Add(newInvestment);
                }
            }

            ExecutionUpdater.UpdateRss();

            Log.Info("RssFeed", "refresh new feeds");

            return(new RssFeed(title: "Angel list feed",
                               items: news,
                               contentType: "application/rss+xml",
                               description: String.Format("Thibaut Cantet Angel list  {0}", Guid.NewGuid())));
        }
示例#25
0
        private static SyndicationItem GetSyndicationItem(OrganizationServiceContext serviceContext, Entity newsItemPage)
        {
            var displayDate = newsItemPage.GetAttributeValue <DateTime?>("adx_displaydate");

            var item = new SyndicationItem(
                newsItemPage.GetAttributeValue <string>("adx_title") ?? newsItemPage.GetAttributeValue <string>("adx_name"),
                SyndicationContent.CreateHtmlContent(newsItemPage.GetAttributeValue <string>("adx_copy") ?? string.Empty),
                new Uri(new UrlBuilder(serviceContext.GetUrl(newsItemPage))),
                "uuid:{0}".FormatWith(newsItemPage.Id),
                displayDate.GetValueOrDefault(newsItemPage.GetAttributeValue <DateTime?>("modifiedon").GetValueOrDefault(DateTime.UtcNow)));

            if (displayDate != null)
            {
                item.PublishDate = displayDate.Value;
            }

            return(item);
        }
示例#26
0
        public async Task <ActionResult> GetFeed()
        {
            SyndicationFeed   feed   = new SyndicationFeed(BlogSettings.Name, BlogSettings.Description, new Uri(BaseAddress));
            SyndicationPerson author = new SyndicationPerson("", BlogSettings.Onwer, BaseAddress);

            feed.Authors.Add(author);
            Dictionary <string, SyndicationCategory> categoryMap = new Dictionary <string, SyndicationCategory>();
            {
                var cates = await BlogService.CategoryService.GetCategories(await BlogService.CategoryService.All());

                foreach (var p in cates)
                {
                    var cate = new SyndicationCategory(p.Name);
                    categoryMap.Add(p.Id, cate);
                    feed.Categories.Add(cate);
                }
            }
            {
                var posts = await BlogService.PostService.GetPosts(await BlogService.PostService.All());

                List <SyndicationItem> items = new List <SyndicationItem>();
                foreach (var p in posts)
                {
                    var s = new SyndicationItem(p.Title,
                                                SyndicationContent.CreateHtmlContent(Markdown.ToHtml(p.Content.Raw, Pipeline)),
                                                new Uri($"{BaseAddress}/posts/{p.Id}"), p.Id, p.ModificationTime);
                    s.Authors.Add(author);
                    string summary = Markdown.ToPlainText(p.Content.Raw, Pipeline);
                    s.Summary = SyndicationContent.CreatePlaintextContent(summary.Length <= 100 ? summary : summary.Substring(0, 100));
                    if (categoryMap.TryGetValue(p.CategoryId, out var cate))
                    {
                        s.Categories.Add(cate);
                    }
                    s.PublishDate = p.CreationTime;
                    items.Add(s);
                }
                feed.Items = items.AsEnumerable();
            }
            StringBuilder sb = new StringBuilder();

            using (var writer = XmlWriter.Create(sb))
                feed.GetAtom10Formatter().WriteTo(writer);
            return(Content(sb.ToString(), "text/xml"));
        }
        private static SyndicationContent GetSyndicationContent(IPublication publication)
        {
            if (string.IsNullOrEmpty(publication.Content))
            {
                return(SyndicationContent.CreatePlaintextContent(string.Empty));
            }
            switch (publication.ContentType)
            {
            case PublicationContentTypes.Text:
                return(SyndicationContent.CreatePlaintextContent(publication.Content));

            case PublicationContentTypes.HTML:
                return(SyndicationContent.CreateHtmlContent(publication.Content));

            default:
                Throw.NotSupported(string.Format("{0} is not a supported content type.", publication.ContentType));
                return(null);
            }
        }
示例#28
0
        public async Task <IActionResult> RssAsync()
        {
            var objGeneralSettings = await _GeneralSettingsService.GetGeneralSettingsAsync();

            var feed = new SyndicationFeed(objGeneralSettings.ApplicationName, objGeneralSettings.ApplicationName, new Uri(GetBaseUrl()), "RSSUrl", DateTime.Now);

            feed.Copyright = new TextSyndicationContent($"{DateTime.Now.Year} {objGeneralSettings.ApplicationName}");
            var items = new List <SyndicationItem>();

            var postings = _BlazorBlogsContext.Blogs.OrderByDescending(x => x.BlogDate);

            foreach (var item in postings)
            {
                string BlogURL     = $"{GetBaseUrl()}/ViewBlogPost/{item.BlogId}";
                var    postUrl     = Url.Action("Article", "Blog", new { id = BlogURL }, HttpContext.Request.Scheme);
                var    title       = item.BlogTitle;
                var    description = SyndicationContent.CreateHtmlContent(item.BlogSummary.Replace("  ", " "));
                items.Add(new SyndicationItem(title, description, new Uri(BlogURL), item.BlogId.ToString(), item.BlogDate));
            }

            feed.Items = items;

            var settings = new XmlWriterSettings
            {
                Encoding            = Encoding.UTF8,
                NewLineHandling     = NewLineHandling.Entitize,
                NewLineOnAttributes = true,
                Indent = true
            };

            using (var stream = new MemoryStream())
            {
                using (var xmlWriter = XmlWriter.Create(stream, settings))
                {
                    var rssFormatter = new Rss20FeedFormatter(feed, false);
                    rssFormatter.WriteTo(xmlWriter);
                    xmlWriter.Flush();
                }

                return(File(stream.ToArray(), "application/rss+xml; charset=utf-8"));
            }
        }
示例#29
0
        private async Task <SyndicationItem> GetItem(FeedIndex index)
        {
            string text = "";

            if (config.EnableContent)
            {
                string filepath = ConfigReader.GetFileContentURL(
                    config.ContentFileRoot,
                    index.Name
                    );
                HttpResponseMessage resp = await httpClient.GetAsync(filepath);

                if (resp.IsSuccessStatusCode)
                {
                    text = await resp.Content.ReadAsStringAsync();
                }
            }

            string          blogpath = config.BlogUrl;
            string          link     = string.Format("{0}/{1}", blogpath, index.Name);
            var             pubDate  = DateTime.Parse(index.Date).ToUniversalTime();
            SyndicationItem item     =
                new SyndicationItem(
                    index.Title,
                    text,
                    new Uri(link),
                    link,
                    pubDate
                    );

            if (config.EnableContent)
            {
                string substr = text.Length > MAX_CONTENT_LENGTH
                    ? text.Substring(0, MAX_CONTENT_LENGTH)
                    : text;

                item.Content = SyndicationContent.CreateHtmlContent(substr);
            }
            item.PublishDate = pubDate;
            return(item);
        }
示例#30
0
        public SyndicationFeed BuildFeed(string websiteUrl, Func <CmsPage, string> generateEntryUrl)
        {
            string rssFeedTitle = settingData.Get(Constant.Settings.SiteLogo).Value;
            string rssFeedDescr = settingData.Get(Constant.Settings.SiteSubLogo).Value;

            IEnumerable <CmsPage>  entries = pageData.LoadLast(10);
            List <SyndicationItem> items   =
                entries.Select(entry => new SyndicationItem(entry.SeoTitle,
                                                            SyndicationContent.
                                                            CreateHtmlContent(entry.PageContent),
                                                            new Uri(generateEntryUrl(entry)),
                                                            string.Format("item-id-{0}", entry.Id),
                                                            entry.CreatedAt)).ToList();

            return(new SyndicationFeed(rssFeedTitle,
                                       rssFeedDescr,
                                       new Uri(websiteUrl),
                                       "syndicationID",
                                       DateTime.Now,
                                       items));
        }