Exemplo n.º 1
0
        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);
        }