private SpojContestModel ParseContest(SpojDataTokenizer tokenizer)
        {
            var nLines  = tokenizer.GetInt();
            var contest = new SpojContestModel()
            {
                Start = tokenizer.GetUnixTime(),
                End   = tokenizer.GetUnixTime(),
            };

            tokenizer.Skip(1);
            contest.Name = tokenizer.GetNext();
            tokenizer.Skip(nLines - 4);
            return(contest);
        }
        private void ParseUserSubmissions(SpojDataTokenizer tokenizer, Dictionary <int, SpojUserModel> users, Dictionary <int, SpojProblemInfoModel> problemsInfo)
        {
            var nSeries = tokenizer.GetInt();
            var nLine   = tokenizer.GetInt();

            tokenizer.Skip(1);
            var nSubmissions = tokenizer.GetInt();

            var listChunk    = new List <SpojSubmissionModel>();
            var listChunkIds = new List <int>();

            var chunkSteps = (int)Math.Ceiling((double)nSubmissions / _chunkSize);

            for (int i = 0; i < chunkSteps; i++)
            {
                for (int j = i * _chunkSize; j < (i + 1) * _chunkSize && j < nSubmissions; j++)
                {
                    var userId        = tokenizer.GetInt();
                    var spojProblemId = tokenizer.GetInt();
                    var time          = tokenizer.GetUnixTime();
                    var status        = tokenizer.GetInt();
                    var language      = tokenizer.GetInt();
                    var score         = tokenizer.GetFloat();
                    var runTime       = tokenizer.GetFloat();
                    tokenizer.Skip(1);
                    var id = tokenizer.GetInt();

                    var languageText = "";
                    switch (language)
                    {
                    case 10: languageText = "Java"; break;

                    case 27: languageText = "C#"; break;

                    case 32: languageText = "JS2"; break;

                    default: languageText = "Other Languages"; break;
                    }
                    tokenizer.Skip(nLine - 9);

                    if (!problemsInfo.ContainsKey(spojProblemId))
                    {
                        continue;
                    }
                    var problemInfo = problemsInfo[spojProblemId];

                    var submission = new SpojSubmissionModel
                    {
                        Id        = id,
                        Time      = time,
                        Score     = status == 15 && problemInfo.Type == 2 ? score : (status == 15 && problemInfo.Type == 0 ? 100 : 0),
                        RunTime   = runTime,
                        Language  = languageText,
                        UserId    = userId,
                        ProblemId = spojProblemId
                    };

                    listChunk.Add(submission);
                    listChunkIds.Add(submission.Id);

                    SpojUserModel user = null;
                    if (users.TryGetValue(userId, out user))
                    {
                        SpojProblemModel problem = null;
                        if (!user.Problems.TryGetValue(spojProblemId, out problem))
                        {
                            problem = new SpojProblemModel()
                            {
                                Id = spojProblemId, Code = problemInfo.Code
                            };
                            user.Problems[spojProblemId] = problem;
                        }
                        problem.Submissions.Add(submission);
                    }
                }

                var        ids             = listChunkIds;
                var        listIdsCache    = _submissionCacheBusiness.GetIds();
                List <int> listNonExisting = new List <int>();
                foreach (var id in listChunkIds)
                {
                    if (!listIdsCache.Contains(id))
                    {
                        listNonExisting.Add(id);
                    }
                }

                var listNotExist = listChunk.Where(x => listNonExisting.Contains(x.Id));

                var listEntities = (from item in listNotExist
                                    let internalProblemId = _problemRepository.Get(x => x.SpojId == item.ProblemId).Select(x => x.Id).FirstOrDefault()
                                                            let internalAccountId = _accountRepository.Get(x => x.SpojUserId == item.UserId).Select(x => x.Id).FirstOrDefault()
                                                                                    select new SubmissionEntity
                {
                    SpojId = item.Id,
                    SubmitTime = item.Time,
                    Score = item.Score,
                    RunTime = item.RunTime,
                    Language = item.Language,
                    ProblemId = internalProblemId == 0 ? (int?)null : internalProblemId,
                    AccountId = internalAccountId == 0 ? (int?)null : internalAccountId
                }).ToList();
                _submissionRepository.InsertRange(listEntities);
                _submissionRepository.SaveChanges();

                listChunk    = new List <SpojSubmissionModel>();
                listChunkIds = new List <int>();
                _submissionCacheBusiness.AddRangeIds(listNonExisting);
            }
        }