コード例 #1
0
        public ICollection <NewsFeed> GetFeeds()
        {
            FudgeDataContext db    = new FudgeDataContext();
            List <NewsFeed>  feeds = new List <NewsFeed>();

            var normalPosts = from p in db.Posts
                              where p.Topic.Visible && p.Topic.Forum.Visible && p.Topic.Forum.ForumCategory.Visible &&
                              SqlMethods.DateDiffDay(p.Timestamp, DateTime.UtcNow) <= Expiration
                              select p;

            var problemPosts = from problem in db.Problems
                               from topics in problem.Forum.Topics
                               from post in topics.Posts
                               where SqlMethods.DateDiffDay(post.Timestamp, DateTime.UtcNow) <= Expiration
                               select new { Post = post, Problem = problem };

            var snippetPosts = from snippet in db.CodeSnippets
                               from post in snippet.Topic.Posts
                               where SqlMethods.DateDiffDay(post.Timestamp, DateTime.UtcNow) <= Expiration
                               select new { Post = post, Snippet = snippet };

            foreach (var post in normalPosts)
            {
                feeds.Add(new NewsFeed {
                    Type       = NewsFeedType.ForumPost,
                    Parameters = NewsFeedDescriptor.BuildNewsFeedDescriptorList(post.PostId),
                    UserId     = post.UserId,
                    Timestamp  = post.Timestamp
                });
            }

            foreach (var post in problemPosts)
            {
                feeds.Add(new NewsFeed {
                    Type       = NewsFeedType.ProblemPost,
                    Parameters = NewsFeedDescriptor.BuildNewsFeedDescriptorList(post.Post.PostId, post.Problem.ProblemId),
                    UserId     = post.Post.UserId,
                    Timestamp  = post.Post.Timestamp
                });
            }

            foreach (var post in snippetPosts)
            {
                feeds.Add(new NewsFeed {
                    Type       = NewsFeedType.CodeSnippetPost,
                    Parameters = NewsFeedDescriptor.BuildNewsFeedDescriptorList(post.Post.PostId, post.Snippet.SnippetId),
                    UserId     = post.Post.UserId,
                    Timestamp  = post.Post.Timestamp
                });
            }

            return(feeds);
        }
コード例 #2
0
ファイル: NewNewsFeed.cs プロジェクト: fudge-project/fudge
        public ICollection <NewsFeed> GetFeeds()
        {
            FudgeDataContext db    = new FudgeDataContext();
            List <NewsFeed>  feeds = new List <NewsFeed>();

            var newes = from n in db.News
                        where SqlMethods.DateDiffDay(n.Timestamp, DateTime.UtcNow) <= Expiration
                        select n;

            foreach (var news in newes)
            {
                feeds.Add(new NewsFeed {
                    Type       = NewsFeedType.News,
                    Parameters = NewsFeedDescriptor.BuildNewsFeedDescriptorList(news.NewsId),
                    UserId     = null,
                    Timestamp  = news.Timestamp + Priority
                });
            }

            return(feeds);
        }
コード例 #3
0
        public ICollection <NewsFeed> GetFeeds()
        {
            FudgeDataContext db    = new FudgeDataContext();
            List <NewsFeed>  feeds = new List <NewsFeed>();

            var snippets = from s in db.CodeSnippets
                           where SqlMethods.DateDiffDay(s.Timestamp, DateTime.UtcNow) <= Expiration
                           select s;

            foreach (var snippet in snippets)
            {
                feeds.Add(new NewsFeed {
                    Type       = NewsFeedType.CodeSnippet,
                    Parameters = NewsFeedDescriptor.BuildNewsFeedDescriptorList(snippet.SnippetId),
                    UserId     = snippet.UserId,
                    Timestamp  = snippet.Timestamp
                });
            }

            return(feeds);
        }
コード例 #4
0
        public ICollection <NewsFeed> GetFeeds()
        {
            FudgeDataContext db    = new FudgeDataContext();
            List <NewsFeed>  feeds = new List <NewsFeed>();

            var contests = from c in db.Contests
                           let d = SqlMethods.DateDiffDay(DateTime.UtcNow, c.StartTime)
                                   where d >= 0 && d <= Expiration && !c.UserId.HasValue
                                   select c;

            foreach (var contest in contests)
            {
                feeds.Add(new NewsFeed {
                    Type       = NewsFeedType.NewContest,
                    Parameters = NewsFeedDescriptor.BuildNewsFeedDescriptorList(contest.ContestId),
                    UserId     = null,
                    Timestamp  = contest.StartTime
                });
            }

            return(feeds);
        }
コード例 #5
0
        public ICollection <NewsFeed> GetFeeds()
        {
            FudgeDataContext db    = new FudgeDataContext();
            List <NewsFeed>  feeds = new List <NewsFeed>();

            var problems = from p in db.Problems
                           where p.Visible
                           where SqlMethods.DateDiffDay(p.Timestamp, DateTime.UtcNow) <= Expiration
                           select p;

            foreach (var problem in problems)
            {
                feeds.Add(new NewsFeed {
                    Type       = NewsFeedType.NewProblem,
                    Parameters = NewsFeedDescriptor.BuildNewsFeedDescriptorList(problem.ProblemId),
                    UserId     = null,
                    Timestamp  = problem.Timestamp
                });
            }

            return(feeds);
        }
コード例 #6
0
        public ICollection <NewsFeed> GetFeeds()
        {
            FudgeDataContext db    = new FudgeDataContext();
            List <NewsFeed>  feeds = new List <NewsFeed>();

            var recents = GetRecentSolutions(db);

            foreach (var recent in recents)
            {
                feeds.Add(new NewsFeed {
                    Type       = NewsFeedType.SolvedProblem,
                    Parameters = NewsFeedDescriptor.BuildNewsFeedDescriptorList(recent.RunId),
                    UserId     = recent.UserId,
                    Timestamp  = recent.Timestamp
                });
            }

            var shortests = GetRecentShortestSolutions(db, recents);

            foreach (var shortest in shortests)
            {
                if (shortest == null)
                {
                    continue;
                }

                feeds.Add(new NewsFeed {
                    Type       = NewsFeedType.ShortestSolution,
                    Parameters = NewsFeedDescriptor.BuildNewsFeedDescriptorList(shortest.RunId),
                    UserId     = shortest.UserId,
                    Timestamp  = shortest.Timestamp
                });
            }

            return(feeds);
        }