Пример #1
0
        public void EventLoop()
        {
            while (events.Count > 0)
            {
                LoadTests   loader = new LoadTests();
                List <Test> tests  = new List <Test>();
                List <Test> tests1 = new List <Test>();

                tests  = loader.Get("B:\\tests\\adunare", "adunare");
                tests1 = loader.Get("B:\\tests\\ciurul", "ciurul");

                GCC gcc = new GCC(@"C:\MinGW\bin\g++.exe");
                CompilerFactory.RegisterCompiler("C++", gcc);
                CompilerFactory.RegisterCompiler("C++11", gcc);
                CompilerFactory.RegisterCompiler("C+11", gcc);

                CompilerFactory.RegisterCompiler("C++14", gcc);
                CompilerFactory.RegisterCompiler("C", gcc);



                tests.AddRange(tests1);
                Repository repository = new Repository();
                repository.Tests = tests;


                Judge          judge      = new Judge("B:\\evaluare", "C++", repository);
                SubmissionJson submission = events.Dequeue().Submission;

                submission.Code = submission.Code.Replace("@", System.Environment.NewLine);


                SaveSolution saveSolution = new SaveSolution(submission.Code, @"B:\solutions", submission.ProblemName + submission.SubmissionAccountId, "cpp");
                saveSolution.SaveFile();

                Dictionary <int, string> submissionsPaths = new Dictionary <int, string>();
                submissionsPaths[submission.Id] = saveSolution.GetCodePath();

                judge.SetSubmissionPath(submissionsPaths);

                judge.Evaluate(submission);
            }
        }
Пример #2
0
        static void Main(string[] args)
        {
            //EventQueue events = new EventQueue();
            //TcpServer.Queue = events;

            //TcpServer.Start();
            LoadTests   loader = new LoadTests();
            List <Test> tests  = new List <Test>();
            List <Test> tests1 = new List <Test>();

            tests  = loader.Get("B:\\tests\\adunare", "adunare");
            tests1 = loader.Get("B:\\tests\\ciurul", "ciurul");

            for (int i = 0; i < tests1.Count; ++i)
            {
                tests.Add(tests1[i]);
            }

            Repository repository = new Repository();

            repository.Tests = tests;

            Judge          judge      = new Judge("B:\\evaluare", "GCCCompiler", repository);
            SubmissionJson submission = new SubmissionJson
            {
                Code                = "#include <iostream> using namespace std; int main() { cout << 1 ; return 0; }",
                Language            = "C++",
                SubmissionAccountId = "1",
                SubmissionProblemId = 1
            };


            judge.Evaluate(submission);


            Console.Read();
        }
Пример #3
0
 private void StartJudge(IReadOnlyCollection <string> members, string dirPath, bool dirPlan, bool isStdInOut)
 {
     Task.Run(() =>
     {
         var start = DateTime.Now;
         while (!_isFinished)
         {
             var dTime = DateTime.Now - start;
             Dispatcher.Invoke(() =>
             {
                 TimeConsume.Content  = $"{dTime.Days * 24 + dTime.Hours}:{dTime.Minutes}:{dTime.Seconds}";
                 JudgingSpeed.Content =
                     $"{Math.Round(Convert.ToInt32(JudgingLog.Items.Count / 2) / (Math.Abs(dTime.TotalMinutes) < 1 ? 1 : dTime.TotalMinutes), MidpointRounding.AwayFromZero)} 题/分钟";
             });
             Thread.Sleep(1000);
         }
     });
     Task.Run(() =>
     {
         var all         = members.Count * _problems.Count(t => t.IsChecked);
         var cur         = -1;
         var myJudgeTask = new List <Task>();
         var cntLock     = new object();
         foreach (var t in members)
         {
             if (_stop)
             {
                 break;
             }
             var p = new JudgeResult
             {
                 MemberName = t,
                 Result     = new List <JudgeInfo>()
             };
             foreach (var m in _problems)
             {
                 if (_stop)
                 {
                     break;
                 }
                 if (!m.IsChecked)
                 {
                     continue;
                 }
                 string code;
                 string type;
                 try
                 {
                     if (dirPlan)
                     {
                         var codeFile = Directory.GetFiles(dirPath + "\\" + t).FirstOrDefault(f =>
                                                                                              Path.GetFileNameWithoutExtension(f) ==
                                                                                              Judge.GetEngName(m.ProblemName)) ??
                                        throw new InvalidOperationException();
                         code = File.ReadAllText(codeFile, Encoding.Default);
                         type = Configuration.Configurations.Compiler.FirstOrDefault(c =>
                                                                                     c.ExtName.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries)
                                                                                     .Any(d => string.Equals(d, Path.GetExtension(codeFile),
                                                                                                             StringComparison.CurrentCultureIgnoreCase)))
                                ?.DisplayName ??
                                throw new InvalidOperationException();
                     }
                     else
                     {
                         var codeFile =
                             Directory.GetFiles(dirPath + "\\" + t + "\\" + Judge.GetEngName(m.ProblemName))
                             .FirstOrDefault(f =>
                                             Path.GetFileNameWithoutExtension(f) ==
                                             Judge.GetEngName(m.ProblemName)) ??
                             throw new InvalidOperationException();
                         code = File.ReadAllText(codeFile, Encoding.Default);
                         type = Configuration.Configurations.Compiler.FirstOrDefault(c =>
                                                                                     c.ExtName.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries)
                                                                                     .Any(d => string.Equals(d, Path.GetExtension(codeFile),
                                                                                                             StringComparison.CurrentCultureIgnoreCase)))
                                ?.DisplayName ??
                                throw new InvalidOperationException();
                     }
                 }
                 catch
                 {
                     continue;
                 }
                 Connection.CanPostJudgTask = false;
                 myJudgeTask.Add(Task.Run(() =>
                 {
                     if (_stop)
                     {
                         return;
                     }
                     Dispatcher.Invoke(() =>
                     {
                         JudgingLog.Items.Add(new TextBlock
                         {
                             Text = $"{DateTime.Now:yyyy/MM/dd HH:mm:ss} 开始评测,题目:{m.ProblemName},评测选手:{t}"
                         });
                         JudgingLog.ScrollIntoView(JudgingLog.Items[JudgingLog.Items.Count - 1]);
                     });
                     var j = new Judge(m.ProblemId, 1, code, type, isStdInOut, $"离线评测,选手:{t}", null, 0);
                     p.Result.Add(j.JudgeResult);
                     Dispatcher.Invoke(() =>
                     {
                         lock (cntLock)
                         {
                             cur++;
                             JudgingProcess.Value = (double)cur * 100 / all;
                         }
                         JudgingLog.Items.Add(new TextBlock
                         {
                             Text =
                                 $"{DateTime.Now:yyyy/MM/dd HH:mm:ss} 评测完毕,题目:{m.ProblemName},评测选手:{t},结果:{j.JudgeResult.ResultSummary}"
                         });
                         JudgingLog.ScrollIntoView(JudgingLog.Items[JudgingLog.Items.Count - 1]);
                     });
                 }));