mirror of
				https://github.com/Nioux/AideDeJeu.git
				synced 2025-10-31 15:36:07 +00:00 
			
		
		
		
	Abandon du HTML Agility Pack ( pour l'instant ;) )
This commit is contained in:
		
							parent
							
								
									2ba11fc99f
								
							
						
					
					
						commit
						20b1366e92
					
				
					 15 changed files with 1275 additions and 1273 deletions
				
			
		|  | @ -45,7 +45,6 @@ | ||||||
|   </ItemGroup> |   </ItemGroup> | ||||||
| 
 | 
 | ||||||
|   <ItemGroup> |   <ItemGroup> | ||||||
|     <PackageReference Include="HtmlAgilityPack" Version="1.8.4" /> |  | ||||||
|     <PackageReference Include="SkiaSharp.Views.Forms" Version="1.60.1" /> |     <PackageReference Include="SkiaSharp.Views.Forms" Version="1.60.1" /> | ||||||
|     <PackageReference Include="Xamarin.Forms" Version="3.0.0.482510" /> |     <PackageReference Include="Xamarin.Forms" Version="3.0.0.482510" /> | ||||||
|   </ItemGroup> |   </ItemGroup> | ||||||
|  |  | ||||||
|  | @ -1,7 +1,7 @@ | ||||||
| using AideDeJeuLib.Spells; | using AideDeJeuLib.Spells; | ||||||
| using HtmlAgilityPack; |  | ||||||
| using System.Collections.Generic; | using System.Collections.Generic; | ||||||
| using System.Linq; | using System.Linq; | ||||||
|  | using System.Xml; | ||||||
| 
 | 
 | ||||||
| namespace AideDeJeuLib.Cards | namespace AideDeJeuLib.Cards | ||||||
| { | { | ||||||
|  | @ -66,14 +66,15 @@ namespace AideDeJeuLib.Cards | ||||||
|             return texts.ToArray(); |             return texts.ToArray(); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         public static CardContent[] ToContents(HtmlNode description) |         public static CardContent[] ToContents(XmlNode description) | ||||||
|         { |         { | ||||||
|             var contents = new List<CardContent>(); |             var contents = new List<CardContent>(); | ||||||
|             string currentText = ""; |             string currentText = ""; | ||||||
|             foreach (var content in description.ChildNodes) |             foreach (var contentt in description.ChildNodes) | ||||||
|             { |             { | ||||||
|  |                 var content = contentt as XmlNode; | ||||||
|                 //Debug.WriteLine(content.NodeType + " " + content.Name + " " + content.InnerText); |                 //Debug.WriteLine(content.NodeType + " " + content.Name + " " + content.InnerText); | ||||||
|                 if ((content.NodeType == HtmlNodeType.Element || content.NodeType == HtmlNodeType.Document) && content.Name == "strong") |                 if ((content.NodeType == XmlNodeType.Element || content.NodeType == XmlNodeType.Document) && content.Name == "strong") | ||||||
|                 { |                 { | ||||||
|                     if (currentText.Length > 0) |                     if (currentText.Length > 0) | ||||||
|                     { |                     { | ||||||
|  | @ -82,11 +83,11 @@ namespace AideDeJeuLib.Cards | ||||||
|                     } |                     } | ||||||
|                     contents.Add(new SectionCardContent(content.InnerText)); |                     contents.Add(new SectionCardContent(content.InnerText)); | ||||||
|                 } |                 } | ||||||
|                 else if ((content.NodeType == HtmlNodeType.Element || content.NodeType == HtmlNodeType.Document) && content.Name == "em") |                 else if ((content.NodeType == XmlNodeType.Element || content.NodeType == XmlNodeType.Document) && content.Name == "em") | ||||||
|                 { |                 { | ||||||
|                     currentText += "<em>" + content.InnerText + "</em>"; |                     currentText += "<em>" + content.InnerText + "</em>"; | ||||||
|                 } |                 } | ||||||
|                 else if (content.NodeType == HtmlNodeType.Text) |                 else if (content.NodeType == XmlNodeType.Text) | ||||||
|                 { |                 { | ||||||
|                     var texts = SplitText(content.InnerText); |                     var texts = SplitText(content.InnerText); | ||||||
|                     for (int i = 0; i < texts.Length - 1; i++) |                     for (int i = 0; i < texts.Length - 1; i++) | ||||||
|  | @ -143,7 +144,7 @@ namespace AideDeJeuLib.Cards | ||||||
|                 //new FillCardContent(1), |                 //new FillCardContent(1), | ||||||
|                 //new TextCardContent(spell.DescriptionText), |                 //new TextCardContent(spell.DescriptionText), | ||||||
|             }); |             }); | ||||||
|             var description = ToContents(spell.DescriptionDiv.Element("div")); |             var description = ToContents(spell.DescriptionDiv.SelectSingleNode("div")); | ||||||
|             foreach (var line in description) |             foreach (var line in description) | ||||||
|             { |             { | ||||||
|                 int size = contents.Sum(cc => cc.Height); |                 int size = contents.Sum(cc => cc.Height); | ||||||
|  |  | ||||||
|  | @ -1,5 +1,5 @@ | ||||||
| using HtmlAgilityPack; | using System.Collections.Generic; | ||||||
| using System.Collections.Generic; | using System.Xml; | ||||||
| 
 | 
 | ||||||
| namespace AideDeJeuLib | namespace AideDeJeuLib | ||||||
| { | { | ||||||
|  | @ -13,23 +13,23 @@ namespace AideDeJeuLib | ||||||
|         public string NamePHB { get; set; } |         public string NamePHB { get; set; } | ||||||
|         public string Html { get; set; } |         public string Html { get; set; } | ||||||
| 
 | 
 | ||||||
|         public static IEnumerable<string> NodeListToStringList(IEnumerable<HtmlNode> nodes) |         public static IEnumerable<string> NodeListToStringList(IEnumerable<XmlNode> nodes) | ||||||
|         { |         { | ||||||
|             if (nodes == null) return null; |             if (nodes == null) return null; | ||||||
|             var strings = new List<string>(); |             var strings = new List<string>(); | ||||||
|             foreach (var node in nodes) |             foreach (var node in nodes) | ||||||
|             { |             { | ||||||
|                 strings.Add(node.OuterHtml); |                 strings.Add(node.OuterXml); | ||||||
|             } |             } | ||||||
|             return strings; |             return strings; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         public static HtmlNode StringToNode(string str) |         public static XmlNode StringToNode(string str) | ||||||
|         { |         { | ||||||
|             if (str == null) return null; |             if (str == null) return null; | ||||||
|             var doc = new HtmlDocument(); |             var doc = new XmlDocument(); | ||||||
|             doc.LoadHtml(str); |             doc.LoadXml(str); | ||||||
|             return doc.DocumentNode; |             return doc.DocumentElement; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         //public static IEnumerable<HtmlNode> StringListToNodeList(IEnumerable<string> strings) |         //public static IEnumerable<HtmlNode> StringListToNodeList(IEnumerable<string> strings) | ||||||
|  |  | ||||||
|  | @ -1,8 +1,8 @@ | ||||||
| using HtmlAgilityPack; | using System.Collections.Generic; | ||||||
| using System.Collections.Generic; |  | ||||||
| using System.Linq; | using System.Linq; | ||||||
| using System.Runtime.Serialization; | using System.Runtime.Serialization; | ||||||
| using System.Text.RegularExpressions; | using System.Text.RegularExpressions; | ||||||
|  | using System.Xml; | ||||||
| 
 | 
 | ||||||
| namespace AideDeJeuLib.Monsters | namespace AideDeJeuLib.Monsters | ||||||
| { | { | ||||||
|  | @ -52,7 +52,7 @@ namespace AideDeJeuLib.Monsters | ||||||
| 
 | 
 | ||||||
|         public IEnumerable<string> SpecialFeatures { get; set; } |         public IEnumerable<string> SpecialFeatures { get; set; } | ||||||
|         [IgnoreDataMember] |         [IgnoreDataMember] | ||||||
|         public IEnumerable<HtmlNode> SpecialFeaturesNodes |         public IEnumerable<XmlNode> SpecialFeaturesNodes | ||||||
|         { |         { | ||||||
|             set |             set | ||||||
|             { |             { | ||||||
|  | @ -62,7 +62,7 @@ namespace AideDeJeuLib.Monsters | ||||||
| 
 | 
 | ||||||
|         public IEnumerable<string> Actions { get; set; } |         public IEnumerable<string> Actions { get; set; } | ||||||
|         [IgnoreDataMember] |         [IgnoreDataMember] | ||||||
|         public IEnumerable<HtmlNode> ActionsNodes |         public IEnumerable<XmlNode> ActionsNodes | ||||||
|         { |         { | ||||||
|             set |             set | ||||||
|             { |             { | ||||||
|  | @ -72,7 +72,7 @@ namespace AideDeJeuLib.Monsters | ||||||
| 
 | 
 | ||||||
|         public IEnumerable<string> LegendaryActions { get; set; } |         public IEnumerable<string> LegendaryActions { get; set; } | ||||||
|         [IgnoreDataMember] |         [IgnoreDataMember] | ||||||
|         public IEnumerable<HtmlNode> LegendaryActionsNodes |         public IEnumerable<XmlNode> LegendaryActionsNodes | ||||||
|         { |         { | ||||||
|             set |             set | ||||||
|             { |             { | ||||||
|  | @ -83,15 +83,15 @@ namespace AideDeJeuLib.Monsters | ||||||
| 
 | 
 | ||||||
|         public void ParseHtml() |         public void ParseHtml() | ||||||
|         { |         { | ||||||
|             var pack = new HtmlDocument(); |             var pack = new XmlDocument(); | ||||||
|             pack.LoadHtml(this.Html); |             pack.LoadXml(this.Html); | ||||||
|             var divSpell = pack.DocumentNode.SelectNodes("//div[contains(@class,'bloc')]").FirstOrDefault(); |             var divSpell = pack.DocumentElement.SelectSingleNode("//div[contains(@class,'bloc')]"); | ||||||
|             ParseNode(divSpell); |             ParseNode(divSpell); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         //public static Monster FromHtml(HtmlNode divBloc) |         //public static Monster FromHtml(HtmlNode divBloc) | ||||||
|         //{ |         //{ | ||||||
|         public void ParseNode(HtmlNode divBloc) |         public void ParseNode(XmlNode divBloc) | ||||||
|         { |         { | ||||||
|             //monster.Html = divBloc.OuterHtml; |             //monster.Html = divBloc.OuterHtml; | ||||||
|             var divMonster = divBloc?.SelectSingleNode("div[contains(@class,'monstre')]"); |             var divMonster = divBloc?.SelectSingleNode("div[contains(@class,'monstre')]"); | ||||||
|  | @ -99,7 +99,7 @@ namespace AideDeJeuLib.Monsters | ||||||
| 
 | 
 | ||||||
|             var divTrad = divMonster.SelectSingleNode("div[@class='trad']"); |             var divTrad = divMonster.SelectSingleNode("div[@class='trad']"); | ||||||
| 
 | 
 | ||||||
|             var linkVO = divTrad.SelectSingleNode("a").GetAttributeValue("href", ""); |             var linkVO = divTrad.SelectSingleNode("a").Attributes["href"].InnerText; | ||||||
|             var matchIdVF = new Regex(@"\?vf=(?<idvf>.*)").Match(linkVO); |             var matchIdVF = new Regex(@"\?vf=(?<idvf>.*)").Match(linkVO); | ||||||
|             this.IdVF = matchIdVF?.Groups["idvf"]?.Value; |             this.IdVF = matchIdVF?.Groups["idvf"]?.Value; | ||||||
|             var matchIdVO = new Regex(@"\?vo=(?<idvo>.*)").Match(linkVO); |             var matchIdVO = new Regex(@"\?vo=(?<idvo>.*)").Match(linkVO); | ||||||
|  | @ -160,24 +160,24 @@ namespace AideDeJeuLib.Monsters | ||||||
|             this.Languages = divRed?.SelectSingleNode("strong[contains(text(),'Langues') or contains(text(),'Languages')]")?.NextSibling?.InnerText; |             this.Languages = divRed?.SelectSingleNode("strong[contains(text(),'Langues') or contains(text(),'Languages')]")?.NextSibling?.InnerText; | ||||||
|             this.Challenge = divRed?.SelectSingleNode("strong[contains(text(),'Puissance') or contains(text(),'Challenge')]")?.NextSibling?.InnerText; |             this.Challenge = divRed?.SelectSingleNode("strong[contains(text(),'Puissance') or contains(text(),'Challenge')]")?.NextSibling?.InnerText; | ||||||
| 
 | 
 | ||||||
|             List<HtmlNode> nodes = new List<HtmlNode>(); |             List<XmlNode> nodes = new List<XmlNode>(); | ||||||
|             List<HtmlNode> specialFeatures = null; |             List<XmlNode> specialFeatures = null; | ||||||
|             List<HtmlNode> actions = null; |             List<XmlNode> actions = null; | ||||||
|             List<HtmlNode> legendaryActions = null; |             List<XmlNode> legendaryActions = null; | ||||||
|             var node = divSansSerif.SelectSingleNode("p"); |             var node = divSansSerif.SelectSingleNode("p"); | ||||||
|             while(node != null) |             while(node != null) | ||||||
|             { |             { | ||||||
|                 if(node.NodeType == HtmlNodeType.Element && node.Name == "div") |                 if(node.NodeType == XmlNodeType.Element && node.Name == "div") | ||||||
|                 { |                 { | ||||||
|                     if(node.InnerText == "ACTIONS") |                     if(node.InnerText == "ACTIONS") | ||||||
|                     { |                     { | ||||||
|                         specialFeatures = nodes; |                         specialFeatures = nodes; | ||||||
|                         nodes = new List<HtmlNode>(); |                         nodes = new List<XmlNode>(); | ||||||
|                     } |                     } | ||||||
|                     else if (node.InnerText == "ACTIONS LÉGENDAIRES" || node.InnerText == "LEGENDARY ACTIONS") |                     else if (node.InnerText == "ACTIONS LÉGENDAIRES" || node.InnerText == "LEGENDARY ACTIONS") | ||||||
|                     { |                     { | ||||||
|                         actions = nodes; |                         actions = nodes; | ||||||
|                         nodes = new List<HtmlNode>(); |                         nodes = new List<XmlNode>(); | ||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
|                 else |                 else | ||||||
|  | @ -213,13 +213,13 @@ namespace AideDeJeuLib.Monsters | ||||||
|             this.Source = divSource?.InnerText; |             this.Source = divSource?.InnerText; | ||||||
| 
 | 
 | ||||||
|             var img = divBloc?.SelectSingleNode("div[contains(@class,'center')]/img[contains(@class,'picture')]"); |             var img = divBloc?.SelectSingleNode("div[contains(@class,'center')]/img[contains(@class,'picture')]"); | ||||||
|             this.Picture = img?.GetAttributeValue("src", null); |             this.Picture = img?.Attributes["src"].InnerText; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         public static Monster FromHtml(HtmlNode node) |         public static Monster FromHtml(XmlNode node) | ||||||
|         { |         { | ||||||
|             var monster = new Monster(); |             var monster = new Monster(); | ||||||
|             monster.Html = node.OuterHtml; |             monster.Html = node.OuterXml; | ||||||
|             monster.ParseNode(node); |             monster.ParseNode(node); | ||||||
|             return monster; |             return monster; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  | @ -1,11 +1,11 @@ | ||||||
| using HtmlAgilityPack; | using System; | ||||||
| using System; |  | ||||||
| using System.Collections.Generic; | using System.Collections.Generic; | ||||||
| using System.Linq; | using System.Linq; | ||||||
| using System.Net.Http; | using System.Net.Http; | ||||||
| using System.Text; | using System.Text; | ||||||
| using System.Text.RegularExpressions; | using System.Text.RegularExpressions; | ||||||
| using System.Threading.Tasks; | using System.Threading.Tasks; | ||||||
|  | using System.Xml; | ||||||
| 
 | 
 | ||||||
| namespace AideDeJeuLib.Monsters | namespace AideDeJeuLib.Monsters | ||||||
| { | { | ||||||
|  | @ -78,22 +78,23 @@ namespace AideDeJeuLib.Monsters | ||||||
|             var url = string.Format($"https://www.aidedd.org/dnd-filters/monstres.php?c={category}&t={type}&min={minPower}&max={maxPower}&sz={size}&lg={legendary}&s={source}", category, type, minPower, maxPower, size, legendary, source); |             var url = string.Format($"https://www.aidedd.org/dnd-filters/monstres.php?c={category}&t={type}&min={minPower}&max={maxPower}&sz={size}&lg={legendary}&s={source}", category, type, minPower, maxPower, size, legendary, source); | ||||||
|             html = await client.GetStringAsync(url); |             html = await client.GetStringAsync(url); | ||||||
| 
 | 
 | ||||||
|             var pack = new HtmlDocument(); |             var pack = new XmlDocument(); | ||||||
|             pack.LoadHtml(html); |             pack.LoadXml(html); | ||||||
|             //var trs = pack.GetElementbyId("liste").Element("table").Elements("tr").ToList(); |             //var trs = pack.GetElementbyId("liste").Element("table").Elements("tr").ToList(); | ||||||
|             var trs = pack.DocumentNode.SelectSingleNode("//table[contains(@class,'liste')]").Elements("tr").ToList(); |             var trs = pack.DocumentElement.SelectSingleNode("//table[contains(@class,'liste')]").SelectNodes("tr"); | ||||||
|             var monsters = new List<Monster>(); |             var monsters = new List<Monster>(); | ||||||
|             foreach (var tr in trs) |             foreach (var tro in trs) | ||||||
|             { |             { | ||||||
|                 var tds = tr.Elements("td").ToArray(); |                 var tr = tro as XmlNode; | ||||||
|                 if (tds.Length > 0) |                 var tds = tr.SelectNodes("td"); | ||||||
|  |                 if (tds.Count > 0) | ||||||
|                 { |                 { | ||||||
|                     var monster = new Monster(); |                     var monster = new Monster(); | ||||||
|                     var aname = tds[1].Element("a"); |                     var aname = tds[1].SelectSingleNode("a"); | ||||||
|                     var spanname = aname.Element("span"); |                     var spanname = aname.SelectSingleNode("span"); | ||||||
|                     if (spanname != null) |                     if (spanname != null) | ||||||
|                     { |                     { | ||||||
|                         monster.NamePHB = spanname.GetAttributeValue("title", ""); |                         monster.NamePHB = spanname.Attributes["title"].InnerText; | ||||||
|                         monster.Name = spanname.InnerText; |                         monster.Name = spanname.InnerText; | ||||||
|                     } |                     } | ||||||
|                     else |                     else | ||||||
|  | @ -103,7 +104,7 @@ namespace AideDeJeuLib.Monsters | ||||||
|                     } |                     } | ||||||
| 
 | 
 | ||||||
|                     //monster.Name = tds[0].InnerText; |                     //monster.Name = tds[0].InnerText; | ||||||
|                     var href = aname.GetAttributeValue("href", ""); |                     var href = aname.Attributes["href"].InnerText; | ||||||
|                     var regex = new Regex("vf=(?<id>.*)"); |                     var regex = new Regex("vf=(?<id>.*)"); | ||||||
|                     monster.Id = regex.Match(href).Groups["id"].Value; |                     monster.Id = regex.Match(href).Groups["id"].Value; | ||||||
|                     monster.Power = tds[2].InnerText; |                     monster.Power = tds[2].InnerText; | ||||||
|  | @ -125,9 +126,9 @@ namespace AideDeJeuLib.Monsters | ||||||
| 
 | 
 | ||||||
|             html = await client.GetStringAsync(string.Format($"https://www.aidedd.org/dnd/monstres.php?vf={id}", id)); |             html = await client.GetStringAsync(string.Format($"https://www.aidedd.org/dnd/monstres.php?vf={id}", id)); | ||||||
| 
 | 
 | ||||||
|             var pack = new HtmlDocument(); |             var pack = new XmlDocument(); | ||||||
|             pack.LoadHtml(html); |             pack.LoadXml(html); | ||||||
|             var divBloc = pack.DocumentNode.SelectNodes("//div[contains(@class,'bloc')]").FirstOrDefault(); |             var divBloc = pack.DocumentElement.SelectSingleNode("//div[contains(@class,'bloc')]"); | ||||||
|             var monster = Monster.FromHtml(divBloc); |             var monster = Monster.FromHtml(divBloc); | ||||||
|             monster.Id = id; |             monster.Id = id; | ||||||
|             return monster; |             return monster; | ||||||
|  |  | ||||||
|  | @ -1,5 +1,4 @@ | ||||||
| using HtmlAgilityPack; | using System; | ||||||
| using System; |  | ||||||
| using System.Linq; | using System.Linq; | ||||||
| using System.Runtime.Serialization; | using System.Runtime.Serialization; | ||||||
| using System.Text.RegularExpressions; | using System.Text.RegularExpressions; | ||||||
|  | @ -28,24 +27,24 @@ namespace AideDeJeuLib.Spells | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         [IgnoreDataMember] |         [IgnoreDataMember] | ||||||
|         public HtmlNode DescriptionDiv |         public XmlNode DescriptionDiv | ||||||
|         { |         { | ||||||
|             get |             get | ||||||
|             { |             { | ||||||
|                 if(DescriptionHtml != null) |                 if(DescriptionHtml != null) | ||||||
|                 { |                 { | ||||||
|                     //XmlDocument xdoc = new XmlDocument(); |                     XmlDocument xdoc = new XmlDocument(); | ||||||
|                     //xdoc.LoadXml(DescriptionHtml); |                     xdoc.LoadXml(DescriptionHtml); | ||||||
|                     //return xdoc.DocumentElement; |                     return xdoc.DocumentElement; | ||||||
|                     HtmlDocument doc = new HtmlDocument(); |                     //HtmlDocument doc = new HtmlDocument() { OptionOutputAsXml = true }; | ||||||
|                     doc.LoadHtml(DescriptionHtml); |                     //doc.LoadHtml(DescriptionHtml); | ||||||
|                     return doc.DocumentNode; |                     //return doc.DocumentNode; | ||||||
|                 } |                 } | ||||||
|                 return null; |                 return null; | ||||||
|             } |             } | ||||||
|             set |             set | ||||||
|             { |             { | ||||||
|                 DescriptionHtml = value?.OuterHtml; |                 DescriptionHtml = value?.OuterXml; | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  | @ -55,18 +54,18 @@ namespace AideDeJeuLib.Spells | ||||||
| 
 | 
 | ||||||
|         public void ParseHtml() |         public void ParseHtml() | ||||||
|         { |         { | ||||||
|             var pack = new HtmlDocument(); |             var pack = new XmlDocument(); | ||||||
|             pack.LoadHtml(this.Html); |             pack.LoadXml(this.Html); | ||||||
|             var divSpell = pack.DocumentNode.SelectNodes("//div[contains(@class,'bloc')]").FirstOrDefault(); |             var divSpell = pack.DocumentElement.SelectSingleNode("//div[contains(@class,'bloc')]"); | ||||||
|             ParseNode(divSpell); |             ParseNode(divSpell); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         public void ParseNode(HtmlNode nodeSpell) |         public void ParseNode(XmlNode nodeSpell) | ||||||
|         { |         { | ||||||
|             this.Name = nodeSpell.SelectSingleNode("h1").InnerText; |             this.Name = nodeSpell.SelectSingleNode("h1").InnerText; | ||||||
|             var divTrad = nodeSpell.SelectSingleNode("div[@class='trad']"); |             var divTrad = nodeSpell.SelectSingleNode("div[@class='trad']"); | ||||||
|              |              | ||||||
|             var linkVO = divTrad.SelectSingleNode("a").GetAttributeValue("href", ""); |             var linkVO = divTrad.SelectSingleNode("a").Attributes["href"].InnerText; | ||||||
|             var matchIdVF = new Regex(@"\?vf=(?<idvf>.*)").Match(linkVO); |             var matchIdVF = new Regex(@"\?vf=(?<idvf>.*)").Match(linkVO); | ||||||
|             this.IdVF = matchIdVF?.Groups["idvf"]?.Value; |             this.IdVF = matchIdVF?.Groups["idvf"]?.Value; | ||||||
|             var matchIdVO = new Regex(@"\?vo=(?<idvo>.*)").Match(linkVO); |             var matchIdVO = new Regex(@"\?vo=(?<idvo>.*)").Match(linkVO); | ||||||
|  | @ -95,10 +94,10 @@ namespace AideDeJeuLib.Spells | ||||||
|             this.Source = nodeSpell.SelectSingleNode("div[@class='source']").InnerText; |             this.Source = nodeSpell.SelectSingleNode("div[@class='source']").InnerText; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         public static Spell FromHtml(HtmlNode nodeSpell) |         public static Spell FromHtml(XmlNode nodeSpell) | ||||||
|         { |         { | ||||||
|             var spell = new Spell(); |             var spell = new Spell(); | ||||||
|             spell.Html = nodeSpell.OuterHtml; |             spell.Html = nodeSpell.OuterXml; | ||||||
|             spell.ParseNode(nodeSpell); |             spell.ParseNode(nodeSpell); | ||||||
|             return spell; |             return spell; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  | @ -1,10 +1,11 @@ | ||||||
| using HtmlAgilityPack; | using System; | ||||||
| using System; |  | ||||||
| using System.Collections.Generic; | using System.Collections.Generic; | ||||||
| using System.Linq; | using System.Linq; | ||||||
| using System.Net.Http; | using System.Net.Http; | ||||||
| using System.Text.RegularExpressions; | using System.Text.RegularExpressions; | ||||||
| using System.Threading.Tasks; | using System.Threading.Tasks; | ||||||
|  | using System.Xml; | ||||||
|  | using System.Xml.Linq; | ||||||
| 
 | 
 | ||||||
| namespace AideDeJeuLib.Spells | namespace AideDeJeuLib.Spells | ||||||
| { | { | ||||||
|  | @ -76,22 +77,23 @@ namespace AideDeJeuLib.Spells | ||||||
|             var url = string.Format("https://www.aidedd.org/dnd-filters/sorts.php?c={0}&min={1}&max={2}&e={3}&r={4}&s={5}", classe, niveauMin, niveauMax, ecole, rituel, source); |             var url = string.Format("https://www.aidedd.org/dnd-filters/sorts.php?c={0}&min={1}&max={2}&e={3}&r={4}&s={5}", classe, niveauMin, niveauMax, ecole, rituel, source); | ||||||
|             html = await client.GetStringAsync(url); |             html = await client.GetStringAsync(url); | ||||||
| 
 | 
 | ||||||
|             var pack = new HtmlDocument(); |             var pack = new XmlDocument(); | ||||||
|             pack.LoadHtml(html); |             pack.LoadXml(html); | ||||||
|             //var tdssort = pack.GetElementbyId("liste").Element("table").Elements("tr").ToList(); |             //var tdssort = pack.GetElementbyId("liste").Element("table").Elements("tr").ToList(); | ||||||
|             var tdssort = pack.DocumentNode.SelectSingleNode("//table[contains(@class,'liste')]").Elements("tr").ToList(); |             var tdssort = pack.DocumentElement.SelectSingleNode("//table[contains(@class,'liste')]").SelectNodes("tr"); | ||||||
|             var spells = new List<Spell>(); |             var spells = new List<Spell>(); | ||||||
|             foreach (var tdsort in tdssort) |             foreach (var tdsortt in tdssort) | ||||||
|             { |             { | ||||||
|                 var thssort = tdsort.Elements("td").ToArray(); |                 var tdsort = tdsortt as XmlNode; | ||||||
|                 if (thssort.Length > 0) |                 var thssort = tdsort.SelectNodes("td"); | ||||||
|  |                 if (thssort.Count > 0) | ||||||
|                 { |                 { | ||||||
|                     Spell spell = new Spell(); |                     Spell spell = new Spell(); | ||||||
|                     var aname = thssort[1].Element("a"); |                     var aname = thssort[1].SelectSingleNode("a"); | ||||||
|                     var spanname = aname.Element("span"); |                     var spanname = aname.SelectSingleNode("span"); | ||||||
|                     if(spanname != null) |                     if(spanname != null) | ||||||
|                     { |                     { | ||||||
|                         spell.NamePHB = spanname.GetAttributeValue("title", ""); |                         spell.NamePHB = spanname.Attributes["title"].InnerText; | ||||||
|                         spell.Name = spanname.InnerText; |                         spell.Name = spanname.InnerText; | ||||||
|                     } |                     } | ||||||
|                     else |                     else | ||||||
|  | @ -99,7 +101,7 @@ namespace AideDeJeuLib.Spells | ||||||
|                         spell.NamePHB = aname.InnerText; |                         spell.NamePHB = aname.InnerText; | ||||||
|                         spell.Name = aname.InnerText; |                         spell.Name = aname.InnerText; | ||||||
|                     } |                     } | ||||||
|                     var href = aname.GetAttributeValue("href", ""); |                     var href = aname.Attributes["href"].InnerText; | ||||||
|                     var regex = new Regex("vf=(?<id>.*)"); |                     var regex = new Regex("vf=(?<id>.*)"); | ||||||
|                     spell.Id = regex.Match(href).Groups["id"].Value; |                     spell.Id = regex.Match(href).Groups["id"].Value; | ||||||
| 
 | 
 | ||||||
|  | @ -123,9 +125,9 @@ namespace AideDeJeuLib.Spells | ||||||
| 
 | 
 | ||||||
|             html = await client.GetStringAsync(string.Format("https://www.aidedd.org/dnd/sorts.php?vf={0}", id)); |             html = await client.GetStringAsync(string.Format("https://www.aidedd.org/dnd/sorts.php?vf={0}", id)); | ||||||
| 
 | 
 | ||||||
|             var pack = new HtmlDocument(); |             var pack = new XmlDocument(); | ||||||
|             pack.LoadHtml(html); |             pack.LoadXml(html); | ||||||
|             var divSpell = pack.DocumentNode.SelectNodes("//div[contains(@class,'bloc')]").FirstOrDefault(); |             var divSpell = pack.DocumentElement.SelectSingleNode("//div[contains(@class,'bloc')]"); | ||||||
|             var spell = Spell.FromHtml(divSpell); |             var spell = Spell.FromHtml(divSpell); | ||||||
|             spell.Id = id; |             spell.Id = id; | ||||||
|             return spell; |             return spell; | ||||||
|  | @ -141,9 +143,9 @@ namespace AideDeJeuLib.Spells | ||||||
| 
 | 
 | ||||||
|             html = await client.GetStringAsync(string.Format("https://www.aidedd.org/adj/livre-sorts/?c={0}&min={1}&max={2}", classe, niveauMin, niveauMax)); |             html = await client.GetStringAsync(string.Format("https://www.aidedd.org/adj/livre-sorts/?c={0}&min={1}&max={2}", classe, niveauMin, niveauMax)); | ||||||
| 
 | 
 | ||||||
|             var pack = new HtmlDocument(); |             var pack = new XmlDocument(); | ||||||
|             pack.LoadHtml(html); |             pack.LoadXml(html); | ||||||
|             return pack.DocumentNode.SelectNodes("//input[@name='select_sorts[]']").Select(node => node.GetAttributeValue("value", "")); |             return pack.DocumentElement.SelectNodes("//input[@name='select_sorts[]']").Cast<XmlNode>().Select(node => node.Attributes["value"].InnerText); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         public async Task<IEnumerable<Spell>> GetSpells(IEnumerable<string> spellIds) |         public async Task<IEnumerable<Spell>> GetSpells(IEnumerable<string> spellIds) | ||||||
|  | @ -159,14 +161,14 @@ namespace AideDeJeuLib.Spells | ||||||
|             var response = await client.PostAsync("http://www.aidedd.org/dnd/sorts.php", content); |             var response = await client.PostAsync("http://www.aidedd.org/dnd/sorts.php", content); | ||||||
|             html = await response.Content.ReadAsStringAsync(); |             html = await response.Content.ReadAsStringAsync(); | ||||||
| 
 | 
 | ||||||
|             var pack = new HtmlDocument(); |             var pack = new XmlDocument(); | ||||||
|             pack.LoadHtml(html); |             pack.LoadXml(html); | ||||||
|             var newSpells = new List<Spell>(); |             var newSpells = new List<Spell>(); | ||||||
|             var spells = pack.DocumentNode.SelectNodes("//div[contains(@class,'blocCarte')]").ToList(); |             var spells = pack.DocumentElement.SelectNodes("//div[contains(@class,'blocCarte')]"); | ||||||
|             foreach (var spell in spells) |             foreach (var spell in spells) | ||||||
|             { |             { | ||||||
|                 //var newSpell = new Spell(); |                 //var newSpell = new Spell(); | ||||||
|                 var newSpell = Spell.FromHtml(spell); |                 var newSpell = Spell.FromHtml(spell as XmlNode); | ||||||
|                 //newSpell.Name = spell.SelectSingleNode("h1").InnerText; |                 //newSpell.Name = spell.SelectSingleNode("h1").InnerText; | ||||||
|                 //newSpell.NameVO = spell.SelectSingleNode("div[@class='trad']").InnerText; |                 //newSpell.NameVO = spell.SelectSingleNode("div[@class='trad']").InnerText; | ||||||
|                 //newSpell.LevelType = spell.SelectSingleNode("h2/em").InnerText; |                 //newSpell.LevelType = spell.SelectSingleNode("h2/em").InnerText; | ||||||
|  |  | ||||||
|  | @ -1,9 +1,9 @@ | ||||||
| using AideDeJeu.ViewModels; | using AideDeJeu.ViewModels; | ||||||
| using HtmlAgilityPack; |  | ||||||
| using System; | using System; | ||||||
| using System.Collections.Generic; | using System.Collections.Generic; | ||||||
| using System.Globalization; | using System.Globalization; | ||||||
| using System.Text; | using System.Text; | ||||||
|  | using System.Xml; | ||||||
| using Xamarin.Forms; | using Xamarin.Forms; | ||||||
| 
 | 
 | ||||||
| namespace AideDeJeu.Tools | namespace AideDeJeu.Tools | ||||||
|  | @ -41,11 +41,11 @@ namespace AideDeJeu.Tools | ||||||
|             var str = value as string; |             var str = value as string; | ||||||
|             if (str != null) |             if (str != null) | ||||||
|             { |             { | ||||||
|                 var doc = new HtmlDocument(); |                 var doc = new XmlDocument(); | ||||||
|                 doc.LoadHtml(str); |                 doc.LoadXml("<div>" + str + "</div>"); | ||||||
| 
 | 
 | ||||||
|                 var fs = new FormattedString(); |                 var fs = new FormattedString(); | ||||||
|                 FormatedTextHelpers.HtmlNodeToFormatedString(doc.DocumentNode, fs); |                 FormatedTextHelpers.HtmlNodeToFormatedString(doc.DocumentElement, fs); | ||||||
|                 return fs; |                 return fs; | ||||||
|             } |             } | ||||||
|             else |             else | ||||||
|  | @ -70,10 +70,10 @@ namespace AideDeJeu.Tools | ||||||
|                 var fs = new FormattedString(); |                 var fs = new FormattedString(); | ||||||
|                 foreach (var str in strings) |                 foreach (var str in strings) | ||||||
|                 { |                 { | ||||||
|                     var doc = new HtmlDocument(); |                     var doc = new XmlDocument(); | ||||||
|                     doc.LoadHtml(str); |                     doc.LoadXml("<div>" + str + "</div>"); | ||||||
| 
 | 
 | ||||||
|                     FormatedTextHelpers.HtmlNodeToFormatedString(doc.DocumentNode, fs); |                     FormatedTextHelpers.HtmlNodeToFormatedString(doc.DocumentElement, fs); | ||||||
|                     fs.Spans.Add(new Span() { Text = "\r\n" }); |                     fs.Spans.Add(new Span() { Text = "\r\n" }); | ||||||
|                 } |                 } | ||||||
|                 return fs; |                 return fs; | ||||||
|  |  | ||||||
|  | @ -1,8 +1,8 @@ | ||||||
| using HtmlAgilityPack; | using System; | ||||||
| using System; |  | ||||||
| using System.Collections.Generic; | using System.Collections.Generic; | ||||||
| using System.Linq; | using System.Linq; | ||||||
| using System.Text; | using System.Text; | ||||||
|  | using System.Xml; | ||||||
| using Xamarin.Forms; | using Xamarin.Forms; | ||||||
| using Xamarin.Forms.Internals; | using Xamarin.Forms.Internals; | ||||||
| 
 | 
 | ||||||
|  | @ -10,20 +10,21 @@ namespace AideDeJeu.Tools | ||||||
| { | { | ||||||
|     public static class FormatedTextHelpers |     public static class FormatedTextHelpers | ||||||
|     { |     { | ||||||
|         public static void HtmlNodesToFormatedString(HtmlNodeCollection nodes, FormattedString fs, FontAttributes attributes = FontAttributes.None) |         public static void HtmlNodesToFormatedString(XmlNodeList nodes, FormattedString fs, FontAttributes attributes = FontAttributes.None) | ||||||
|         { |         { | ||||||
|             if (nodes != null) |             if (nodes != null) | ||||||
|             { |             { | ||||||
|                 foreach (var node in nodes) |                 foreach (var nodee in nodes) | ||||||
|                 { |                 { | ||||||
|  |                     var node = nodee as XmlNode; | ||||||
|                     HtmlNodeToFormatedString(node, fs, attributes); |                     HtmlNodeToFormatedString(node, fs, attributes); | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         public static void HtmlNodeToFormatedString(HtmlNode node, FormattedString fs, FontAttributes attributes = FontAttributes.None) |         public static void HtmlNodeToFormatedString(XmlNode node, FormattedString fs, FontAttributes attributes = FontAttributes.None) | ||||||
|         { |         { | ||||||
|             if (node.NodeType == HtmlNodeType.Text) |             if (node.NodeType == XmlNodeType.Text) | ||||||
|             { |             { | ||||||
|                 var resname = "content"; |                 var resname = "content"; | ||||||
|                 if (attributes.HasFlag(FontAttributes.Bold)) |                 if (attributes.HasFlag(FontAttributes.Bold)) | ||||||
|  | @ -37,23 +38,23 @@ namespace AideDeJeu.Tools | ||||||
|                 var fd = FontData.FromResource(resname); |                 var fd = FontData.FromResource(resname); | ||||||
|                 fs.Spans.Add(new Span() { FontFamily = fd.FontFamily, FontAttributes = attributes | fd.FontAttributes, FontSize = fd.FontSize, ForegroundColor = fd.TextColor, Text = node.InnerText }); |                 fs.Spans.Add(new Span() { FontFamily = fd.FontFamily, FontAttributes = attributes | fd.FontAttributes, FontSize = fd.FontSize, ForegroundColor = fd.TextColor, Text = node.InnerText }); | ||||||
|             } |             } | ||||||
|             else if (node.NodeType == HtmlNodeType.Element && node.Name == "br") |             else if (node.NodeType == XmlNodeType.Element && node.Name == "br") | ||||||
|             { |             { | ||||||
|                 fs.Spans.Add(new Span() { Text = "\r\n" }); |                 fs.Spans.Add(new Span() { Text = "\r\n" }); | ||||||
|             } |             } | ||||||
|             else if (node.NodeType == HtmlNodeType.Element && node.Name == "strong") |             else if (node.NodeType == XmlNodeType.Element && node.Name == "strong") | ||||||
|             { |             { | ||||||
|                 HtmlNodesToFormatedString(node.ChildNodes, fs, attributes | FontAttributes.Bold); |                 HtmlNodesToFormatedString(node.ChildNodes, fs, attributes | FontAttributes.Bold); | ||||||
|             } |             } | ||||||
|             else if (node.NodeType == HtmlNodeType.Element && node.Name == "em") |             else if (node.NodeType == XmlNodeType.Element && node.Name == "em") | ||||||
|             { |             { | ||||||
|                 HtmlNodesToFormatedString(node.ChildNodes, fs, attributes | FontAttributes.Italic); |                 HtmlNodesToFormatedString(node.ChildNodes, fs, attributes | FontAttributes.Italic); | ||||||
|             } |             } | ||||||
|             else if (node.NodeType == HtmlNodeType.Element) |             else if (node.NodeType == XmlNodeType.Element) | ||||||
|             { |             { | ||||||
|                 HtmlNodesToFormatedString(node.ChildNodes, fs, attributes); |                 HtmlNodesToFormatedString(node.ChildNodes, fs, attributes); | ||||||
|             } |             } | ||||||
|             else if (node.NodeType == HtmlNodeType.Document) |             else if (node.NodeType == XmlNodeType.Document) | ||||||
|             { |             { | ||||||
|                 HtmlNodesToFormatedString(node.ChildNodes, fs, attributes); |                 HtmlNodesToFormatedString(node.ChildNodes, fs, attributes); | ||||||
|             } |             } | ||||||
|  |  | ||||||
|  | @ -1,7 +1,6 @@ | ||||||
| using AideDeJeu.Services; | using AideDeJeu.Services; | ||||||
| using AideDeJeuLib.Monsters; | using AideDeJeuLib.Monsters; | ||||||
| using AideDeJeuLib.Spells; | using AideDeJeuLib.Spells; | ||||||
| using HtmlAgilityPack; |  | ||||||
| using System; | using System; | ||||||
| using System.Collections.Generic; | using System.Collections.Generic; | ||||||
| using System.Globalization; | using System.Globalization; | ||||||
|  | @ -74,7 +73,7 @@ namespace AideDeJeuCmd | ||||||
|             spellsVF.ForEach(sp => sp.Html = null); |             spellsVF.ForEach(sp => sp.Html = null); | ||||||
|             spellsVO.ForEach(sp => sp.Html = null); |             spellsVO.ForEach(sp => sp.Html = null); | ||||||
|             spellsVF.ForEach(sp => sp.DescriptionDiv = sp.DescriptionDiv); |             spellsVF.ForEach(sp => sp.DescriptionDiv = sp.DescriptionDiv); | ||||||
|             spellsVO.ForEach(sp => sp.Html = null); |             spellsVO.ForEach(sp => sp.DescriptionDiv = sp.DescriptionDiv); | ||||||
|             monstersVF.ForEach(it => it.Html = null); |             monstersVF.ForEach(it => it.Html = null); | ||||||
|             monstersVO.ForEach(it => it.Html = null); |             monstersVO.ForEach(it => it.Html = null); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
										
											
												File diff suppressed because it is too large
												Load diff
											
										
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
										
											
												File diff suppressed because it is too large
												Load diff
											
										
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Yan Maniez
						Yan Maniez