public IEnumerable <AltemaCharacterInfo> GetAltemaCharacterInfos()
        {
            _logger.LogInformation($"Logic Method invoked: {nameof(GetAltemaCharacterInfos)}");

            string cacheKey = nameof(GetAltemaCharacterInfos);
            IEnumerable <AltemaCharacterInfo> results = _cacheProvider.ObjectGet <IList <AltemaCharacterInfo> >(cacheKey);

            if (results == null)
            {
                IList <AltemaCharacterInfo> altemaCharacterInfos = new List <AltemaCharacterInfo>();

                //Stream
                //Stream altemaCharacterRatingStream = _altemaCharacterRatingRepository.GetAltemaCharacterRatingStream();
                ////don't fail if we can't contact the altema page
                //if (altemaCharacterRatingStream == null) { return altemaCharacterInfos; }

                //HtmlDocument htmlDoc = GetLoadedHtmlDocument(altemaCharacterRatingStream);

                //String
                string altemaCharacterRatingString = _altemaCharacterRatingRepository.GetAltemaCharacterRatingString();

                //don't fail if we can't contact the altema page
                if (altemaCharacterRatingString == null)
                {
                    return(altemaCharacterInfos);
                }

                HtmlDocument htmlDoc = GetLoadedHtmlDocument(altemaCharacterRatingString);

                IEnumerable <HtmlNode> characterNodes = GetCharacterNodes(htmlDoc);

                int altemaOrder = 1;
                foreach (HtmlNode node in characterNodes)
                {
                    AltemaCharacterNodeComponents characterNodeComponents = _altemaCharacterNodeParser.ParseCharacterNode(node);
                    AltemaCharacterInfo           characterInfo           = _altemaCharacterNodeInterpreter.ConvertCharacterNodeToCharacterInfo(characterNodeComponents);

                    if (characterInfo != null)
                    {
                        characterInfo.AltemaOrder = altemaOrder++;
                        altemaCharacterInfos.Add(characterInfo);
                    }
                }

                results = altemaCharacterInfos;

                _cacheProvider.ObjectSet(cacheKey, results);
            }

            return(results);
        }
Beispiel #2
0
        public AltemaCharacterInfo ConvertCharacterNodeToCharacterInfo(AltemaCharacterNodeComponents characterNodeComponents)
        {
            AltemaCharacterInfo characterInfo = null;


            if (characterNodeComponents != null && characterNodeComponents.IsRatedCharacter) //IsRatedCharacter makes sure important fields are not null
            {
                characterInfo = new AltemaCharacterInfo()
                {
                    Id                  = characterNodeComponents.CharacterIdAttribute.Value,
                    ImageUrl            = GetImageUrl(characterNodeComponents),
                    JapaneseName        = characterNodeComponents.NameNode.InnerText.Trim(),
                    Rating              = System.Convert.ToInt32(characterNodeComponents.RatingNode.InnerText.Trim()),
                    JapaneseRoleSummary = characterNodeComponents.RoleNode.InnerText.Trim(),
                    Name                = _altemaCharacterJapaneseTextMapper.GetCharacterNameFromId(characterNodeComponents.CharacterIdAttribute.Value) ?? characterNodeComponents.NameNode.InnerText.Trim(),
                    RoleSummary         = _altemaCharacterJapaneseTextMapper.GetRoleSummaryFromJapaneseRoleSummary(characterNodeComponents.RoleNode.InnerText.Trim())
                };

                characterInfo.Roles = _altemaCharacterJapaneseTextMapper.GetRolesFromJapaneseRoleSummary(characterInfo.JapaneseRoleSummary);
            }

            return(characterInfo);
        }