Ejemplo n.º 1
0
        public async Task UpdateAllCharacters()
        {
            try
            {
                logger.Log("Started UpdateAllCharacters job.");

                int  page                = 0;
                int  pageSize            = 100;
                long totalCharacterCount = await characterRepository.CountAsync(x => true);

                while (page * pageSize < totalCharacterCount)
                {
                    var characterCollection = await characterRepository.GetOrderedPageAsync(PredicateBuilder.True <Data.Model.Character>(), "MalId ASC", page, pageSize);

                    foreach (Data.Model.Character character in characterCollection.Results)
                    {
                        JikanDotNet.Character characterFullData = await SendSingleCharacterRequest(character.MalId, 0);

                        if (characterFullData != null)
                        {
                            logger.Log($"Parsed character with id {character.MalId}: {character.Name}");

                            await UpdateCharacter(character, characterFullData);
                        }
                        else
                        {
                            logger.Log($"Error on {character.MalId} - not found");
                            continue;
                        }
                    }

                    page++;
                }
                logger.Log("Finished UpdateAllCharacters job.");
            }
            catch (Exception ex)
            {
                logger.Log($"Exception: {ex.Message}");
            }
        }