示例#1
0
        public ActionResult Feed(string format, string galleryName)
        {
            var baseUri = Request.Url;

            var settings   = GalleryService.GetGallerySettings(galleryName);
            var gallery    = GalleryService.GetGallery(galleryName, true, User, null, "bydate");
            var galleryUrl = Url.Action("Show", "Gallery", new { galleryName });

            var contentFormat = "<img src=\"{0}\" />" + (settings.StatsEnabled ? "<div>Voted by {1} user(s), Uploaded by {2}</div>" : null);

            var items = from photo in gallery.Photos
                        let title = photo.Title ?? photo.Name
                                    let itemUri = new Uri(baseUri, galleryUrl + "#" + photo.GetHash())
                                                  let imageUri = new Uri(baseUri, Url.ThumbnailUrl(galleryName, photo.Name))
                                                                 let author = photo.User != null && settings.StatsEnabled ? Regex.Replace(photo.User, ".*\\\\(.*)|(.*)@.*", "$1$2") : "Anonymous" // remove domain / email
                                                                              let description = new TextSyndicationContent(string.Format(contentFormat, imageUri, photo.TotalVotes, author), TextSyndicationContentKind.Html)
                                                                                                select new SyndicationItem(title, description, itemUri, itemUri.ToString(), photo.Date)
            {
                Title   = new TextSyndicationContent(title),
                Summary = description,
                Authors = { new SyndicationPerson {
                                Name = author
                            } },
                PublishDate = photo.PublishDate
            };

            var gallerySummary = string.Format("Publish date: {0}, {1} vote(s), {2} photo(s) by {3} user(s)", gallery.PublishDate.ToShortDateString(), gallery.TotalVotes, gallery.Photos.Count(), gallery.TotalUsers);
            var galleryUri     = new Uri(baseUri, galleryUrl);
            var feed           = new SyndicationFeed(galleryName, gallerySummary, galleryUri, items)
            {
                Id              = galleryUri.ToString(),
                Title           = new TextSyndicationContent(galleryName),
                LastUpdatedTime = gallery.Date,
                Description     = new TextSyndicationContent(gallerySummary),
            };

            return(new SyndicationActionResult {
                Feed = feed, Format = format
            });
        }