Пример #1
0
 public void BeHackedPush(HackResult result)
 {
     System.Threading.Tasks.Task.Factory.StartNew(() =>
     {
         App.Current.Dispatcher.Invoke(new Action(() =>
         {
             new ModernDialog
             {
                 Title = "Your program has been hacked",
                 Content = new CenaPlus.Client.Remote.Contest.HackPush(result)
             }.ShowDialog();
         }));
     });
     if (OnBeHacked != null)
     {
         System.Threading.Tasks.Task.Factory.StartNew(() => OnBeHacked(result.RecordID));
     }
 }
Пример #2
0
 public void HackResultPush(HackResult result)
 {
     System.Threading.Tasks.Task.Factory.StartNew(() =>
     {
         if (result.HackerUserID == App.Server.GetProfile().ID)
         {
             App.Current.Dispatcher.Invoke(new Action(() =>
             {
                 new ModernDialog
                 {
                     Title = "Your hack action has a new status.",
                     Content = new CenaPlus.Client.Remote.Contest.HackFinishedPush(result)
                 }.ShowDialog();
             }));
         }
     });
     if (OnHackFinished != null)
     {
         System.Threading.Tasks.Task.Factory.StartNew(() => OnHackFinished(result));
     }
 }
Пример #3
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);
             });
         }
     }
 }