private Dictionary <int, SpojUserModel> ParseUsers(SpojDataTokenizer tokenizer)
        {
            var users  = new Dictionary <int, SpojUserModel>();
            var nUsers = tokenizer.GetInt();
            var nLines = tokenizer.GetInt();

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

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

            for (int i = 0; i < chunkSteps; i++)
            {
                for (int j = i * _chunkSize; j < (i + 1) * _chunkSize && j < nUsers; j++)
                {
                    var user = new SpojUserModel()
                    {
                        UserId      = tokenizer.GetInt(),
                        Username    = tokenizer.GetNext(),
                        DisplayName = tokenizer.GetNext(),
                        Email       = tokenizer.GetNext()
                    };
                    tokenizer.Skip(nLines - 4);
                    users[user.UserId] = user;

                    listChunk.Add(user);
                    listChunkIds.Add(user.UserId);
                }
                var ids         = listChunkIds;
                var listExist   = _accountRepository.Get(x => ids.Contains(x.SpojUserId)).Select(x => x.SpojUserId).ToList();
                var listEntites = listChunk.Where(x => !listExist.Contains(x.UserId)).Select(x => new AccountEntity
                {
                    SpojUserId  = x.UserId,
                    UserName    = x.Username,
                    DisplayName = x.DisplayName,
                    Email       = x.Email
                });

                _accountRepository.InsertRange(listEntites);
                _accountRepository.SaveChanges();

                listChunk    = new List <SpojUserModel>();
                listChunkIds = new List <int>();
            }

            return(users);
        }
        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 Dictionary <int, SpojProblemInfoModel> ParseProblems(SpojDataTokenizer tokenizer)
        {
            var prolems   = new Dictionary <int, SpojProblemInfoModel>();
            var nProblems = tokenizer.GetInt();
            var nLines    = tokenizer.GetInt();

            var listCheckingIds = new List <int>();

            var listChunk  = new List <SpojProblemInfoModel>();
            var chunkSteps = (int)Math.Ceiling((double)nProblems / _chunkSize);

            for (int i = 0; i < chunkSteps; i++)
            {
                for (int j = i * _chunkSize; j < (i + 1) * _chunkSize && j < nProblems; j++)
                {
                    var problemModel = new SpojProblemInfoModel()
                    {
                        Id         = tokenizer.GetInt(),
                        TimeLimit  = tokenizer.GetFloat(),
                        Code       = tokenizer.GetNext(),
                        Name       = tokenizer.GetNext(),
                        Type       = tokenizer.GetInt(),
                        ProblemSet = tokenizer.GetNext()
                    };

                    listChunk.Add(problemModel);
                    listCheckingIds.Add(problemModel.Id);

                    tokenizer.Skip(nLines - 6);
                    prolems[problemModel.Id] = problemModel;
                }

                var ids = listCheckingIds;

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

                var listEntitties = listChunk.Where(x => listNonExisting.Contains(x.Id)).Select(model => new ProblemEntity
                {
                    SpojId         = model.Id,
                    TimeLimit      = model.TimeLimit,
                    Code           = model.Code,
                    Name           = model.Name,
                    Type           = model.Type,
                    SpojProblemSet = model.ProblemSet
                })
                                    .ToList();

                _problemRepository.InsertRange(listEntitties);
                _problemRepository.SaveChanges();
                listChunk       = new List <SpojProblemInfoModel>();
                listCheckingIds = new List <int>();
                _problemCacheBusiness.AddRangeIds(listNonExisting);
            }
            _problemRepository.SaveChanges();


            return(prolems);
        }