private List <Item> FetchMostUsedItems(string heroReference) { HtmlNode root = HtmlDocumentController.GetDotabuffHeroRoot(heroReference); IEnumerable <HtmlNode> mostUsedItemNodes = root.SelectNodes(HeroPath.MostUsedItems.List.Value); List <Item> mostUsedItems = new List <Item>(); foreach (HtmlNode node in mostUsedItemNodes) { string itemReference = HtmlEntity.DeEntitize(node.Attributes[HtmlAttributes.MostUsedItem.Attribute.Value].Value).Replace(HtmlAttributes.MostUsedItem.Replace.Value, ""); mostUsedItems.Add(mainController.ItemController.GetItem(itemReference)); } return(mostUsedItems); }
private List <Roles> FetchRoles(string heroReference) { HtmlNode root = HtmlDocumentController.GetDotabuffHeroRoot(heroReference); string roles = root.SelectSingleNode(HeroPath.General.Roles.Value).InnerText; string[] rolesSplit = roles.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); List <Roles> roleList = new List <Roles>(); foreach (string role in rolesSplit) { roleList.Add(mainController.MapStringToEnum <Roles>(role)); } return(roleList); }
internal List <AbilityBuild> FetchMostPopularAbilityBuild(string heroReference) { HtmlNode root = HtmlDocumentController.GetDotabuffHeroRoot(heroReference); IList <HtmlNode> mostPopularAbilityBuildNodes = root.SelectNodes(HeroPath.MostPopularAbilitBuild.Abilities.Value); IList <HtmlNode> mostPopularAbilityBuildIconNodes = root.SelectNodes(HeroPath.MostPopularAbilitBuild.Icons.Value); List <Ability> abilities = FetchAbilities(heroReference); List <AbilityBuild> abilityBuildList = new List <AbilityBuild>(); for (int i = 0; i < mostPopularAbilityBuildNodes.Count(); i++) { AbilityBuild abilityBuild = new AbilityBuild(); string abilityName = HtmlEntity.DeEntitize(mostPopularAbilityBuildIconNodes[i].Attributes["alt"].Value); abilityBuild.Ability = abilities.First(ability => ability.Name.Contains(abilityName)); abilityBuild.LevelBuild = new List <int>(); IEnumerable <HtmlNode> levelBuildNodes = mostPopularAbilityBuildNodes[i].Descendants("div") .Where( d => d.Attributes.Contains("class") && d.Attributes["class"].Value.Contains("entry choice")); List <int> abilityLevelBuild = new List <int>(); foreach (HtmlNode levelBuildNode in levelBuildNodes) { abilityLevelBuild.Add(int.Parse(levelBuildNode.InnerText)); } abilityBuild.LevelBuild = abilityLevelBuild; abilityBuildList.Add(abilityBuild); } return(abilityBuildList); }
public Hero GetExtendedHero(Heroes heroEnum) { Hero hero = mappedHeros.Find(h => h.HeroEnum == heroEnum); if (hero.WinRate == null || hero.Popularity == null || hero.Image == null) { HtmlNode root = HtmlDocumentController.GetDotabuffHeroRoot(hero.Reference); hero.WinRate = mainController.ConvertStringToWinRate(root.SelectSingleNode(HeroPath.General.WinRate.Value).InnerText); hero.Popularity = mainController.ConvertStringToPopularity(root.SelectSingleNode(HeroPath.General.Popularity.Value).InnerText); string url = UrlPath.Main + root.SelectSingleNode(HeroPath.General.Image.Value).Attributes[MainController.HTML_ATTRIBUTE_SRC].Value; using (WebClient webclient = HtmlDocumentController.CreateWebclient()) { hero.Image = webclient.DownloadData(url); } } if (hero.Abilities == null) { hero.Abilities = abilityController.FetchAbilities(hero.Reference); } if (hero.MostPopularAbilityBuild == null) { hero.MostPopularAbilityBuild = abilityController.FetchMostPopularAbilityBuild(hero.Reference); } if (hero.Roles == null) { hero.Roles = FetchRoles(hero.Reference); } if (hero.Attributes == null) { hero.Attributes = attributeController.FetchAttributes(hero.Reference); } if (hero.LanePresence == null) { hero.LanePresence = lanePresenceController.FetchLanePresence(hero.Reference); } if (hero.BestVersus == null) { hero.BestVersus = AttachHeroesToVersus(versusController.FetchBestVersus(hero.Reference), hero.Reference); } if (hero.WorstVersus == null) { hero.WorstVersus = AttachHeroesToVersus(versusController.FetchWorstVersus(hero.Reference), hero.Reference); } if (hero.MostUsedItems == null) { hero.MostUsedItems = FetchMostUsedItems(hero.Reference); } return(hero); }