示例#1
0
        public override void DoWork()
        {
            int reminders       = 0;
            FudgeDataContext db = new FudgeDataContext();

            var upcomingContests = from c in db.Contests
                                   where SqlMethods.DateDiffDay(DateTime.UtcNow, c.StartTime) == 1
                                   select c;

            Log("{0} upcoming contests", upcomingContests.Count());
            foreach (var contest in upcomingContests)
            {
                foreach (var user in contest.ContestUsers)
                {
                    DateTime startTime = TimeZoneInfo.ConvertTimeFromUtc(contest.StartTime, user.User.TimeZoneInfo);
                    String   body      = String.Format(Emails.ContestNotificationEmail, user.User.FirstName,
                                                       contest.Name, startTime.ToString("f"), user.User.Timezone, contest.UrlName);
                    if (Emails.SendEmail(user.User, "Contest Reminder", body))
                    {
                        reminders++;
                    }
                }
                Log("{0}/{1} Reminders sent", reminders, contest.ContestUsers.Count);
            }
        }
示例#2
0
        public void ShowDialog(FudgeDataContext dataContext, Contest contest)
        {
            contestAnalyzer.DataContext = dataContext;
            contestAnalyzer.Contest     = contest;
            contestAnalyzer.Initialize();

            base.ShowDialog();
        }
示例#3
0
 public static void ValidateData(this CustomValidator validator, Func <FudgeDataContext, string, bool> pred, Func <string, string> error)
 {
     validator.ServerValidate += (s, e) => {
         FudgeDataContext db = new FudgeDataContext();
         e.IsValid = pred(db, e.Value);
         validator.ErrorMessage = error(e.Value);
     };
 }
示例#4
0
    public static string LinkToSchoolProfile(int schoolId)
    {
        var db = new FudgeDataContext();

        var school = db.Schools.SingleOrDefault(s => s.SchoolId == schoolId);

        return(Link("/Schools/" + schoolId, school.Name));
    }
示例#5
0
    public static string LinkToBlog(int blogId)
    {
        var db = new FudgeDataContext();

        var blog = db.Blogs.SingleOrDefault(b => b.BlogId == blogId);

        return(LinkToBlog(blogId, blog.Name));
    }
示例#6
0
    public static string LinkToBlog(int blogId, string text)
    {
        var db = new FudgeDataContext();

        var blog = db.Blogs.SingleOrDefault(b => b.BlogId == blogId);

        return(Link("/Community/Blogs/" + blog.UrlName, text));
    }
示例#7
0
        public SchoolEditForm(FudgeDataContext dataContext)
        {
            DataContext = dataContext;
            InitializeComponent();

            countryComboBox.Items.AddRange(DataContext.Countries.ToArray());
            countryComboBox.SelectedIndex = 0;
        }
示例#8
0
    public static string LinkToTopics(int forumId)
    {
        var db = new FudgeDataContext();

        var topic = db.Topics.SingleOrDefault(t => t.ForumId == forumId);

        return(Link("/Community/Forum/Topic/" + topic.ForumId, topic.Title));
    }
示例#9
0
    public static string LinkToPost(int postId)
    {
        var db = new FudgeDataContext();

        var post = db.Posts.SingleOrDefault(p => p.PostId == postId);

        return(Link("/Community/Forum/Posts/" + post.TopicId, post.Title));
    }
示例#10
0
    public static string LinkToCountryProfile(int countryId)
    {
        var db = new FudgeDataContext();

        var country = db.Countries.SingleOrDefault(c => c.CountryId == countryId);

        return(Link("/Country/" + countryId, country.Name));
    }
示例#11
0
    public static string LinkToTeamProfile(int teamId)
    {
        var db = new FudgeDataContext();

        var team = db.Teams.SingleOrDefault(t => t.TeamId == teamId);

        return(Link("/Teams/" + teamId, team.Name));
    }
示例#12
0
        public static void UnSubscribeFrom(this User user, int topicId)
        {
            FudgeDataContext db = new FudgeDataContext();
            var subscription    = db.TopicSubscriptions.SingleOrDefault(s => s.UserId == user.UserId &&
                                                                        s.TopicId == topicId);

            db.TopicSubscriptions.DeleteOnSubmit(subscription);
            db.SubmitChanges();
        }
示例#13
0
        public static void AcceptTeamInvite(this User user, int teamId)
        {
            FudgeDataContext db = new FudgeDataContext();
            var team            = Team.GetTeamById(teamId);

            team.ChangeUserStatus(user.UserId, TeamUserStatus.Member);
            //subscribe to this team
            user.SubscribeForReplies(team.TopicId);
        }
示例#14
0
        public override void DoWork()
        {
            FudgeDataContext db = new FudgeDataContext();

            foreach (Contest contest in db.Contests)
            {
                contest.UpdatePoints();
            }
        }
示例#15
0
    protected void notificationsSource_Selecting(object sender, LinqDataSourceSelectEventArgs e)
    {
        FudgeDataContext db = new FudgeDataContext();

        e.Result = (from n in db.Notifications
                    where n.UserId == FudgeUser.UserId
                    orderby n.Timestamp descending
                    select n).Take(5);
    }
示例#16
0
        public void Initialize()
        {
            Console.WriteLine("[contest] Looking for a Judge module...");

            foreach (IModule module in Host.Modules)
            {
                Judge = module as JudgeModule;

                if (Judge != null)
                {
                    break;
                }
            }

            if (Judge == null)
            {
                Console.WriteLine("[contest] There is no Judge module loaded. Contest module will unload.");
                Dispose();
            }
            else
            {
                Console.WriteLine("[contest] Contest module will use {0} as Judge.", Judge.Name);

                while (true)
                {
                    DataContext = new FudgeDataContext();

                    // Get all contests that have ended and are waiting for deferred judging
                    var contests = DataContext.Contests.Where(c => (c.Scoring & ContestScoring.DeferredJudging) == ContestScoring.DeferredJudging &&
                                                              c.EndTime < DateTime.UtcNow &&
                                                              c.Status != ContestStatus.Closed);
                    foreach (Contest contest in contests)
                    {
                        Console.WriteLine("[contest] Judging contest {0}", contest.ContestId);

                        foreach (ContestProblem problem in contest.ContestProblems)
                        {
                            var runs = problem.Problem.Runs.Where(p => p.ContestId == contest.ContestId);

                            Console.WriteLine("[contest] Judging contest problem {0}", problem.Problem.Name);

                            foreach (Run run in runs)
                            {
                                Thread judge = new Thread(Judge.Run);
                                judge.Start(run.RunId);
                            }
                        }

                        contest.Status = ContestStatus.Closed;
                        DataContext.SubmitChanges();
                    }

                    Thread.Sleep(30000);
                }
            }
        }
示例#17
0
    public static void ChangeUserStatus(this Team team, int userId, TeamUserStatus status)
    {
        FudgeDataContext db = new FudgeDataContext();

        var teamUser = FindTeamUser(db, userId, team.TeamId);

        teamUser.Status = status;

        db.SubmitChanges();
    }
示例#18
0
        //For AutoComplete
        public static IEnumerable <string> GetUsersByName(string name)
        {
            var db    = new FudgeDataContext();
            var users = from u in db.Users
                        let domain = u.School.Domain.Substring(0, u.School.Domain.IndexOf('.'))
                                     where (u.FirstName + " " + u.LastName).StartsWith(name)
                                     select(u.FirstName + " " + u.LastName) + " (" + domain + ")";

            return(users.Take(10));
        }
示例#19
0
        public static void SubscribeForReplies(this User user, int topicId)
        {
            FudgeDataContext db = new FudgeDataContext();

            db.TopicSubscriptions.InsertOnSubmit(new TopicSubscription {
                TopicId = topicId,
                UserId  = user.UserId
            });
            db.SubmitChanges();
        }
示例#20
0
        public static void RejectFriend(this User user, int friendId)
        {
            FudgeDataContext db = new FudgeDataContext();

            //reject the user
            var friendRelation = db.Friends.Single(f => f.UserId == friendId && f.FriendId == user.UserId);

            friendRelation.Status = FriendStatus.Rejected;

            db.SubmitChanges();
        }
示例#21
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);
        }
示例#22
0
        //creates a new rating and returns the id
        public static int NewRating()
        {
            FudgeDataContext db = new FudgeDataContext();
            var rating          = new Rating {
                Sum   = 0,
                Count = 0
            };

            db.Ratings.InsertOnSubmit(rating);
            db.SubmitChanges();
            return(rating.RatingId);
        }
示例#23
0
        public static void RequestJoinTeam(this User user, int teamId)
        {
            FudgeDataContext db = new FudgeDataContext();

            db.TeamUsers.InsertOnSubmit(new TeamUser {
                Status = TeamUserStatus.Requested,
                TeamId = teamId,
                UserId = user.UserId,
                Title  = null
            });
            db.SubmitChanges();
        }
示例#24
0
        public static bool SolvedWhenNew(this User user, int problemId)
        {
            FudgeDataContext db = new FudgeDataContext();

            var problem    = Problem.GetProblemById(problemId);
            var solvedRuns = from r in problem.SolvedRuns
                             where r.UserId == user.UserId &&
                             SqlMethods.DateDiffDay(problem.Timestamp.Date, r.Timestamp.Date) <= 20
                             select r;

            return(solvedRuns.Any());
        }
示例#25
0
        /// <summary>
        /// Deletes users from each other friend links i.e (Friend,User) and (User,Friend)
        /// </summary>
        /// <param name="friendId"></param>
        public static void RemoveFriend(this User user, int friendId)
        {
            FudgeDataContext db = new FudgeDataContext();

            var userToFriend = db.Friends.Single(f => f.UserId == user.UserId && f.FriendId == friendId);
            var friendToUser = db.Friends.Single(f => f.UserId == friendId && f.FriendId == user.UserId);

            db.Friends.DeleteOnSubmit(userToFriend);
            db.Friends.DeleteOnSubmit(friendToUser);

            db.SubmitChanges();
        }
示例#26
0
        public static int CreateFrom(string title, byte[] image)
        {
            FudgeDataContext db     = new FudgeDataContext();
            Picture          newPic = new Picture {
                Data  = new Binary(image),
                Title = title,
            };

            db.Pictures.InsertOnSubmit(newPic);
            db.SubmitChanges();
            return(newPic.PictureId);
        }
示例#27
0
        public static Notification PromoteToAdmin(int userId, int teamId)
        {
            FudgeDataContext db = new FudgeDataContext();
            var Team            = db.Teams.Single(t => t.TeamId == teamId);

            return(new Notification {
                Link = "http://fudge.fit.edu/Teams/" + teamId,
                Text = String.Format("You have been promted to admin of {0}", Team.Name),
                Timestamp = DateTime.UtcNow,
                Type = NotificationType.Default,
                UserId = userId
            });
        }
示例#28
0
        public static Notification DemoteToMember(int userId, int teamId)
        {
            FudgeDataContext db = new FudgeDataContext();
            var Team            = db.Teams.Single(t => t.TeamId == teamId);

            return(new Notification {
                Link = "http://fudge.fit.edu/Teams/" + teamId,
                Text = String.Format("You have been demoted by {0}", User.LoggedInUser.FirstName),
                Timestamp = DateTime.UtcNow,
                Type = NotificationType.Default,
                UserId = userId
            });
        }
示例#29
0
        public static Notification SourcePost(int runId)
        {
            FudgeDataContext db = new FudgeDataContext();
            var run             = db.Runs.SingleOrDefault(r => r.RunId == runId);

            return(new Notification {
                Link = "http://fudge.fit.edu/Problems/SourceView/" + run.RunId,
                Text = String.Format("{0} commented on your solution", User.LoggedInUser.FirstName),
                Timestamp = DateTime.UtcNow,
                Type = NotificationType.Default,
                UserId = run.UserId
            });
        }
示例#30
0
        public static Notification TopicReply(int topicId)
        {
            FudgeDataContext db = new FudgeDataContext();
            var topic           = db.Topics.SingleOrDefault(t => t.TopicId == topicId);

            return(new Notification {
                Link = "http://fudge.fit.edu/Community/Forum/Posts/" + topicId,
                Text = String.Format("{0} replied your post on {1}", User.LoggedInUser.FirstName, topic.Title),
                Timestamp = DateTime.UtcNow,
                Type = NotificationType.Default,
                UserId = topic.UserId
            });
        }