Esempio n. 1
0
 public HackStateMachineHandler(OnlineJudgeContext db, IHubContext <OnlineJudgeHub> hub, ManagementServiceClient mgmt, ContestExecutorFactory cef)
 {
     _db   = db;
     _hub  = hub;
     _mgmt = mgmt;
     _cef  = cef;
 }
 public ContestExecutorFactory(OnlineJudgeContext db, SmartUser <User, Guid> user, ManagementServiceClient mgmt, IConfiguration config)
 {
     this._db     = db;
     this._user   = user;
     this._mgmt   = mgmt;
     this._config = config;
 }
Esempio n. 3
0
        static async Task MainAsync(CancellationToken token)
        {
            var connStr = JsonConvert.DeserializeObject <dynamic>(File.ReadAllText("config.json")).Oj;
            var builder = new DbContextOptionsBuilder <OnlineJudgeContext>();

            builder.UseMySql((string)connStr);
            var cnt = 0;

            using (var db = new OnlineJudgeContext(builder.Options))
            {
                var problemIds = await db.Problems
                                 .Where(x => x.Source == ProblemSource.Local)
                                 .Select(x => x.Id)
                                 .ToListAsync(token);

                var mgmt = new ManagementServiceClient("https://mgmtsvc.1234.sh", @"C:\Users\Yuko\Documents\webapi-client.pfx", "123456");

                var tasks  = new List <Task>();
                var cancel = new CancellationTokenSource();
                var ret    = new ConcurrentBag <(string, Guid)>();
                foreach (var id in problemIds)
                {
                    cnt++;
                    if (cnt % 10 == 0)
                    {
                        Console.WriteLine(cnt + " problems handled.");
                    }

                    foreach (var x in await db.TestCases.Where(x => x.ProblemId == id).ToListAsync(token))
                    {
                        tasks.Add(Task.Run(async() => {
                            try
                            {
                                await mgmt.GetBlobAsync(x.InputBlobId);
                            }
                            catch
                            {
                                ret.Add((x.ProblemId, x.InputBlobId));
                                Console.WriteLine("[Failed] " + x.ProblemId + ", input id = " + x.InputBlobId);
                            }
                            try
                            {
                                await mgmt.GetBlobAsync(x.OutputBlobId);
                            }
                            catch
                            {
                                ret.Add((x.ProblemId, x.OutputBlobId));
                                Console.WriteLine("[Failed] " + x.ProblemId + ", output id = " + x.OutputBlobId);
                            }
                        }));
                    }
                    await Task.WhenAll(tasks);
                }

                File.WriteAllText("result.txt", string.Join("\r\n", ret.Select(x => x.Item1 + " " + x.Item2)));
            }
        }
Esempio n. 4
0
 static void Main(string[] args)
 {
     while (true)
     {
         var id      = Guid.Parse(Console.ReadLine());
         var builder = new DbContextOptionsBuilder <OnlineJudgeContext>();
         var connStr = JsonConvert.DeserializeObject <dynamic>(File.ReadAllText("config.json")).Oj;
         builder.UseMySql((string)connStr);
         using (var db = new OnlineJudgeContext(builder.Options))
         {
             var statemachineId = db.JudgeStatusStateMachines.Where(x => x.StatusId == id).Last().StateMachineId;
             var mgmt           = new ManagementServiceClient("https://mgmtsvc.1234.sh", @"C:\Users\Yuko\Documents\webapi-client.pfx", "123456");
             mgmt.PatchStateMachineInstanceAsync(statemachineId, "Start");
             Console.WriteLine("OK");
         }
     }
 }
Esempio n. 5
0
        static void FixOneUser(string username, OnlineJudgeContext db)
        {
            Console.WriteLine("Processing user: "******"User: "******" has been fixed");
        }
Esempio n. 6
0
        static void Main(string[] args)
        {
            var builder = new DbContextOptionsBuilder <OnlineJudgeContext>();

            Console.WriteLine("Please input the connection string of Joy OI online judge database.");
            Console.Write("Connection string=");
            builder.UseMySql(Console.ReadLine());
            builder.UseMySqlLolita();
            var db = new OnlineJudgeContext(builder.Options);

            Console.WriteLine("1=Fix specified user, 2=Fix register after time");
            Console.Write("Your choice=");
            var choice = Convert.ToInt16(Console.ReadLine());

            if (choice == 1)
            {
                Console.WriteLine("Please input the user which you want to fix.");
                Console.Write("Username="******"Please input the time(YYYY-MM-DD).");
                Console.Write("Time=");

                var time  = Convert.ToDateTime(Console.ReadLine());
                var users = db.Users
                            .Where(x => x.RegisteryTime >= time)
                            .Select(x => x.UserName)
                            .ToList();

                foreach (var x in users)
                {
                    FixOneUser(x, db);
                }
            }
            Console.WriteLine("Hello World!");
        }
Esempio n. 7
0
 public JudgeStateMachineHandler(OnlineJudgeContext db, IHubContext <OnlineJudgeHub> hub, ManagementServiceClient mgmt)
 {
     _db   = db;
     _hub  = hub;
     _mgmt = mgmt;
 }
        public static async Task <IDictionary <string, ProblemStatisticsValue> > GenerateAsync(OnlineJudgeContext db, string groupId, IEnumerable <string> problemIds, CancellationToken token)
        {
            var ret = new Dictionary <string, ProblemStatisticsValue>();
            var pid = $"({string.Join(',', problemIds.Select(x => $"'{x}'"))})";
            var sql = $"SELECT `ProblemId`, `Result` = 0 AS `IsAccepted`, Sum(1) AS `Count` FROM `JudgeStatuses` WHERE `ProblemId` IN {pid} AND `GroupId` = '{groupId}' GROUP BY `ProblemId`, `Result` = 0";

            using (MySqlConnection conn = (MySqlConnection)db.Database.GetDbConnection())
            {
                try { await conn.OpenAsync(token); }
                catch { }
                using (var cmd = new MySqlCommand(sql, conn))
                    using (var reader = await cmd.ExecuteReaderAsync(token))
                    {
                        while (await reader.ReadAsync(token))
                        {
                            var problemId = reader.GetString(0);
                            if (!ret.ContainsKey(problemId))
                            {
                                ret.Add(problemId, new ProblemStatisticsValue());
                            }

                            if (reader.GetInt32(1) == 1)
                            {
                                ret[problemId].Accepted = reader.GetInt32(2);
                            }
                            else
                            {
                                ret[problemId].NonAccepted = reader.GetInt32(2);
                            }
                        }
                    }
            }
            return(ret);
        }