Esempio n. 1
0
        private static void UpdateContentUrlWithinDatabase(RedditPostContext context, List <RedditPost> posts)
        {
            IQueryable <RedditPost>  postsQuery      = from m in context.RedditPost select m;
            IEnumerable <RedditPost> postsEnumerable = postsQuery.ToList().AsEnumerable();

            foreach (RedditPost fromJson in posts)
            {
                RedditPost fromDatabase = postsEnumerable.Where(post => post.Number == fromJson.Number).FirstOrDefault();

                if (fromJson.UrlContent != fromDatabase.UrlContent)
                {
                    fromDatabase.UrlContent = fromJson.UrlContent;
                    context.Update(fromDatabase);
                    context.SaveChanges();
                }
            }
        }
Esempio n. 2
0
        private void Randomize()
        {
            List <RedditPost> posts = PostsToFilter.ToList();
            Random            r     = new Random(Vm.RandomizeSeed);

            int curr = posts.Count;

            while (curr > 1)
            {
                curr--;
                int        toSwap = r.Next(curr + 1);
                RedditPost value  = posts[toSwap];
                posts[toSwap] = posts[curr];
                posts[curr]   = value;
            }

            PostsToFilter = posts.AsEnumerable();
        }
Esempio n. 3
0
        private void ContentTypeFilter()
        {
            List <RedditPost>  posts = PostsToFilter.ToList();
            List <ContentType> types = Enum.GetValues(typeof(ContentType)).Cast <ContentType>().ToList();

            for (int i = posts.Count - 1; i >= 0; i--)
            {
                RedditPost  post = posts[i];
                ContentType type = post.GetContentType();

                for (int j = 0; j < types.Count; j++)
                {
                    bool isWhitelisted = Vm.ContentTypes[j];

                    if (!isWhitelisted && types[j] == type)
                    {
                        posts.RemoveAt(i);
                    }
                }
            }

            PostsToFilter = posts.AsEnumerable();
        }