Пример #1
0
        public void Ctor_should_set_Feed_property_if_feed_parameter_has_a_correct_value()
        {
            var feed   = new SyndicationFeed("fake");
            var result = new RssResult(feed);

            Assert.AreEqual(feed, result.Feed);
        }
Пример #2
0
        public void ExecuteResult_should_throw_ArgumentNullException_if_context_parameter_is_null()
        {
            var feed   = new SyndicationFeed("fake");
            var result = new RssResult(feed);

            Executing.This(() => result.ExecuteResultAsync(null))
            .Should()
            .Throw <ArgumentNullException>()
            .And
            .ValueOf
            .ParamName
            .Should()
            .Be
            .EqualTo("context");
        }
Пример #3
0
        public void ExecuteResult_should_return_rss_mimetype()
        {
            var writer       = new StringWriter();
            var responseMock = new Mock <HttpResponse>();

            responseMock.SetupProperty <string>(x => x.ContentType);
            responseMock.SetupGet(x => x.Output).Returns(writer);
            var httpContextMock = new Mock <HttpResponse>();

            httpContextMock.SetupGet(x => x.Response).Returns(responseMock.Object);
            var controllerContextMock = new Mock <ControllerContext>();

            controllerContextMock.SetupGet(x => x.HttpContext).Returns(httpContextMock.Object);


            var feed   = new SyndicationFeed("fake");
            var result = new RssResult(feed);

            result.ExecuteResultAsync(controllerContextMock.Object);

            Assert.AreEqual("application/rss+xml", controllerContextMock.Object.HttpContext.Response.ContentType);
        }
Пример #4
0
        //TODO: Major refractor
        public ActionResult Feed(ContentModel model)
        {
            var blogPage = this._viewModelFactory.CreateModel(null, model);

            this._umbracoMapper.Map(model.Content, blogPage);
            var blogUrl = "https://" + Request.Url.Host + blogPage.Url + "";

            var syndicationItems = new List <SyndicationItem>();

            var author = new SyndicationPerson(Rasolo.Services.Constants.Project.Email, "Rasmus Olofsson", "https://rasolo.net");

            author.ElementExtensions.Add("title", string.Empty, "Web developer");


            author.ElementExtensions.Add("image", string.Empty, "https://rasolo.net/media/5a1pqhxs/rasolo.png");

            SyndicationFeed feed = new SyndicationFeed(blogPage.Title, blogPage?.MainBody?.ToString().StripHtml(), new System.Uri(Request.Url.AbsoluteUri))
            {
                Language = "en-us",
                Id       = blogUrl,
                Authors  = { author }
            };
            //var blogPostPages = blogPage.Children;
            var blogPostPages = new List <BlogPostPage.BlogPostPage>();

            this._umbracoMapper.MapCollection(blogPage.Children, blogPostPages);

            foreach (var blogPostPage in blogPostPages)
            {
                var blogPostPageUrl = "https://" + Request.Url.Host + blogPostPage.Url + "";

                var blogPostUri =
                    new Uri(blogPostPageUrl);
                var blogPostContent  = new TextSyndicationContent(HttpUtility.HtmlDecode(blogPostPage.MainBody?.ToString().StripHtml()));
                var blogPostFeedItem = new SyndicationItem(blogPostPage.Title,
                                                           blogPostContent.ToString(),
                                                           blogPostUri);
                blogPostFeedItem.ElementExtensions.Add("author", string.Empty, Rasolo.Services.Constants.Project.Email);
                blogPostFeedItem.PublishDate     = blogPostPage.CreateDate;
                blogPostFeedItem.LastUpdatedTime = blogPostPage.UpdateDate.ToUniversalTime();


                blogPostFeedItem.Content = blogPostContent;

                blogPostFeedItem.Categories.Add(new SyndicationCategory(blogPage.Name));
                syndicationItems.Add(blogPostFeedItem);
            }

            feed.LastUpdatedTime = blogPostPages.OrderByDescending(x => x.UpdateDate)
                                   .FirstOrDefault()
                                   .UpdateDate.ToUniversalTime();


            feed.Items = syndicationItems;
            SyndicationLink link = new SyndicationLink(
                new Uri(blogUrl + "feed"), "self", "type", "text/xml", 1000);

            feed.Links.Add(link);

            var result = new RssResult(feed);

            return(result);
        }
Пример #5
0
 public RssResult Rss()
 {
     var postViewModel = _postService.GetAllPostForBlog();
     var posts = new RssResult(postViewModel);
     return posts;
 }
Пример #6
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="series"></param>
        /// <param name="minAge"></param>
        /// <returns></returns>
        public override List<RssResult> UpdateRss(List<Series> series, int minAge)
        {
            FileNameParser fileNameParser = new FileNameParser();
            List<RssResult> rssResults = new List<RssResult>();

            foreach (Series serie in series)
            {
                WebClient wc = new WebClient();
                byte[] temp = wc.DownloadData(string.Format("http://www.dailytvtorrents.org/rss/show/{0}?items=all&minage={1}",
                                              serie.Name.Replace(" ", "-").ToLower(),
                                              minAge));
                string rss = Encoding.ASCII.GetString(temp);

                XDocument xDoc = XDocument.Parse(rss);

                foreach (var item in xDoc.Descendants("item"))
                {
                    RssResult rssResult = new RssResult();
                    rssResult.SeriesId = serie.Id;
                    rssResult.Title = Misc.GetElementValueAsString(item, "title");

                    var enclosure = from e in item.Elements("enclosure") select e;
                    if (enclosure.Any() == false)
                    {
                        continue;
                    }

                    rssResult.Url = Misc.GetAttributeValueAsString(enclosure.First(), "url");

                    fileNameParser.Parse(rssResult.Title);
                    if (fileNameParser.Matched() == true)
                    {
                        rssResult.SeasonNumber = fileNameParser.SeasonNumber;
                        rssResult.EpisodeNumber = fileNameParser.EpisodeNumber;
                        rssResult.Quality = fileNameParser.Quality;

                        rssResults.Add(rssResult);
                    }
                }
            }

            return rssResults;
        }
Пример #7
0
        protected ActionResult Display(string pageTitle, DisplayFormat format, SearchOrder order, bool votedOnly, int? page, string search)
        {
            int pageNumber = page.GetValueOrDefault(1);

            if (format == DisplayFormat.Rss)
            {
                pageNumber = 1;
            }

            IPagedList<TweetReport> tweets = TweetRepository.Search(App, pageNumber, 20, Tweeter, search, votedOnly, DefaultLanguage, order, null);

            TweetViewList tweetList = new TweetViewList(pageTitle, tweets.TotalItems, tweets.PageNumber, tweets.ItemsPerPage);
            tweetList.SearchTerm = String.IsNullOrWhiteSpace(search) ? null : search;

            foreach (TweetReport tweet in tweets)
            {
                TweetView tweetView = new TweetView()
                {
                    Id = tweet.Id,
                    TwitterId = tweet.TwitterId,
                    Username = tweet.Username,
                    ProfileImageUrl = tweet.ProfileImageUrl,
                    Message = tweet.Message,
                    DatePosted = tweet.DatePosted,
                    DeviceName = tweet.DeviceName,
                    DeviceUrl = tweet.DeviceUrl,
                    TotalVotes = (int)tweet.TotalVotes,
                    HasBeenVotedByUser = tweet.HasBeenVotedByUser
                };

                tweetList.Tweets.Add(tweetView);
            }

            if (format == DisplayFormat.Html)
            {
                return View(tweetList);
            }
            else if (format == DisplayFormat.HtmlSnippet)
            {
                return PartialView("Tweet", tweetList);
            }
            else if (format == DisplayFormat.Json)
            {
                return Json(tweetList, JsonRequestBehavior.AllowGet);
            }
            else if (format == DisplayFormat.Rss)
            {
                string rssTitle = pageTitle;

                if (!String.IsNullOrWhiteSpace(search))
                {
                    rssTitle += " Containing \"" + search + "\"";
                }

                rssTitle += " - " + App.Title;

                RssResult<TweetView> rssResult = new RssResult<TweetView>(rssTitle, "http://" + App.Url, App.Blurb);

                rssResult.DataSource = tweetList.Tweets;

                Uri requestUrl = Request.Url;
                string baseUrl = "http://" + requestUrl.Host + (requestUrl.Port != 80 ? ":" + requestUrl.Port : "");

                rssResult.SetDataSourceFields(t => t.Message, t => baseUrl + Url.Action("Status", new { twitterId = t.TwitterId, message = t.Message.ToFriendlyUrl() }),
                    t => "@" + t.Username + " tweeted \"" + t.Message + "\"", t => "@" + t.Username, t => t.DatePosted);

                return rssResult;
            }
            else
            {
                throw new NotSupportedException(format + " is not supported");
            }
        }