/*public async Task LoadSectors(HomeViewModel model)
         * {
         *  using (Profiler.StepStatic("Loading Sectors"))
         *  {
         *      model.PostSectors = new Dictionary<Post, IEnumerable<Category>>();
         *      if (model.TopStory != null)
         *      {
         *          IEnumerable<Category> sectors = await Repository.GetPostSectorsAsync(model.TopStory);
         *          model.PostSectors.Add(model.TopStory, sectors);
         *      }
         *
         *      IEnumerable<Category> postSectors = null;
         *      if (model.FeatureStory != null && !model.PostSectors.TryGetValue(model.FeatureStory, out postSectors))
         *      {
         *          postSectors = await Repository.GetPostSectorsAsync(model.FeatureStory);
         *          model.PostSectors.Add(model.FeatureStory, postSectors);
         *      }
         *
         *      if (model.LatestNews != null)
         *      {
         *          foreach (Post post in model.LatestNews)
         *          {
         *              if (!model.PostSectors.TryGetValue(post, out postSectors))
         *              {
         *                  postSectors = await Repository.GetPostSectorsAsync(post);
         *                  model.PostSectors.Add(post, postSectors);
         *              }
         *          }
         *      }
         *  }
         * }*/

        private async Task <SyndicationFeedViewModel> GetFeedModel(string key, string postKind)
        {
            IndexModel indexModel = await GetIndexModel(key);

            var model = new SyndicationFeedViewModel();

            model.AlternateUri = new Uri(Configuration["NewsHostUri"]);

            var posts = new List <Post>();

            if (string.IsNullOrEmpty(postKind))
            {
                model.Title = indexModel.Index.Name;
                await indexModel.LoadTopAndFeaturePosts(Repository);

                if (indexModel.TopPost != null)
                {
                    posts.Add(indexModel.TopPost);
                }

                if (indexModel.FeaturePost != null)
                {
                    posts.Add(indexModel.FeaturePost);
                }
            }
            else
            {
                model.Title = indexModel.Index.Name + " " + char.ToUpper(postKind[0]) + postKind.Substring(1);
            }
            posts.AddRange(await Repository.GetLatestPostsAsync(indexModel, postKind));
            model.Entries = posts.Take(ProviderHelpers.MaximumSyndicationItems);

            return(model);
        }
        protected async Task <ActionResult> GetNewsFeedContent(string format, SyndicationFeedViewModel model, bool newsOnDemand, bool resetRssFeeds)
        {
            if (this.GetType().GetTypeInfo().IsDefined(typeof(ObsoleteAttribute), false))
            {
                return(NotFound());
            }

            NewsSyndicationFeed feed = new NewsSyndicationFeed(format, model, Repository);

            string content = await feed.GetContentAsync(ControllerContext, newsOnDemand, resetRssFeeds);

            string contentType;

            if (format == "atom")
            {
                contentType = "application/atom+xml";
            }
            else if (format == null || format == "rss2")
            {
                contentType = "application/rss+xml";
            }
            else
            {
                throw new NotImplementedException();
            }
            return(Content(content, contentType));
        }
Exemple #3
0
        public async Task <SyndicationFeedViewModel> GetSyndicationFeedViewModel(string title, IEnumerable <string> postKeys)
        {
            var model = new SyndicationFeedViewModel();

            model.AlternateUri = new Uri(Configuration["NewsHostUri"]);

            model.Title        = title;
            model.AlternateUri = null;
            model.Entries      = (await Repository.GetPostsAsync(postKeys.Take(ProviderHelpers.MaximumSyndicationItems))).Where(e => e != null);

            return(model);
        }
        public async Task <SyndicationFeedViewModel> GetFeatureStoriesModel()
        {
            var model = new SyndicationFeedViewModel();

            model.AlternateUri = new Uri(Configuration["NewsHostUri"]);
            model.Title        = "Featured Stories";
            model.AlternateUri = null;

            List <string> postKeys = IndexModel.GetFeaturePostKeysToLoad(await Repository.GetMinistriesAsync()).ToList();

            postKeys.AddRange(IndexModel.GetFeaturePostKeysToLoad(await Repository.GetSectorsAsync()));
            (await Repository.GetHomeAsync()).AddFeaturePostKeyToLoad(postKeys);

            model.Entries = await Repository.GetPostsAsync(postKeys.Take(ProviderHelpers.MaximumSyndicationItems));

            return(model);
        }
        public NewsSyndicationFeed(string format, SyndicationFeedViewModel model, Repository repository)
        {
            Model       = model;
            _repository = repository;

            if (string.IsNullOrEmpty(format))
            {
                Format = "rss2";
            }
            else if (format == "atom" || format == "rss2")
            {
                Format = format;
            }
            else
            {
                throw new ArgumentException("The syndication format must be \"atom\" or \"rss2\".", "format");
            }
        }
        /*public async Task LoadSectors(HomeViewModel model)
         * {
         *  using (Profiler.StepStatic("Loading Sectors"))
         *  {
         *      model.PostSectors = new Dictionary<Post, IEnumerable<Category>>();
         *      if (model.TopStory != null)
         *      {
         *          IEnumerable<Category> sectors = await Repository.GetPostSectorsAsync(model.TopStory);
         *          model.PostSectors.Add(model.TopStory, sectors);
         *      }
         *
         *      IEnumerable<Category> postSectors = null;
         *      if (model.FeatureStory != null && !model.PostSectors.TryGetValue(model.FeatureStory, out postSectors))
         *      {
         *          postSectors = await Repository.GetPostSectorsAsync(model.FeatureStory);
         *          model.PostSectors.Add(model.FeatureStory, postSectors);
         *      }
         *
         *      if (model.LatestNews != null)
         *      {
         *          foreach (Post post in model.LatestNews)
         *          {
         *              if (!model.PostSectors.TryGetValue(post, out postSectors))
         *              {
         *                  postSectors = await Repository.GetPostSectorsAsync(post);
         *                  model.PostSectors.Add(post, postSectors);
         *              }
         *          }
         *      }
         *  }
         * }*/

        private async Task <SyndicationFeedViewModel> GetFeedModel(string key, string postKind)
        {
            DataIndex index = await GetDataIndex(key, (string)RouteData.Values["category"]);

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

            var model = new SyndicationFeedViewModel();

            model.AlternateUri = new Uri(Configuration["NewsHostUri"]);

            var posts = new List <Post>();

            if (string.IsNullOrEmpty(postKind))
            {
                model.Title = index.Name;
                var loadedPosts = await IndexModel.LoadTopAndFeaturePosts(index, Repository);

                var topPost = loadedPosts.SingleOrDefault(p => p.Key == index.TopPostKey);
                if (topPost != null)
                {
                    posts.Add(topPost);
                }

                var featurePost = loadedPosts.SingleOrDefault(p => p.Key == index.FeaturePostKey);
                if (featurePost != null)
                {
                    posts.Add(featurePost);
                }
            }
            else
            {
                model.Title = index.Name + " " + char.ToUpper(postKind[0]) + postKind.Substring(1);
            }
            posts.AddRange(await Repository.GetLatestPostsAsync(index, ProviderHelpers.MaximumSyndicationItems - posts.Count, postKind, GetIndexFilter(index)));
            model.Entries = posts;

            return(model);
        }