Ejemplo n.º 1
0
        private SyndicationItem CreateItemFromReference(ContentReference contentReference)
        {
            var content         = _contentLoader.Get <IContent>(contentReference);
            var changeTrackable = content as IChangeTrackable;

            if (changeTrackable == null)
            {
                return(null);
            }

            var mimeType    = GetMimeType(content);
            var url         = GetItemUrl(content);
            var publishDate = _feedPage.OrderByCreatedDate ? changeTrackable.Created : changeTrackable.Saved;
            var summary     = GetSummary(content, _feedPage.PropertyContainingSummary);

            var item = new SyndicationItem
            {
                Id              = content.ContentLink.ID.ToString(),
                Title           = new TextSyndicationContent(content.Name),
                Summary         = new TextSyndicationContent(summary),
                PublishDate     = publishDate,
                LastUpdatedTime = publishDate,
                Content         = new UrlSyndicationContent(url, mimeType),
            };

            item.AddPermalink(url);
            item.Authors.Add(new SyndicationPerson(string.Empty, changeTrackable.ChangedBy, string.Empty));

            return(item);
        }
        private SyndicationItem BuildSyndicationItem(AnnouncementInfo ann)
        {
            var item = new SyndicationItem();
            if (ann.PublishDate != null)
                item.PublishDate = DateTime.SpecifyKind(ann.PublishDate.Value,DateTimeKind.Utc);

            item.Content = new TextSyndicationContent(ann.Description, TextSyndicationContentKind.Html);
            item.LastUpdatedTime = DateTime.SpecifyKind(ann.LastModifiedOnDate, DateTimeKind.Utc);
            item.Title = new TextSyndicationContent(ann.Title);
            var p = ann.Permalink;
            if (p != null)
            {
                //item.BaseUri = new Uri(p);
                item.AddPermalink(new Uri(p));
            }

            if (ann.URL != "")
            {
                item.Links.Add(new SyndicationLink(new Uri(ann.URL)));
                item.Id = ann.URL;
            }

            item.Authors.Add(new SyndicationPerson { Name = ann.LastModifiedByUserID.ToString(CultureInfo.InvariantCulture) });
            return item;
        }
        private SyndicationItem CreateSyndicationItem(IContent content)
        {
            var changeTrackable = content as IChangeTrackable;
            var changed         = DateTime.Now;
            var changedby       = string.Empty;

            if (changeTrackable != null)
            {
                changed   = changeTrackable.Saved;
                changedby = changeTrackable.ChangedBy;
            }

            var item = new SyndicationItem
            {
                Title       = new TextSyndicationContent(content.Name),
                Summary     = new TextSyndicationContent(FeedDescriptionProvider.ItemDescripton(content)),
                PublishDate = changed,
            };

            foreach (var contentCategory in ContentCategoryLoader.GetContentCategories(content))
            {
                item.Categories.Add(new SyndicationCategory(contentCategory));
            }

            var mimeType = GetMimeType(content);
            Uri url      = GetItemUrl(content);

            item.Content = new UrlSyndicationContent(url, mimeType);
            item.AddPermalink(url);
            item.Authors.Add(new SyndicationPerson(string.Empty, changedby, string.Empty));

            return(item);
        }
Ejemplo n.º 4
0
        public void Clone()
        {
            SyndicationItem item = new SyndicationItem();

            item.AddPermalink(new Uri("http://mono-project.com/index.rss.20071210"));
            item.Id      = Guid.NewGuid().ToString();
            item.BaseUri = new Uri("http://mono-project.com");
            item.Authors.Add(new SyndicationPerson("*****@*****.**"));
            item.SourceFeed       = new SyndicationFeed();
            item.SourceFeed.Items = new SyndicationItem [] { new SyndicationItem() };

            SyndicationItem clone = item.Clone();

            Assert.AreEqual(1, clone.Links.Count, "#1");
            Assert.AreEqual(item.Id, clone.Id, "#2");              // hmm ...
            Assert.AreEqual("http://mono-project.com/", clone.BaseUri.ToString(), "#3");

            // LAMESPEC: .NET fails to clone it
            // Assert.IsFalse (Object.ReferenceEquals (item.BaseUri, clone.BaseUri), "#4"); // should not be just a shallow copy

            Assert.IsNull(clone.Title, "#5");
            Assert.IsNotNull(clone.SourceFeed, "#6");
            Assert.IsFalse(Object.ReferenceEquals(item.SourceFeed, clone.SourceFeed), "#7");               // ... not just a shallow copy??
            // items in the SourceFeed are not cloned, but Items property is not null
            Assert.IsNotNull(clone.SourceFeed.Items, "#8-1");
            Assert.IsFalse(clone.SourceFeed.Items.GetEnumerator().MoveNext(), "#8-2");
            Assert.AreEqual(1, clone.Authors.Count, "#9");
            SyndicationPerson person = clone.Authors [0];

            Assert.IsFalse(Object.ReferenceEquals(item.Authors [0], person), "#10");               // should not be just a shallow copy
            Assert.AreEqual("*****@*****.**", person.Email, "#11");
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Creates an RSS syndication feed from the list of <see cref="WorkItemSummary"/> and sets the title (which also includes the project name and filter).
        /// </summary>
        protected SyndicationFeed GetRssFeed(IEnumerable <WorkItemSummary> list, string title)
        {
            SyndicationFeed feed = new SyndicationFeed();

            title      = string.Format("{0} ({1} - {2})", title, UserContext.Current.CurrentProject.Name, ViewData["CurrentFilter"]);
            feed.Title = new TextSyndicationContent(title);

            List <SyndicationItem> items = new List <SyndicationItem>();
            Markdown markdown            = new Markdown();

            foreach (WorkItemSummary summary in list)
            {
                SyndicationItem item = new SyndicationItem();
                item.Title       = new TextSyndicationContent(string.Format("#{0} - {1}", summary.Id, summary.Title));
                item.PublishDate = summary.CreatedDate;
                item.Summary     = new TextSyndicationContent(markdown.Transform(summary.Description));
                item.Content     = new TextSyndicationContent(markdown.Transform(summary.Description));
                item.Authors.Add(new SyndicationPerson(summary.CreatedBy));

                string url = string.Format("{0}/{1}/view/{2}", SpruceSection.Current.SiteUrl, RouteData.Values["Controller"], summary.Id);
                item.AddPermalink(new Uri(url));

                items.Add(item);
            }

            feed.Items = items;
            return(feed);
        }
Ejemplo n.º 6
0
        private SyndicationItem CreateSyndicationItem(IContent content)
        {
            var changeTrackable = content as IChangeTrackable;
            var changed         = DateTime.Now;
            var changedby       = string.Empty;

            if (changeTrackable != null)
            {
                changed   = changeTrackable.Saved;
                changedby = changeTrackable.ChangedBy;
            }

            var item = new SyndicationItem
            {
                Id              = content.ContentLink.ID.ToString(),
                Title           = new TextSyndicationContent(content.Name),
                Summary         = new TextSyndicationContent(FeedInformationHandler.SetItemDescription(content)),
                PublishDate     = changed,
                LastUpdatedTime = changed,
            };

            var mimeType = GetMimeType(content);
            Uri url      = GetItemUrl(content);

            item.Content = new UrlSyndicationContent(url, mimeType);
            item.AddPermalink(url);
            item.Authors.Add(new SyndicationPerson(string.Empty, changedby, string.Empty));

            return(item);
        }
Ejemplo n.º 7
0
        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);
        }
Ejemplo n.º 8
0
        public static void Snippet36()
        {
            // <Snippet36>
            SyndicationItem item = new SyndicationItem("Item Title", "Item Content", new Uri("http://Item/Alternate/Link"), "itemID", DateTimeOffset.Now);

            item.AddPermalink(new Uri("http://contoso/links/mylink"));
            // </Snippet36>
        }
Ejemplo n.º 9
0
        private SyndicationFeed GetFeed()
        {
            var feed = new SyndicationFeed("", "", new Uri(_appConfig.BlogAddress))
            {
                Title     = new TextSyndicationContent(BlogConstant.BlogName, TextSyndicationContentKind.Plaintext),
                Copyright = new TextSyndicationContent(
                    $"Copyright {DateTime.UtcNow.Year} {BlogConstant.AuthorChineseName}",
                    TextSyndicationContentKind.Plaintext),
                Description =
                    new TextSyndicationContent(BlogConstant.BlogDescription, TextSyndicationContentKind.Plaintext),
                Generator       = "ASP.NET CORE",
                BaseUri         = new Uri(_appConfig.BlogAddress),
                Id              = _appConfig.BlogAddress,
                Language        = "zh-cn",
                LastUpdatedTime = DateTimeOffset.UtcNow,
                TimeToLive      = TimeSpan.FromHours(1)
            };

            var sp = new SyndicationPerson(BlogConstant.AuthorEmail, BlogConstant.AuthorChineseName, _appConfig.BlogAddress);

            feed.Authors.Add(sp);
            feed.Contributors.Add(sp);

            var items = new List <SyndicationItem>();
            var posts = _blogService.GetPosts().Where(p => p.IsReallyPublic).OrderByDescending(p => p.CreationTimeUtc)
                        .ToList();

            foreach (var blogPost in posts)
            {
                var item = new SyndicationItem
                {
                    Title           = new TextSyndicationContent(blogPost.Title, TextSyndicationContentKind.Plaintext),
                    Copyright       = feed.Copyright,
                    Id              = blogPost.FullUrlWithBaseAddress,
                    PublishDate     = new DateTimeOffset(blogPost.CreationTimeUtc, TimeSpan.Zero),
                    Summary         = new TextSyndicationContent(blogPost.Excerpt, TextSyndicationContentKind.Html),
                    Content         = new TextSyndicationContent(blogPost.HtmlContent, TextSyndicationContentKind.Html),
                    LastUpdatedTime = new DateTimeOffset(blogPost.LastUpdateTimeUtc, TimeSpan.Zero)
                };

                item.AddPermalink(new Uri(blogPost.FullUrlWithBaseAddress));
                item.Authors.Add(sp);
                item.Contributors.Add(sp);

                foreach (var cat in blogPost.CategoryNames)
                {
                    item.Categories.Add(new SyndicationCategory(cat));
                }

                items.Add(item);
            }

            feed.Items = items;

            return(feed);
        }
Ejemplo n.º 10
0
        public void AddPermalink()
        {
            SyndicationItem item = new SyndicationItem();

            Assert.AreEqual(0, item.Links.Count, "#1");
            item.AddPermalink(new Uri("http://mono-project.com/index.rss.20071210"));
            Assert.AreEqual(1, item.Links.Count, "#2");
            SyndicationLink link = item.Links [0];

            Assert.AreEqual("http://mono-project.com/index.rss.20071210", link.Uri.ToString(), "#3");
            Assert.AreEqual("alternate", link.RelationshipType, "#4");
        }
Ejemplo n.º 11
0
        private SyndicationItem CreateSyndicationItem(IContent content)
        {
            var changeTrackable = content as IChangeTrackable;
            var versionable     = content as IVersionable;

            var changed   = DateTime.Now;
            var changedby = string.Empty;

            if (changeTrackable != null)
            {
                changed   = changeTrackable.Saved;
                changedby = changeTrackable.ChangedBy;
            }

            var item = new SyndicationItem
            {
                Title           = new TextSyndicationContent(content.Name),
                Summary         = new TextSyndicationContent(ItemDescriptionProvider.ItemDescripton(content)),
                LastUpdatedTime = changed
            };

            if (versionable != null)
            {
                var published = versionable.StartPublish;
                if (published.HasValue)
                {
                    item.PublishDate = published.Value;
                }
            }

            var categorizable = content as ICategorizable;

            if (categorizable != null)
            {
                var categoryRepository = ServiceLocator.Current.GetInstance <CategoryRepository>();
                foreach (var category in categorizable.Category)
                {
                    item.Categories.Add(new SyndicationCategory(categoryRepository.Get(category).Description));
                }
            }

            var mimeType = GetMimeType(content);
            Uri url      = GetItemUrl(content);

            item.Content = new UrlSyndicationContent(url, mimeType);
            item.AddPermalink(url);
            item.Authors.Add(new SyndicationPerson(string.Empty, changedby, string.Empty));

            item = ItemModifier.Modify(item, content);


            return(item);
        }
Ejemplo n.º 12
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);
        }
Ejemplo n.º 13
0
        private IEnumerable <SyndicationItem> ListPosts(UrlHelper urlHelper)
        {
            var authors = new Dictionary <Guid, SyndicationPerson>();

            foreach (var post in _postRepository.ListPublished(1, 10).Items)
            {
                Trace.Assert(post.IsPublished, "Unpublished post in feed.");

                var item      = new SyndicationItem(post.Title, post.Body, null);
                var permaLink = _urlResolverService.CreateDetailLink(urlHelper, post, true);
                item.AddPermalink(permaLink);
                item.Id = permaLink.ToString();
                item.Categories.Add(new SyndicationCategory("Posts"));

                foreach (var tag in post.Tags)
                {
                    item.Categories.Add(new SyndicationCategory(tag));
                }

                if (authors.ContainsKey(post.AuthorID))
                {
                    item.Authors.Add(authors[post.AuthorID]);
                }
                else
                {
                    var user = Membership.GetUser(post.AuthorID);

                    if (user != null)
                    {
                        var author = new SyndicationPerson(null, user.UserName, null);

                        authors.Add(post.AuthorID, author);
                        item.Authors.Add(author);
                    }
                }

                item.PublishDate     = post.PublishDate.Value;
                item.LastUpdatedTime = post.PositionDateTime.Value;

                if (post.Position != null)
                {
                    item.ElementExtensions.Add(
                        "point",
                        "http://www.georss.org/georss",
                        String.Format(NumberFormatInfo.InvariantInfo, "{0} {1}", post.Position.Latitude, post.Position.Longitude));
                }

                yield return(item);
            }
        }
Ejemplo n.º 14
0
        private List <SyndicationItem> GetRecentPagesOrPosts(RSSFeedInclude feedData)
        {
            List <SyndicationItem> syndRSS = new List <SyndicationItem>();
            List <SiteNav>         lst     = new List <SiteNav>();

            ContentPageType PageType = new ContentPageType();

            using (ISiteNavHelper navHelper = SiteNavFactory.GetSiteNavHelper()) {
                if (feedData == RSSFeedInclude.PageOnly || feedData == RSSFeedInclude.BlogAndPages)
                {
                    List <SiteNav> lst1 = navHelper.GetLatest(this.SiteID, 8, true);
                    lst = lst.Union(lst1).ToList();
                    List <SiteNav> lst2 = navHelper.GetLatestUpdates(this.SiteID, 10, true);
                    lst = lst.Union(lst2).ToList();
                }
                if (feedData == RSSFeedInclude.BlogOnly || feedData == RSSFeedInclude.BlogAndPages)
                {
                    List <SiteNav> lst1 = navHelper.GetLatestPosts(this.SiteID, 8, true);
                    lst = lst.Union(lst1).ToList();
                    List <SiteNav> lst2 = navHelper.GetLatestPostUpdates(this.SiteID, 10, true);
                    lst = lst.Union(lst2).ToList();
                }
            }

            lst.RemoveAll(x => x.ShowInSiteMap == false && x.ContentType == ContentPageType.PageType.ContentEntry);
            lst.RemoveAll(x => x.BlockIndex == true);

            foreach (SiteNav sn in lst)
            {
                SyndicationItem si = new SyndicationItem();

                string sPageURI = RemoveDupeSlashesURL(this.ConstructedCanonicalURL(sn));

                Uri PageURI = new Uri(sPageURI);

                si.Content = new TextSyndicationContent(sn.PageTextPlainSummaryMedium.ToString());
                si.Title   = new TextSyndicationContent(sn.NavMenuText);
                si.Links.Add(SyndicationLink.CreateSelfLink(PageURI));
                si.AddPermalink(PageURI);

                si.LastUpdatedTime = sn.EditDate;
                si.PublishDate     = sn.CreateDate;

                syndRSS.Add(si);
            }

            return(syndRSS.OrderByDescending(p => p.PublishDate).ToList());
        }
Ejemplo n.º 15
0
        private IEnumerable <SyndicationItem> ListVideos(UrlHelper urlHelper)
        {
            foreach (var video in _videoRepository.ListVideos(1, 10).Items)
            {
                var permaLink = _urlResolverService.CreateDetailLink(urlHelper, video, true);

                var item = new SyndicationItem("Video: " + video.Title, String.Format(c_videoTemplate, video.Description, video.EmbedHtml), null)
                {
                    PublishDate     = video.PositionDateTime.Value,
                    LastUpdatedTime = video.PositionDateTime.Value,
                    Id = permaLink.ToString()
                };

                item.Categories.Add(new SyndicationCategory("Videos"));

                item.AddPermalink(permaLink);

                yield return(item);
            }
        }
Ejemplo n.º 16
0
        private IEnumerable <SyndicationItem> ListPictures(UrlHelper urlHelper)
        {
            foreach (var album in _pictureRepository.ListAlbums(1, 10).Items)
            {
                var permaLink = _urlResolverService.CreateDetailLink(urlHelper, album, true);

                var item = new SyndicationItem("Fotos: " + album.Title, String.Format(c_albumTemplate, album.Description, permaLink, album.ThumbnailUri), null)
                {
                    PublishDate     = album.PositionDateTime.Value,
                    LastUpdatedTime = album.PositionDateTime.Value,
                    Id = permaLink.ToString()
                };

                item.Categories.Add(new SyndicationCategory("Fotos"));

                item.AddPermalink(permaLink);

                yield return(item);
            }
        }
Ejemplo n.º 17
0
        private void RssTask()
        {
            var feed = new SyndicationFeed("绅士之庭订阅源", "应广大群众的呼声,Gmgard.com的订阅源轰然面世。如遇任何问题请联系站长", rsslink);

            //feed.Language = "zh-CN";
            feed.Authors.Add(new SyndicationPerson("*****@*****.**"));
            feed.LastUpdatedTime = DateTimeOffset.Now;
            feed.Links.Add(new SyndicationLink(link, "self", "gmgard.com", null, 0));
            feed.ImageUrl = imgurl;
            var items = new List <SyndicationItem>();

            using (var scope = _scopeFactory.CreateScope())
            {
                var db           = scope.ServiceProvider.GetRequiredService <BlogContext>();
                var blogs        = db.Blogs.Where(b => b.isApproved == true).OrderByDescending(b => b.BlogDate).Take(20);
                var categoryUtil = scope.ServiceProvider.GetRequiredService <CategoryUtil>();
                foreach (var blog in blogs)
                {
                    var item = new SyndicationItem();
                    foreach (var CategoryName in categoryUtil.GetFullCategoryNames(blog.CategoryID))
                    {
                        item.Categories.Add(new SyndicationCategory(CategoryName));
                    }
                    var path = BlogHelper.firstImgPath(blog, true);
                    item.Summary = new CDataSyndicationContent(string.Format("<img src='{0}'></img><br/><p>{1}</p>", path, BlogHelper.getFirstLine(blog.Content, 200, true)));
                    item.Authors.Add(new SyndicationPerson(blog.Author));
                    item.PublishDate     = blog.BlogDate;
                    item.LastUpdatedTime = blog.BlogDate;
                    item.Title           = new TextSyndicationContent(blog.BlogTitle);
                    item.Id = "https://gmgard.com/gm" + blog.BlogID;
                    item.AddPermalink(new Uri("https://gmgard.com/gm" + blog.BlogID));
                    items.Add(item);
                }
                feed.Items = items;
            }

            using (var writer = System.Xml.XmlWriter.Create(filepath))
            {
                feed.SaveAsAtom10(writer);
            }
        }
Ejemplo n.º 18
0
        public static SyndicationItem ToSyndicationItem(this CartEntry entry, QueryString qs)
        {
            var builder = new UriBuilder(entry.GrabUrl);

            builder.Query = qs.Value;
            var grabUri = builder.Uri;

            var feedItem = new SyndicationItem(entry.Title, entry.Description, grabUri)
            {
                PublishDate = new DateTimeOffset(entry.PublishDate),
                Id          = entry.RowKey,
            };

            feedItem.AddPermalink(new Uri(entry.DetailsUrl));
            feedItem.ElementExtensions.Add(new XElement("category", entry.Category));
            feedItem.ElementExtensions.Add(new XElement("enclosure",
                                                        new XAttribute("url", grabUri),
                                                        new XAttribute("length", "0"),
                                                        new XAttribute("type", "application/x+nzb")));

            return(feedItem);
        }
Ejemplo n.º 19
0
        public ActionResult PostFeed(string nsxAlias)
        {
            string urlweb = "http://localhost:41221/";
            NSX    nsx    = db.NSXes.FirstOrDefault(x => x.NSXAlias.Contains(nsxAlias));

            if (nsx == null)
            {
                return(HttpNotFound());
            }
            IEnumerable <SanPham> sanPhams = db.SanPhams.Where(x => x.IDNSX == nsx.IDNSX).ToList();

            var feed = new SyndicationFeed(nsx.TenNSX, "RSS Feed", new Uri(urlweb + "RSS"), Guid.NewGuid().ToString(), DateTime.Now);

            var items = new List <SyndicationItem>();

            foreach (SanPham a in sanPhams)
            {
                string postUrl = string.Format(urlweb + "r/{0}/{1}/{2}", a.NSX.Loai.LoaiAlias, a.NSX.NSXAlias, a.SanPhamAlias);
                //var item = new SyndicationItem(Helper.RemoveIllegalCharacters(a.A_Title),
                //    Helper.RemoveIllegalCharacters(a.A_Description),
                //    new Uri(postUrl),
                //    a.A_ID.ToString(),
                //    a.A_DatePublished.Value);
                SyndicationItem syndicationItem = new SyndicationItem();
                syndicationItem.Title   = new TextSyndicationContent(Helper.RemoveIllegalCharacters(a.TenSanPham));
                syndicationItem.Content = new TextSyndicationContent(Helper.RemoveIllegalCharacters(a.MoTaSanPham));
                syndicationItem.AddPermalink(new Uri(postUrl));
                syndicationItem.Id          = a.IDSanPham.ToString();
                syndicationItem.PublishDate = a.NgayCapNhat.Value;

                items.Add(syndicationItem);
            }
            feed.Items = items;
            return(new RSSActionResult {
                Feed = feed
            });
        }
Ejemplo n.º 20
0
        public static Dictionary <string, List <SyndicationItem> > Grab()
        {
            var NewSubRedditPosts = RssStation.Utils.Grabbers.RedditGrabber.GetNewSubRedditPosts("Amd");

            var items = new Dictionary <string, List <SyndicationItem> >();

            foreach (var post in NewSubRedditPosts)
            {
                Console.WriteLine(post.Title);

                try
                {
                    var item = new SyndicationItem();
                    item.Id    = post.Id;
                    item.Title = new TextSyndicationContent(post.Title);
                    item.AddPermalink(new Uri(post.Shortlink));
                    item.Content         = SyndicationContent.CreateHtmlContent(GrabPostContent(post));
                    item.LastUpdatedTime = post.Created;
                    item.PublishDate     = post.Created;

                    var postType = (post.LinkFlairText is string) ? post.LinkFlairText.Trim() : "Other";
                    if (!items.ContainsKey(postType))
                    {
                        items.Add(postType, (new List <SyndicationItem>()));
                    }

                    items[postType].Add(item);
                }
                catch (System.Exception ex)
                {
                    Console.WriteLine(ex);
                }
            }

            return(items);
        }
Ejemplo n.º 21
0
        public void AddPermalinkNull()
        {
            SyndicationItem item = new SyndicationItem();

            item.AddPermalink(null);
        }
Ejemplo n.º 22
0
        public static string GetFeed(QuickParameters quickParameters, string type)
        {
            string urlPrefix = System.Configuration.ConfigurationManager.AppSettings["HostName"] + HttpContext.Current.Request.ApplicationPath;

            UserDataContext udc = UserDataContext.GetUserDataContext();

            quickParameters.Udc         = udc;
            quickParameters.ObjectTypes = QuickParameters.GetDelimitedObjectTypeIDs(rssEngineConfig.ObjectTypes, ',');
            quickParameters.SortBy      = QuickSort.StartDate;
            //quickParameters.FromStartDate = DateTime.Now - new TimeSpan(rssEngineConfig.Days, 0, 0, 0);
            quickParameters.Amount   = rssEngineConfig.MaxItems;
            quickParameters.PageSize = rssEngineConfig.MaxItems;

            StringBuilder   sb;
            List <string>   titleSegments = new List <string>();
            SyndicationFeed feed          = new SyndicationFeed();

            if (quickParameters.CommunityID.HasValue)
            {
                DataObjectCommunity channelCommunity = DataObject.Load <DataObjectCommunity>(quickParameters.CommunityID);
                if (channelCommunity.State != ObjectState.Added)
                {
                    if (channelCommunity.ObjectType == Helper.GetObjectTypeNumericID("ProfileCommunity"))
                    {
                        titleSegments.Add(string.Format("Von {0}", channelCommunity.Nickname));
                    }
                    else
                    {
                        titleSegments.Add(string.Format("Von {0}", channelCommunity.Title));
                    }
                }
            }
            else if (quickParameters.UserID.HasValue)
            {
                Business.DataObjectUser channelUser = DataObject.Load <DataObjectUser>(quickParameters.UserID);
                if (channelUser.State != ObjectState.Added)
                {
                    titleSegments.Add(string.Format("Von {0}", channelUser.Nickname));
                }
            }
            if (!string.IsNullOrEmpty(quickParameters.RawTags1) || !string.IsNullOrEmpty(quickParameters.RawTags2) || !string.IsNullOrEmpty(quickParameters.RawTags3))
            {
                titleSegments.Add(string.Format("Tags {0}", Helper.GetTagWordString(new List <string>()
                {
                    quickParameters.RawTags1, quickParameters.RawTags2, quickParameters.RawTags3
                })));
            }

            sb = new StringBuilder();
            if (titleSegments.Count > 0)
            {
                for (int i = 0; i < titleSegments.Count; i++)
                {
                    sb.Append(titleSegments[i]);
                    if (i < titleSegments.Count - 1)
                    {
                        sb.Append(", ");
                    }
                }
            }
            else
            {
                sb.Append("Alles");
            }
            string title       = string.Format("{0} Feed - {1}", siteName, sb.ToString());
            string description = "RSS Feed von " + siteName;

            feed.Title       = TextSyndicationContent.CreatePlaintextContent(title);
            feed.Description = TextSyndicationContent.CreatePlaintextContent(description);
            feed.Links.Add(new SyndicationLink(new Uri(urlPrefix)));
            feed.Language = "de-CH";

            List <SyndicationItem>      items    = new List <SyndicationItem>();
            DataObjectList <DataObject> rssItems = DataObjects.Load <DataObject>(quickParameters);

            foreach (DataObject rssItem in rssItems)
            {
                SyndicationItem item = new SyndicationItem();

                // Add prefix to title
                item.Title = TextSyndicationContent.CreatePlaintextContent("[" + Helper.GetObjectName(rssItem.ObjectType, true) + "] " + rssItem.Title);

                // Set owner as author
                SyndicationPerson author = new SyndicationPerson();
                author.Name = rssItem.Nickname;
                item.Authors.Add(author);

                // Set object's guid
                item.Id = rssItem.objectID.Value.ToString();

                // Link to the object
                string itemUrl = urlPrefix + Helper.GetDetailLink(rssItem.ObjectType, rssItem.objectID.Value.ToString());
                item.AddPermalink(new Uri(itemUrl));

                // Take start date as publish date
                item.PublishDate = rssItem.StartDate;

                // Image if available
                if (!string.IsNullOrEmpty(rssItem.GetImage(PictureVersion.S)) && rssItem.GetImage(PictureVersion.S).ToLower() != Helper.GetDefaultURLImageSmall(rssItem.ObjectType).ToLower())
                {
                    item.Content = SyndicationContent.CreateXhtmlContent("<div><a href=\"" + itemUrl + "\"><img src=\"" + System.Configuration.ConfigurationManager.AppSettings["MediaDomainName"] + rssItem.GetImage(PictureVersion.S) + "\"></a></div><div>" + rssItem.Description.StripHTMLTags().CropString(rssEngineConfig.MaxDescriptionLength) + "</div>");
                }
                else
                {
                    item.Content = TextSyndicationContent.CreatePlaintextContent(rssItem.Description.StripHTMLTags().CropString(rssEngineConfig.MaxDescriptionLength));
                }

                items.Add(item);
            }

            feed.Items = items;

            sb = new StringBuilder();
            XmlWriter xmlWriter = XmlWriter.Create(sb);

            if (type == "rss")
            {
                feed.SaveAsRss20(xmlWriter);
            }
            else if (type == "atom")
            {
                feed.SaveAsAtom10(xmlWriter);
            }
            xmlWriter.Close();

            string feedXml = sb.ToString();

            feedXml = Regex.Replace(feedXml, @"^<.*?xml.*?>\s*", "");
            return(feedXml);
        }