Esempio n. 1
0
        /// <summary>
        /// Fetch latest posts
        /// </summary>
        /// <returns>List or null in case of errors</returns>
        internal async Task <List <Post> > fetchPosts()
        {
            // fetch posts (amount of limit set)
            HashSet <RedditPost> rpList;

            try
            {
                RedditPostPage rpp = await RedditScraper.ParsePosts(FUNNY_URL + "&limit=" + POST_FETCH_LIMIT);

                rpList = rpp.Posts;
            }
            catch (WebException we)
            {
                Debug.WriteLine(we.Message);
                return(null);
            }

            // convert reddit posts into funnyposts
            ConcurrentStack <Post> fpStack = new ConcurrentStack <Post>();
            int dclBackup = ServicePointManager.DefaultConnectionLimit;

            ServicePointManager.DefaultConnectionLimit = MAX_TASKS;
            Parallel.ForEach(rpList, new ParallelOptions {
                MaxDegreeOfParallelism = MAX_TASKS
            }, post =>
            {
                Post fp = createFunnyPost(post).Result;
                if (fp != null)
                {
                    fpStack.Push(fp);
                }
            });
            ServicePointManager.DefaultConnectionLimit = dclBackup;
            return(new List <Post>(fpStack));
        }
Esempio n. 2
0
 public void ParsePostsInvalidUri()
 {
     RedditPostPage rpp = RedditScraper.ParsePosts("http://127.0.0.1.json").Result;
 }
Esempio n. 3
0
        public void ParsePosts()
        {
            RedditPostPage rpp = RedditScraper.ParsePosts("http://www.reddit.com/r/csharp.json").Result;

            Assert.IsFalse(rpp.Posts.Count == 0);
        }