Exemplo n.º 1
0
 public void StandingsPush(int contest_id, Entity.StandingItem si)
 {
     if (Bll.StandingsCache.Standings[contest_id] == null)
     {
         System.Threading.Tasks.Task.Factory.StartNew(() =>
         {
             App.Current.Dispatcher.Invoke(new Action(() =>
             {
                 App.Server.GetStandings(contest_id);
             }));
         });
     }
     else
     {
         StandingsCache.UpdateSingleUser(contest_id, si);
     }
     if (OnStandingPushed != null)
     {
         System.Threading.Tasks.Task.Factory.StartNew(() => OnStandingPushed(contest_id, si));
     }
 }
Exemplo n.º 2
0
 public void HackFinished(int hack_id)
 {
     using (DB db = new DB())
     {
         Hack hack = (from h in db.Hacks
                      where h.ID == hack_id
                      select h).FirstOrDefault();
         HackResult re = new HackResult()
         {
             HackID               = hack.ID,
             DefenderUserID       = hack.HackeeID,
             DefenderUserNickName = hack.Record.User.NickName,
             HackerUserID         = hack.HackerID,
             HackerUserNickName   = (from u in db.Users where u.ID == hack.HackerID select u.NickName).FirstOrDefault(),
             Status               = hack.Status,
             RecordID             = hack.RecordID,
             ProblemTitle         = hack.Record.Problem.Title,
             Time = hack.Time
         };
         var contest_id = hack.Record.Problem.ContestID;
         if (hack.Status == HackStatus.Success)
         {
             System.Threading.Tasks.Task.Factory.StartNew(() =>
             {
                 LocalCenaServer client;
                 if (App.Clients.TryGetValue(hack.HackeeID, out client))
                 {
                     client.Callback.BeHackedPush(re);
                 }
             });
             StandingsCache.UpdateSingleDetail(hack.HackeeID, hack.Record.ProblemID, contest_id, hack.Record.Problem.Contest.Type);
             foreach (var client in App.Clients.Values)
             {
                 System.Threading.Tasks.Task.Factory.StartNew(() =>
                 {
                     client.Callback.StandingsPush(contest_id, (StandingsCache.Standings[contest_id] as List <Entity.StandingItem>).Find(x => x.UserID == hack.HackeeID));
                 });
             }
         }
         if (hack.Status == HackStatus.Success || hack.Status == HackStatus.Failure)
         {
             StandingsCache.UpdateSingleUser(hack.HackerID, contest_id, (from p in db.Problems
                                                                         where p.ContestID == contest_id
                                                                         orderby p.Score ascending
                                                                         select p.ID).ToList());
             foreach (var client in App.Clients.Values)
             {
                 System.Threading.Tasks.Task.Factory.StartNew(() =>
                 {
                     client.Callback.StandingsPush(contest_id, (StandingsCache.Standings[contest_id] as List <Entity.StandingItem>).Find(x => x.UserID == hack.HackerID));
                 });
             }
         }
         foreach (var client in App.Clients.Values)
         {
             System.Threading.Tasks.Task.Factory.StartNew(() =>
             {
                 client.Callback.HackResultPush(re);
             });
         }
     }
 }
Exemplo n.º 3
0
        public void JudgeFinished(int record_id)
        {
            using (DB db = new DB())
            {
                Record record = (from r in db.Records
                                 where r.ID == record_id
                                 select r).FirstOrDefault();
                var Type = record.Problem.Contest.Type;
                if (Type == ContestType.OI)
                {
                    return;
                }
                var    dtl = (record.Problem.Contest.Type == ContestType.ACM && record.Status != RecordStatus.CompileError ? "" : record.Detail);
                Result re  = new Result()
                {
                    StatusID       = record.ID,
                    Status         = record.Status,
                    TimeUsage      = record.TimeUsage,
                    MemoryUsage    = record.MemoryUsage,
                    UserID         = record.UserID,
                    SubmissionTime = record.SubmissionTime,
                    UserNickName   = record.UserNickName,
                    Detail         = dtl,
                    Language       = record.Language,
                    ProblemTitle   = record.Problem.Title
                };
                System.Threading.Tasks.Task.Factory.StartNew(() =>
                {
                    LocalCenaServer client;
                    if (App.Clients.TryGetValue(record.UserID, out client))
                    {
                        client.Callback.JudgeFinished(re);
                    }
                });

                // Push to remote management servers
                foreach (var s in App.Clients.Values.Where(s => s.SessionMode == LocalCenaServer.SessionType.Server))
                {
                    System.Threading.Tasks.Task.Factory.StartNew(() => s.Callback.JudgeFinished(re));
                }

                if (StandingsCache.Standings[record.Problem.ContestID] == null)
                {
                    StandingsCache.Rebuild(record.Problem.ContestID);
                }
                var userindex = (StandingsCache.Standings[record.Problem.ContestID] as List <Entity.StandingItem>).FindIndex(x => x.UserID == record.UserID);
                if (userindex == -1)
                {
                    StandingsCache.UpdateSingleUser(record.UserID, record.Problem.ContestID, (from p in db.Problems where p.ContestID == record.Problem.ContestID select p.ID).ToList());
                }
                else
                {
                    StandingsCache.UpdateSingleDetail(record.UserID, record.ProblemID, record.Problem.ContestID, Type);
                }
                foreach (var c in App.Clients.Values)
                {
                    System.Threading.Tasks.Task.Factory.StartNew(() =>
                    {
                        c.Callback.StandingsPush(record.Problem.ContestID, (StandingsCache.Standings[record.Problem.ContestID] as List <Entity.StandingItem>).Find(x => x.UserID == record.UserID));
                    });
                }
            }
        }