Esempio n. 1
0
 public Validator(List <School> sl, List <Group> gl, List <TeamInfo> ti, List <Problem> p,
                  List <SubmissionWithResult> swr, ContestInfo ci)
 {
     this.SchoolsList  = sl;
     this.GroupsList   = gl;
     this.TeamsList    = ti;
     this.ProblemsList = p;
     this.SubmissionWithResultsList = swr;
     this.ContestInfo = ci;
 }
Esempio n. 2
0
 public Validator(string pathToJson)
 {
     JsonFileStream            = new StreamReader(pathToJson);
     SchoolsList               = new List <School>();
     GroupsList                = new List <Group>();
     TeamsList                 = new List <TeamInfo>();
     ProblemsList              = new List <Problem>();
     ReturnSummaryList         = new List <ReturnSummary>();
     SubmissionWithResultsList = new List <SubmissionWithResult>();
     ContestInfo               = new ContestInfo();
 }
Esempio n. 3
0
        public void LoadAllEventData()
        {
            string jsonLine;

            while ((jsonLine = JsonFileStream.ReadLine()) != null)
            {
                var    jsonLoader = JObject.Parse(jsonLine);
                JToken dataType = jsonLoader["type"], opType = jsonLoader["op"], opData = jsonLoader["data"];
                if (dataType != null)
                {
                    switch (dataType.ToString())
                    {
                    case "organizations":
                        var school = opData.ToObject <School>();
                        if (opType.ToString() == "create")
                        {
                            SchoolsList.Add(school);
                        }
                        else if (opType.ToString() == "update")
                        {
                            var idx = SchoolsList.FindIndex(x => x.id == school.id);
                            if (idx != -1)
                            {
                                SchoolsList[idx] = school;
                            }
                            else
                            {
                                SchoolsList.Add(school);
                            }
                        }
                        break;

                    case "groups":
                        var group = opData.ToObject <Group>();
                        if (opType.ToString() == "create")
                        {
                            GroupsList.Add(group);
                        }
                        else if (opType.ToString() == "update")
                        {
                            var idx = GroupsList.FindIndex(x => x.id == group.id);
                            if (idx != -1)
                            {
                                GroupsList[idx] = group;
                            }
                            else
                            {
                                GroupsList.Add(group);
                            }
                        }
                        break;

                    case "teams":
                        var team = opData.ToObject <TeamInfo>();
                        if (opType.ToString() == "create")
                        {
                            TeamsList.Add(team);
                        }
                        else if (opType.ToString() == "update")
                        {
                            var idx = TeamsList.FindIndex(x => x.id == team.id);
                            if (idx != -1)
                            {
                                TeamsList[idx] = team;
                            }
                            else
                            {
                                TeamsList.Add(team);
                            }
                        }
                        break;

                    case "problems":
                        var problem = opData.ToObject <Problem>();
                        if (opType.ToString() == "create")
                        {
                            ProblemsList.Add(problem);
                        }
                        else if (opType.ToString() == "update")
                        {
                            var idx = ProblemsList.FindIndex(x => x.id == problem.id);
                            if (idx != -1)
                            {
                                ProblemsList[idx] = problem;
                            }
                            else
                            {
                                ProblemsList.Add(problem);
                            }
                        }
                        else if (opType.ToString() == "delete")
                        {
                            ProblemsList.RemoveAt(ProblemsList.FindIndex(x => x.id == opType["id"]?.ToString()));
                        }
                        break;

                    case "submissions":
                        var submission = opData.ToObject <Submission>();
                        if (opType.ToString() == "delete")
                        {
                            SubmissionWithResultsList.RemoveAt(
                                SubmissionWithResultsList.FindIndex(x => x.id == opData["id"]?.ToString()));
                        }
                        else
                        {
                            var submissionWithResult = new SubmissionWithResult(submission);
                            SubmissionWithResultsList.Add(submissionWithResult);
                        }

                        break;

                    case "judgements":
                        string submissionId = opData["submission_id"].ToString(),
                               judgeResult  = opData["judgement_type_id"].ToString();
                        SubmissionWithResultsList.First(x => x.id == submissionId).judgeResult = judgeResult;
                        break;

                    case "contests":
                        ContestInfo = opData.ToObject <ContestInfo>();
                        break;

                    default:
                        break;
                    }
                }
            }
        }