diff --git a/AideDeJeu/AideDeJeu/Tools/FormatedTextHelpers.cs b/AideDeJeu/AideDeJeu/Tools/FormatedTextHelpers.cs
index f2074796..fd01a694 100644
--- a/AideDeJeu/AideDeJeu/Tools/FormatedTextHelpers.cs
+++ b/AideDeJeu/AideDeJeu/Tools/FormatedTextHelpers.cs
@@ -53,6 +53,10 @@ namespace AideDeJeu.Tools
{
HtmlNodesToFormatedString(node.ChildNodes, fs, attributes);
}
+ else if (node.NodeType == HtmlNodeType.Document)
+ {
+ HtmlNodesToFormatedString(node.ChildNodes, fs, attributes);
+ }
}
//public static void HtmlToFormatedString(HtmlNode parentNode, FormattedString fs, FontAttributes attributes = FontAttributes.None)
diff --git a/AideDeJeu/AideDeJeuCmd/AideDeJeuCmd.csproj b/AideDeJeu/AideDeJeuCmd/AideDeJeuCmd.csproj
index 08101ea8..81d18836 100644
--- a/AideDeJeu/AideDeJeuCmd/AideDeJeuCmd.csproj
+++ b/AideDeJeu/AideDeJeuCmd/AideDeJeuCmd.csproj
@@ -6,6 +6,21 @@
latest
+
+
+ Always
+
+
+ Always
+
+
+
+
+
+ Always
+
+
+
diff --git a/AideDeJeu/AideDeJeuCmd/ItemDatabaseContext.cs b/AideDeJeu/AideDeJeuCmd/ItemDatabaseContext.cs
index 252eb8ba..11ad2a12 100644
--- a/AideDeJeu/AideDeJeuCmd/ItemDatabaseContext.cs
+++ b/AideDeJeu/AideDeJeuCmd/ItemDatabaseContext.cs
@@ -25,24 +25,24 @@ namespace AideDeJeu.Services
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
- if (DatabasePath == null)
- {
- switch (Device.RuntimePlatform)
- {
- case Device.iOS:
- SQLitePCL.Batteries_V2.Init();
- DatabasePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "..", "Library", DatabaseName); ;
- break;
- case Device.Android:
- DatabasePath = DependencyService.Get().GetDatabasePath(DatabaseName);
- break;
- case Device.UWP:
- DatabasePath = DependencyService.Get().GetDatabasePath(DatabaseName);
- break;
- default:
- throw new NotImplementedException("Platform not supported");
- }
- }
+ //if (DatabasePath == null)
+ //{
+ // switch (Device.RuntimePlatform)
+ // {
+ // case Device.iOS:
+ // SQLitePCL.Batteries_V2.Init();
+ // DatabasePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "..", "Library", DatabaseName); ;
+ // break;
+ // case Device.Android:
+ // DatabasePath = DependencyService.Get().GetDatabasePath(DatabaseName);
+ // break;
+ // case Device.UWP:
+ // DatabasePath = DependencyService.Get().GetDatabasePath(DatabaseName);
+ // break;
+ // default:
+ // throw new NotImplementedException("Platform not supported");
+ // }
+ //}
// Specify that we will use sqlite and the path of the database here
optionsBuilder.UseSqlite($"Filename={DatabasePath}");
}
diff --git a/AideDeJeu/AideDeJeuCmd/Program.cs b/AideDeJeu/AideDeJeuCmd/Program.cs
index 2040b1f8..92dd6601 100644
--- a/AideDeJeu/AideDeJeuCmd/Program.cs
+++ b/AideDeJeu/AideDeJeuCmd/Program.cs
@@ -1,8 +1,11 @@
using AideDeJeu.Services;
+using AideDeJeuLib.Monsters;
using AideDeJeuLib.Spells;
+using HtmlAgilityPack;
using System;
using System.Collections.Generic;
using System.IO;
+using System.Net.Http;
using System.Runtime.Serialization.Json;
using System.Threading.Tasks;
@@ -12,21 +15,61 @@ namespace AideDeJeuCmd
{
static async Task Main(string[] args)
{
- var documentsDirectoryPath = @"C:\Users\yanma\Documents\Visual Studio 2017\Projects\AideDeJeu\Data\database.db"; // Windows.Storage.ApplicationData.Current.LocalFolder.Path;
- ItemDatabaseHelper helper = new ItemDatabaseHelper(documentsDirectoryPath);
- //var items = await helper.GetSpellsAsync(classe: "", niveauMin: "0", niveauMax: "9", ecole: "", rituel: "", source: "(SRD)");
- var items = await helper.GetMonstersAsync(category: "", type: "", minPower: " 0 (0 PX)", maxPower: " 30 (155000 PX)", size: "", legendary: "", source: "(SRD)");
+ //var documentsDirectoryPath = @"database.db"; // Windows.Storage.ApplicationData.Current.LocalFolder.Path;
+ //ItemDatabaseHelper helper = new ItemDatabaseHelper(documentsDirectoryPath);
+ //var spells = await helper.GetSpellsAsync(classe: "", niveauMin: "0", niveauMax: "9", ecole: "", rituel: "", source: "(SRD)");
+ //var monsters = await helper.GetMonstersAsync(category: "", type: "", minPower: " 0 (0 PX)", maxPower: " 30 (155000 PX)", size: "", legendary: "", source: "(SRD)");
+ var pack = new HtmlDocument();
+ var client = new HttpClient();
- foreach (var item in items)
+ var spells = LoadJSon>("spells.json");
+ var monsters = LoadJSon>("monsters.json");
+ var spellsVO = new List();
+ foreach(var spell in spells)
{
+ spell.ParseHtml();
+ var htmlVO = await client.GetStringAsync(string.Format("https://www.aidedd.org/dnd/sorts.php?vo={0}", spell.IdVO));
+ pack.LoadHtml(htmlVO);
+ var spellVO = Spell.FromHtml(pack.DocumentNode.SelectSingleNode("//div[contains(@class,'bloc')]"));
+ spellVO.IdVO = spell.IdVO;
+ spell.IdVF = spellVO.IdVF;
+ spellsVO.Add(spellVO);
+ Console.WriteLine(string.Format("{0} : {1} / {2} : {3}", spell.IdVF, spell.NamePHB, spellVO.IdVO, spellVO.NameVO));
}
- DataContractJsonSerializer serializer = new DataContractJsonSerializer(items.GetType());
- MemoryStream stream = new MemoryStream();
- serializer.WriteObject(stream, items);
- stream.Seek(0, SeekOrigin.Begin);
- string text = await new StreamReader(stream).ReadToEndAsync();
+
+ foreach(var monster in monsters)
+ {
+ monster.ParseHtml();
+ }
+ SaveJSon>("monsters_vf.json", monsters);
+ SaveJSon>("spells_vf.json", spells);
+ //SaveJSon>("monsters_fr.json", monsters);
+ SaveJSon>("spells_vo.json", spellsVO);
+ //DataContractJsonSerializer serializer = new DataContractJsonSerializer(items.GetType());
+ //MemoryStream stream = new MemoryStream();
+ //serializer.WriteObject(stream, items);
+ //stream.Seek(0, SeekOrigin.Begin);
+ //string text = await new StreamReader(stream).ReadToEndAsync();
Console.WriteLine("Hello World!");
}
+
+ private static T LoadJSon(string filename) where T : class
+ {
+ var serializer = new DataContractJsonSerializer(typeof(T));
+ using (var stream = new FileStream(filename, FileMode.Open))
+ {
+ return serializer.ReadObject(stream) as T;
+ }
+ }
+
+ private static void SaveJSon(string filename, T objT) where T : class
+ {
+ var serializer = new DataContractJsonSerializer(typeof(T));
+ using (var stream = new FileStream(filename, FileMode.Create))
+ {
+ serializer.WriteObject(stream, objT);
+ }
+ }
}
}
diff --git a/AideDeJeu/AideDeJeuLib/AideDeJeuLib.csproj b/AideDeJeu/AideDeJeuLib/AideDeJeuLib.csproj
index 0a720de3..f3145cfb 100644
--- a/AideDeJeu/AideDeJeuLib/AideDeJeuLib.csproj
+++ b/AideDeJeu/AideDeJeuLib/AideDeJeuLib.csproj
@@ -8,10 +8,4 @@
-
-
- ..\..\..\..\..\..\..\..\Program Files (x86)\Microsoft SDKs\UWPNuGetPackages\microsoft.netcore.universalwindowsplatform\6.1.4\ref\uap10.0.15138\System.ComponentModel.Annotations.dll
-
-
-
diff --git a/AideDeJeu/AideDeJeuLib/Item.cs b/AideDeJeu/AideDeJeuLib/Item.cs
index 3e5b83e0..959da1cb 100644
--- a/AideDeJeu/AideDeJeuLib/Item.cs
+++ b/AideDeJeu/AideDeJeuLib/Item.cs
@@ -1,14 +1,10 @@
-using System;
-using System.Collections.Generic;
-using System.ComponentModel.DataAnnotations;
-using System.Text;
-
-namespace AideDeJeuLib
+namespace AideDeJeuLib
{
public class Item
{
- [Key]
public string Id { get; set; }
+ public string IdVO { get; set; }
+ public string IdVF { get; set; }
public string Name { get; set; }
public string NameVO { get; set; }
public string NamePHB { get; set; }
diff --git a/AideDeJeu/AideDeJeuLib/Monsters/Monster.cs b/AideDeJeu/AideDeJeuLib/Monsters/Monster.cs
index 55a8a5b8..65d62cf8 100644
--- a/AideDeJeu/AideDeJeuLib/Monsters/Monster.cs
+++ b/AideDeJeu/AideDeJeuLib/Monsters/Monster.cs
@@ -1,10 +1,7 @@
using HtmlAgilityPack;
-using System;
using System.Collections.Generic;
-using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Runtime.Serialization;
-using System.Text;
using System.Text.RegularExpressions;
namespace AideDeJeuLib.Monsters
@@ -54,7 +51,6 @@ namespace AideDeJeuLib.Monsters
}
[IgnoreDataMember]
- [NotMapped]
public List SpecialFeatures { get; set; }
//public List SpecialFeaturesPersist
//{
@@ -76,10 +72,8 @@ namespace AideDeJeuLib.Monsters
//}
[IgnoreDataMember]
- [NotMapped]
public List Actions { get; set; }
[IgnoreDataMember]
- [NotMapped]
public List LegendaryActions { get; set; }
diff --git a/AideDeJeu/AideDeJeuLib/Spells/Spell.cs b/AideDeJeu/AideDeJeuLib/Spells/Spell.cs
index 400aabec..480e17c0 100644
--- a/AideDeJeu/AideDeJeuLib/Spells/Spell.cs
+++ b/AideDeJeu/AideDeJeuLib/Spells/Spell.cs
@@ -1,11 +1,7 @@
using HtmlAgilityPack;
using System;
-using System.Collections.Generic;
-using System.ComponentModel.DataAnnotations;
-using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Runtime.Serialization;
-using System.Text;
using System.Text.RegularExpressions;
namespace AideDeJeuLib.Spells
@@ -21,26 +17,7 @@ namespace AideDeJeuLib.Spells
public string Range { get; set; }
public string Components { get; set; }
public string Duration { get; set; }
- public string DescriptionHtml
- {
- get
- {
- return DescriptionDiv?.InnerHtml;
- }
- set
- {
- if (value != null)
- {
- HtmlDocument doc = new HtmlDocument();
- doc.LoadHtml(value);
- DescriptionDiv = doc.DocumentNode;
- }
- else
- {
- DescriptionDiv = null;
- }
- }
- }
+ public string DescriptionHtml { get; set; }
public string DescriptionText
{
get
@@ -49,8 +26,23 @@ namespace AideDeJeuLib.Spells
}
}
[IgnoreDataMember]
- [NotMapped]
- public HtmlNode DescriptionDiv { get; set; }
+ public HtmlNode DescriptionDiv
+ {
+ get
+ {
+ if(DescriptionHtml != null)
+ {
+ HtmlDocument doc = new HtmlDocument();
+ doc.LoadHtml(DescriptionHtml);
+ return doc.DocumentNode;
+ }
+ return null;
+ }
+ set
+ {
+ DescriptionHtml = value?.OuterHtml;
+ }
+ }
public string Overflow { get; set; }
public string NoOverflow { get; set; }
@@ -67,7 +59,14 @@ namespace AideDeJeuLib.Spells
public void ParseNode(HtmlNode nodeSpell)
{
this.Name = nodeSpell.SelectSingleNode("h1").InnerText;
- var altNames = nodeSpell.SelectSingleNode("div[@class='trad']")?.InnerText;
+ var divTrad = nodeSpell.SelectSingleNode("div[@class='trad']");
+
+ var linkVO = divTrad.SelectSingleNode("a").GetAttributeValue("href", "");
+ var matchIdVF = new Regex(@"\?vf=(?.*)").Match(linkVO);
+ this.IdVF = matchIdVF?.Groups["idvf"]?.Value;
+ var matchIdVO = new Regex(@"\?vo=(?.*)").Match(linkVO);
+ this.IdVO = matchIdVO?.Groups["idvo"]?.Value;
+ var altNames = divTrad?.InnerText;
if (altNames != null)
{
var matchNames = new Regex(@"\[ (?.*?) \](?: \[ (?.*?) \])?").Match(altNames);
@@ -81,10 +80,10 @@ namespace AideDeJeuLib.Spells
this.LevelType = nodeSpell.SelectSingleNode("h2/em").InnerText;
this.Level = this.LevelType.Split(new string[] { " - " }, StringSplitOptions.None)[0].Split(' ')[1];
this.Type = this.LevelType.Split(new string[] { " - " }, StringSplitOptions.None)[1];
- this.CastingTime = nodeSpell.SelectSingleNode("div[@class='paragraphe']").InnerText.Split(new string[] { " : " }, StringSplitOptions.None)[1];
- this.Range = nodeSpell.SelectSingleNode("div[strong/text()='Portée']").InnerText.Split(new string[] { " : " }, StringSplitOptions.None)[1];
- this.Components = nodeSpell.SelectSingleNode("div[strong/text()='Composantes']").InnerText.Split(new string[] { " : " }, StringSplitOptions.None)[1];
- this.Duration = nodeSpell.SelectSingleNode("div[strong/text()='Durée']").InnerText.Split(new string[] { " : " }, StringSplitOptions.None)[1];
+ this.CastingTime = nodeSpell.SelectSingleNode("div[@class='paragraphe']").InnerText.Split(new string[] { ": " }, StringSplitOptions.None)[1];
+ this.Range = nodeSpell.SelectSingleNode("div[strong/text()='Portée' or strong/text()='Range']").InnerText.Split(new string[] { ": " }, StringSplitOptions.None)[1];
+ this.Components = nodeSpell.SelectSingleNode("div[strong/text()='Composantes' or strong/text()='Components']")?.InnerText?.Split(new string[] { ": " }, StringSplitOptions.None)?[1];
+ this.Duration = nodeSpell.SelectSingleNode("div[strong/text()='Durée' or strong/text()='Duration']").InnerText.Split(new string[] { ": " }, StringSplitOptions.None)[1];
this.DescriptionDiv = nodeSpell.SelectSingleNode("div[contains(@class,'description')]");
this.Overflow = nodeSpell.SelectSingleNode("div[@class='overflow']")?.InnerText;
this.NoOverflow = nodeSpell.SelectSingleNode("div[@class='nooverflow']")?.InnerText;