mirror of
https://github.com/Nioux/AideDeJeu.git
synced 2025-10-31 23:45:39 +00:00
Préparation création de la bdd + éviter de recréer des HttpClient à chaque fois
This commit is contained in:
parent
1ba7606b20
commit
28d833c94d
9 changed files with 279 additions and 80 deletions
|
|
@ -151,23 +151,57 @@
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ImageAsset Include="Media.xcassets\Contents.json" />
|
<ImageAsset Include="Media.xcassets\Contents.json">
|
||||||
<ImageAsset Include="Media.xcassets\AppIcon.appiconset\Contents.json" />
|
<Visible>false</Visible>
|
||||||
<ImageAsset Include="Media.xcassets\AppIcon.appiconset\Icon-40.png" />
|
</ImageAsset>
|
||||||
<ImageAsset Include="Media.xcassets\AppIcon.appiconset\Icon-60.png" />
|
<ImageAsset Include="Media.xcassets\AppIcon.appiconset\Contents.json">
|
||||||
<ImageAsset Include="Media.xcassets\AppIcon.appiconset\Icon-58.png" />
|
<Visible>false</Visible>
|
||||||
<ImageAsset Include="Media.xcassets\AppIcon.appiconset\Icon-87.png" />
|
</ImageAsset>
|
||||||
<ImageAsset Include="Media.xcassets\AppIcon.appiconset\Icon-80.png" />
|
<ImageAsset Include="Media.xcassets\AppIcon.appiconset\Icon-40.png">
|
||||||
<ImageAsset Include="Media.xcassets\AppIcon.appiconset\Icon-120.png" />
|
<Visible>false</Visible>
|
||||||
<ImageAsset Include="Media.xcassets\AppIcon.appiconset\Icon-180.png" />
|
</ImageAsset>
|
||||||
<ImageAsset Include="Media.xcassets\AppIcon.appiconset\Icon-20.png" />
|
<ImageAsset Include="Media.xcassets\AppIcon.appiconset\Icon-60.png">
|
||||||
<ImageAsset Include="Media.xcassets\AppIcon.appiconset\Icon-29.png" />
|
<Visible>false</Visible>
|
||||||
<ImageAsset Include="Media.xcassets\AppIcon.appiconset\Icon-76.png" />
|
</ImageAsset>
|
||||||
<ImageAsset Include="Media.xcassets\AppIcon.appiconset\Icon-152.png" />
|
<ImageAsset Include="Media.xcassets\AppIcon.appiconset\Icon-58.png">
|
||||||
<ImageAsset Include="Media.xcassets\AppIcon.appiconset\Icon-167.png" />
|
<Visible>false</Visible>
|
||||||
<ImageAsset Include="Media.xcassets\AppIcon.appiconset\Icon-1024.png" />
|
</ImageAsset>
|
||||||
<ImageAsset Include="Media.xcassets\icon.imageset\Contents.json" />
|
<ImageAsset Include="Media.xcassets\AppIcon.appiconset\Icon-87.png">
|
||||||
<ImageAsset Include="Media.xcassets\icon.imageset\black-book.pdf" />
|
<Visible>false</Visible>
|
||||||
|
</ImageAsset>
|
||||||
|
<ImageAsset Include="Media.xcassets\AppIcon.appiconset\Icon-80.png">
|
||||||
|
<Visible>false</Visible>
|
||||||
|
</ImageAsset>
|
||||||
|
<ImageAsset Include="Media.xcassets\AppIcon.appiconset\Icon-120.png">
|
||||||
|
<Visible>false</Visible>
|
||||||
|
</ImageAsset>
|
||||||
|
<ImageAsset Include="Media.xcassets\AppIcon.appiconset\Icon-180.png">
|
||||||
|
<Visible>false</Visible>
|
||||||
|
</ImageAsset>
|
||||||
|
<ImageAsset Include="Media.xcassets\AppIcon.appiconset\Icon-20.png">
|
||||||
|
<Visible>false</Visible>
|
||||||
|
</ImageAsset>
|
||||||
|
<ImageAsset Include="Media.xcassets\AppIcon.appiconset\Icon-29.png">
|
||||||
|
<Visible>false</Visible>
|
||||||
|
</ImageAsset>
|
||||||
|
<ImageAsset Include="Media.xcassets\AppIcon.appiconset\Icon-76.png">
|
||||||
|
<Visible>false</Visible>
|
||||||
|
</ImageAsset>
|
||||||
|
<ImageAsset Include="Media.xcassets\AppIcon.appiconset\Icon-152.png">
|
||||||
|
<Visible>false</Visible>
|
||||||
|
</ImageAsset>
|
||||||
|
<ImageAsset Include="Media.xcassets\AppIcon.appiconset\Icon-167.png">
|
||||||
|
<Visible>false</Visible>
|
||||||
|
</ImageAsset>
|
||||||
|
<ImageAsset Include="Media.xcassets\AppIcon.appiconset\Icon-1024.png">
|
||||||
|
<Visible>false</Visible>
|
||||||
|
</ImageAsset>
|
||||||
|
<ImageAsset Include="Media.xcassets\icon.imageset\Contents.json">
|
||||||
|
<Visible>false</Visible>
|
||||||
|
</ImageAsset>
|
||||||
|
<ImageAsset Include="Media.xcassets\icon.imageset\black-book.pdf">
|
||||||
|
<Visible>false</Visible>
|
||||||
|
</ImageAsset>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="Media.xcassets\icon.imageset\" />
|
<Folder Include="Media.xcassets\icon.imageset\" />
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
using AideDeJeuLib.Spells;
|
using AideDeJeuLib.Monsters;
|
||||||
|
using AideDeJeuLib.Spells;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
@ -42,5 +43,30 @@ namespace AideDeJeu.Services
|
||||||
await context.SaveChangesAsync();
|
await context.SaveChangesAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<IEnumerable<Monster>> GetMonstersAsync()
|
||||||
|
{
|
||||||
|
using (var context = CreateContext())
|
||||||
|
{
|
||||||
|
//We use OrderByDescending because Posts are generally displayed from most recent to oldest
|
||||||
|
return await context.Monsters
|
||||||
|
.AsNoTracking()
|
||||||
|
.OrderByDescending(monster => monster.Id)
|
||||||
|
.ToListAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task AddOrUpdateMonstersAsync(IEnumerable<Monster> monsters)
|
||||||
|
{
|
||||||
|
using (var context = CreateContext())
|
||||||
|
{
|
||||||
|
// add posts that do not exist in the database
|
||||||
|
var newMonsters = monsters.Where(
|
||||||
|
monster => context.Monsters.Any(dbMonster => dbMonster.Id == monster.Id) == false
|
||||||
|
);
|
||||||
|
await context.Monsters.AddRangeAsync(newMonsters);
|
||||||
|
await context.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,10 @@
|
||||||
using AideDeJeu.Tools;
|
using AideDeJeu.Services;
|
||||||
|
using AideDeJeu.Tools;
|
||||||
|
using AideDeJeuLib.Monsters;
|
||||||
|
using AideDeJeuLib.Spells;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
|
|
||||||
using Xamarin.Forms;
|
using Xamarin.Forms;
|
||||||
|
|
@ -13,9 +18,11 @@ namespace AideDeJeu.ViewModels
|
||||||
Title = "À propos de ...";
|
Title = "À propos de ...";
|
||||||
|
|
||||||
OpenWebCommand = new Command(() => Device.OpenUri(new Uri("https://nioux.github.io/AideDeJeu/")));
|
OpenWebCommand = new Command(() => Device.OpenUri(new Uri("https://nioux.github.io/AideDeJeu/")));
|
||||||
|
UpdateDataCommand = new Command(async() => await ExecuteUpdateDataCommandAsync());
|
||||||
}
|
}
|
||||||
|
|
||||||
public ICommand OpenWebCommand { get; }
|
public ICommand OpenWebCommand { get; }
|
||||||
|
public ICommand UpdateDataCommand { get; }
|
||||||
|
|
||||||
public string Version {
|
public string Version {
|
||||||
get
|
get
|
||||||
|
|
@ -23,5 +30,40 @@ namespace AideDeJeu.ViewModels
|
||||||
return DependencyService.Get<INativeAPI>().GetVersion();
|
return DependencyService.Get<INativeAPI>().GetVersion();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int countUpdateData = 0;
|
||||||
|
private async Task ExecuteUpdateDataCommandAsync()
|
||||||
|
{
|
||||||
|
if (countUpdateData++ != 5) return;
|
||||||
|
|
||||||
|
IsBusy = true;
|
||||||
|
var helper = new ItemDatabaseHelper<ItemDatabaseContext>();
|
||||||
|
|
||||||
|
using (var spellsScrappers = new SpellsScrappers())
|
||||||
|
{
|
||||||
|
var partialSpells = await spellsScrappers.GetSpells();
|
||||||
|
var spells = new List<Spell>();
|
||||||
|
foreach (var partialSpell in partialSpells)
|
||||||
|
{
|
||||||
|
var spell = await spellsScrappers.GetSpell(partialSpell.Id);
|
||||||
|
spells.Add(spell);
|
||||||
|
}
|
||||||
|
await helper.AddOrUpdateSpellsAsync(spells);
|
||||||
|
}
|
||||||
|
|
||||||
|
using (var monstersScrappers = new MonstersScrappers())
|
||||||
|
{
|
||||||
|
var partialMonsters = await monstersScrappers.GetMonsters();
|
||||||
|
var monsters = new List<Monster>();
|
||||||
|
foreach (var partialMonster in partialMonsters)
|
||||||
|
{
|
||||||
|
var monster = await monstersScrappers.GetMonster(partialMonster.Id);
|
||||||
|
monsters.Add(monster);
|
||||||
|
}
|
||||||
|
await helper.AddOrUpdateMonstersAsync(monsters);
|
||||||
|
}
|
||||||
|
|
||||||
|
IsBusy = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -12,8 +12,8 @@ namespace AideDeJeu.ViewModels
|
||||||
{
|
{
|
||||||
public class BaseViewModel : INotifyPropertyChanged
|
public class BaseViewModel : INotifyPropertyChanged
|
||||||
{
|
{
|
||||||
public SpellsScrappers SpellsScrappers => DependencyService.Get<SpellsScrappers>() ?? new SpellsScrappers();
|
//public SpellsScrappers SpellsScrappers => DependencyService.Get<SpellsScrappers>() ?? new SpellsScrappers();
|
||||||
public MonstersScrappers MonsterScrappers => DependencyService.Get<MonstersScrappers>() ?? new MonstersScrappers();
|
//public MonstersScrappers MonstersScrappers => DependencyService.Get<MonstersScrappers>() ?? new MonstersScrappers();
|
||||||
|
|
||||||
bool isBusy = false;
|
bool isBusy = false;
|
||||||
public bool IsBusy
|
public bool IsBusy
|
||||||
|
|
|
||||||
|
|
@ -120,8 +120,11 @@ namespace AideDeJeu.ViewModels
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var item = await SpellsScrappers.GetSpell(Item.Id);
|
using (var spellsScrappers = new SpellsScrappers())
|
||||||
Item = item;
|
{
|
||||||
|
var item = await spellsScrappers.GetSpell(Item.Id);
|
||||||
|
Item = item;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -170,7 +170,11 @@ namespace AideDeJeu.ViewModels
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
AllItems.Clear();
|
AllItems.Clear();
|
||||||
var items = await SpellsScrappers.GetSpells(classe: Classes[Classe].Key, niveauMin: Niveaux[NiveauMin].Key, niveauMax: Niveaux[NiveauMax].Key, ecole: Ecoles[Ecole].Key, rituel: Rituels[Rituel].Key, source: Sources[Source].Key);
|
IEnumerable<Spell> items = null;
|
||||||
|
using (var spellsScrappers = new SpellsScrappers())
|
||||||
|
{
|
||||||
|
items = await spellsScrappers.GetSpells(classe: Classes[Classe].Key, niveauMin: Niveaux[NiveauMin].Key, niveauMax: Niveaux[NiveauMax].Key, ecole: Ecoles[Ecole].Key, rituel: Rituels[Rituel].Key, source: Sources[Source].Key);
|
||||||
|
}
|
||||||
|
|
||||||
//try
|
//try
|
||||||
//{
|
//{
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,8 @@
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||||
x:Class="AideDeJeu.Views.AboutPage"
|
x:Class="AideDeJeu.Views.AboutPage"
|
||||||
xmlns:vm="clr-namespace:AideDeJeu.ViewModels;"
|
xmlns:vm="clr-namespace:AideDeJeu.ViewModels;"
|
||||||
Title="{Binding Title}">
|
Title="{Binding Title}"
|
||||||
|
IsBusy="{Binding IsBusy}">
|
||||||
<ContentPage.BindingContext>
|
<ContentPage.BindingContext>
|
||||||
<vm:AboutViewModel />
|
<vm:AboutViewModel />
|
||||||
</ContentPage.BindingContext>
|
</ContentPage.BindingContext>
|
||||||
|
|
@ -21,7 +22,11 @@
|
||||||
</StackLayout>
|
</StackLayout>
|
||||||
<ScrollView Grid.Row="1">
|
<ScrollView Grid.Row="1">
|
||||||
<StackLayout Orientation="Vertical" Padding="16,40,16,40" Spacing="10">
|
<StackLayout Orientation="Vertical" Padding="16,40,16,40" Spacing="10">
|
||||||
<Label Text="Aide de Jeu" FontSize="22" FontAttributes="Bold" />
|
<Label Text="Aide de Jeu" FontSize="22" FontAttributes="Bold">
|
||||||
|
<Label.GestureRecognizers>
|
||||||
|
<TapGestureRecognizer Command="{Binding UpdateDataCommand}" />
|
||||||
|
</Label.GestureRecognizers>
|
||||||
|
</Label>
|
||||||
<Label Text="{Binding Version}" FontAttributes="Bold" FontSize="22" />
|
<Label Text="{Binding Version}" FontAttributes="Bold" FontSize="22" />
|
||||||
<Label Text="Cette application est une aide de jeu pour le plus célèbre des jeux de rôle" />
|
<Label Text="Cette application est une aide de jeu pour le plus célèbre des jeux de rôle" />
|
||||||
<Label Text="Son contenu provient du site AideDD, et est traduit du SRD" />
|
<Label Text="Son contenu provient du site AideDD, et est traduit du SRD" />
|
||||||
|
|
|
||||||
|
|
@ -9,28 +9,73 @@ using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace AideDeJeuLib.Monsters
|
namespace AideDeJeuLib.Monsters
|
||||||
{
|
{
|
||||||
public class MonstersScrappers
|
public class MonstersScrappers : IDisposable
|
||||||
{
|
{
|
||||||
|
private HttpClient _Client = null;
|
||||||
public HttpClient GetHttpClient()
|
public HttpClient GetHttpClient()
|
||||||
{
|
{
|
||||||
var client = new HttpClient();
|
if (_Client == null)
|
||||||
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("text/html"));
|
{
|
||||||
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/xhtml+xml"));
|
var client = new HttpClient();
|
||||||
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/xml"));
|
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("text/html"));
|
||||||
client.DefaultRequestHeaders.AcceptLanguage.Add(new System.Net.Http.Headers.StringWithQualityHeaderValue("fr"));
|
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/xhtml+xml"));
|
||||||
client.DefaultRequestHeaders.AcceptLanguage.Add(new System.Net.Http.Headers.StringWithQualityHeaderValue("fr-FR"));
|
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/xml"));
|
||||||
return client;
|
client.DefaultRequestHeaders.AcceptLanguage.Add(new System.Net.Http.Headers.StringWithQualityHeaderValue("fr"));
|
||||||
|
client.DefaultRequestHeaders.AcceptLanguage.Add(new System.Net.Http.Headers.StringWithQualityHeaderValue("fr-FR"));
|
||||||
|
_Client = client;
|
||||||
|
}
|
||||||
|
return _Client;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#region IDisposable Support
|
||||||
|
private bool disposedValue = false; // Pour détecter les appels redondants
|
||||||
|
|
||||||
|
protected virtual void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (!disposedValue)
|
||||||
|
{
|
||||||
|
if (disposing)
|
||||||
|
{
|
||||||
|
// TODO: supprimer l'état managé (objets managés).
|
||||||
|
if (_Client != null)
|
||||||
|
{
|
||||||
|
_Client.Dispose();
|
||||||
|
_Client = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: libérer les ressources non managées (objets non managés) et remplacer un finaliseur ci-dessous.
|
||||||
|
// TODO: définir les champs de grande taille avec la valeur Null.
|
||||||
|
|
||||||
|
disposedValue = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: remplacer un finaliseur seulement si la fonction Dispose(bool disposing) ci-dessus a du code pour libérer les ressources non managées.
|
||||||
|
// ~SpellsScrappers() {
|
||||||
|
// // Ne modifiez pas ce code. Placez le code de nettoyage dans Dispose(bool disposing) ci-dessus.
|
||||||
|
// Dispose(false);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// Ce code est ajouté pour implémenter correctement le modèle supprimable.
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
// Ne modifiez pas ce code. Placez le code de nettoyage dans Dispose(bool disposing) ci-dessus.
|
||||||
|
Dispose(true);
|
||||||
|
// TODO: supprimer les marques de commentaire pour la ligne suivante si le finaliseur est remplacé ci-dessus.
|
||||||
|
// GC.SuppressFinalize(this);
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
public async Task<IEnumerable<Monster>> GetMonsters(string category = "", string type = "", string minPower = "", string maxPower = "", string size = "", string legendary = "", string source = "srd")
|
public async Task<IEnumerable<Monster>> GetMonsters(string category = "", string type = "", string minPower = "", string maxPower = "", string size = "", string legendary = "", string source = "srd")
|
||||||
{
|
{
|
||||||
string html = null;
|
string html = null;
|
||||||
using (var client = GetHttpClient())
|
var client = GetHttpClient();
|
||||||
{
|
// https://www.aidedd.org/regles/monstres/?min=.25&max=20&c=M&sz=TP&lg=si&t=Humano%C3%AFde&s=srd
|
||||||
// https://www.aidedd.org/regles/monstres/?min=.25&max=20&c=M&sz=TP&lg=si&t=Humano%C3%AFde&s=srd
|
|
||||||
|
html = await client.GetStringAsync(string.Format($"https://www.aidedd.org/regles/monstres/?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(string.Format($"https://www.aidedd.org/regles/monstres/?c={category}&t={type}&min={minPower}&max={maxPower}&sz={size}&lg={legendary}&s={source}", category, type, minPower, maxPower, size, legendary, source));
|
|
||||||
}
|
|
||||||
var pack = new HtmlDocument();
|
var pack = new HtmlDocument();
|
||||||
pack.LoadHtml(html);
|
pack.LoadHtml(html);
|
||||||
var trs = pack.GetElementbyId("liste").Element("table").Elements("tr").ToList();
|
var trs = pack.GetElementbyId("liste").Element("table").Elements("tr").ToList();
|
||||||
|
|
@ -72,12 +117,11 @@ namespace AideDeJeuLib.Monsters
|
||||||
public async Task<Monster> GetMonster(string id)
|
public async Task<Monster> GetMonster(string id)
|
||||||
{
|
{
|
||||||
string html = null;
|
string html = null;
|
||||||
using (var client = GetHttpClient())
|
var client = GetHttpClient();
|
||||||
{
|
// https://www.aidedd.org/dnd/monstres.php?vf=aarakocra
|
||||||
// https://www.aidedd.org/dnd/monstres.php?vf=aarakocra
|
|
||||||
|
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 HtmlDocument();
|
||||||
pack.LoadHtml(html);
|
pack.LoadHtml(html);
|
||||||
var divBloc = pack.DocumentNode.SelectNodes("//div[contains(@class,'bloc')]").FirstOrDefault();
|
var divBloc = pack.DocumentNode.SelectNodes("//div[contains(@class,'bloc')]").FirstOrDefault();
|
||||||
|
|
|
||||||
|
|
@ -8,29 +8,73 @@ using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace AideDeJeuLib.Spells
|
namespace AideDeJeuLib.Spells
|
||||||
{
|
{
|
||||||
public class SpellsScrappers
|
public class SpellsScrappers : IDisposable
|
||||||
{
|
{
|
||||||
|
private HttpClient _Client = null;
|
||||||
public HttpClient GetHttpClient()
|
public HttpClient GetHttpClient()
|
||||||
{
|
{
|
||||||
var client = new HttpClient();
|
if (_Client == null)
|
||||||
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("text/html"));
|
{
|
||||||
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/xhtml+xml"));
|
var client = new HttpClient();
|
||||||
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/xml"));
|
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("text/html"));
|
||||||
client.DefaultRequestHeaders.AcceptLanguage.Add(new System.Net.Http.Headers.StringWithQualityHeaderValue("fr"));
|
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/xhtml+xml"));
|
||||||
client.DefaultRequestHeaders.AcceptLanguage.Add(new System.Net.Http.Headers.StringWithQualityHeaderValue("fr-FR"));
|
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/xml"));
|
||||||
return client;
|
client.DefaultRequestHeaders.AcceptLanguage.Add(new System.Net.Http.Headers.StringWithQualityHeaderValue("fr"));
|
||||||
|
client.DefaultRequestHeaders.AcceptLanguage.Add(new System.Net.Http.Headers.StringWithQualityHeaderValue("fr-FR"));
|
||||||
|
_Client = client;
|
||||||
|
}
|
||||||
|
return _Client;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#region IDisposable Support
|
||||||
|
private bool disposedValue = false; // Pour détecter les appels redondants
|
||||||
|
|
||||||
|
protected virtual void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (!disposedValue)
|
||||||
|
{
|
||||||
|
if (disposing)
|
||||||
|
{
|
||||||
|
// TODO: supprimer l'état managé (objets managés).
|
||||||
|
if (_Client != null)
|
||||||
|
{
|
||||||
|
_Client.Dispose();
|
||||||
|
_Client = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: libérer les ressources non managées (objets non managés) et remplacer un finaliseur ci-dessous.
|
||||||
|
// TODO: définir les champs de grande taille avec la valeur Null.
|
||||||
|
|
||||||
|
disposedValue = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: remplacer un finaliseur seulement si la fonction Dispose(bool disposing) ci-dessus a du code pour libérer les ressources non managées.
|
||||||
|
// ~SpellsScrappers() {
|
||||||
|
// // Ne modifiez pas ce code. Placez le code de nettoyage dans Dispose(bool disposing) ci-dessus.
|
||||||
|
// Dispose(false);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// Ce code est ajouté pour implémenter correctement le modèle supprimable.
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
// Ne modifiez pas ce code. Placez le code de nettoyage dans Dispose(bool disposing) ci-dessus.
|
||||||
|
Dispose(true);
|
||||||
|
// TODO: supprimer les marques de commentaire pour la ligne suivante si le finaliseur est remplacé ci-dessus.
|
||||||
|
// GC.SuppressFinalize(this);
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
public async Task<IEnumerable<Spell>> GetSpells(string classe = "", string niveauMin = "", string niveauMax = "", string ecole = "", string rituel = "", string source = "srd")
|
public async Task<IEnumerable<Spell>> GetSpells(string classe = "", string niveauMin = "", string niveauMax = "", string ecole = "", string rituel = "", string source = "srd")
|
||||||
{
|
{
|
||||||
string html = null;
|
string html = null;
|
||||||
using (var client = GetHttpClient())
|
var client = GetHttpClient();
|
||||||
{
|
// https://www.aidedd.org/regles/sorts/
|
||||||
// https://www.aidedd.org/regles/sorts/
|
|
||||||
|
var url = string.Format("https://www.aidedd.org/regles/sorts/?c={0}&min={1}&max={2}&e={3}&r={4}&s={5}", classe, niveauMin, niveauMax, ecole, rituel, source);
|
||||||
|
html = await client.GetStringAsync(url);
|
||||||
|
|
||||||
var url = string.Format("https://www.aidedd.org/regles/sorts/?c={0}&min={1}&max={2}&e={3}&r={4}&s={5}", classe, niveauMin, niveauMax, ecole, rituel, source);
|
|
||||||
html = await client.GetStringAsync(url);
|
|
||||||
}
|
|
||||||
var pack = new HtmlDocument();
|
var pack = new HtmlDocument();
|
||||||
pack.LoadHtml(html);
|
pack.LoadHtml(html);
|
||||||
var tdssort = pack.GetElementbyId("liste").Element("table").Elements("tr").ToList();
|
var tdssort = pack.GetElementbyId("liste").Element("table").Elements("tr").ToList();
|
||||||
|
|
@ -71,13 +115,12 @@ namespace AideDeJeuLib.Spells
|
||||||
public async Task<Spell> GetSpell(string id)
|
public async Task<Spell> GetSpell(string id)
|
||||||
{
|
{
|
||||||
string html = null;
|
string html = null;
|
||||||
using (var client = GetHttpClient())
|
var client = GetHttpClient();
|
||||||
{
|
// https://www.aidedd.org/dnd/sorts.php?vo=ray-of-frost
|
||||||
// https://www.aidedd.org/dnd/sorts.php?vo=ray-of-frost
|
// https://www.aidedd.org/dnd/sorts.php?vf=rayon-de-givre
|
||||||
// https://www.aidedd.org/dnd/sorts.php?vf=rayon-de-givre
|
|
||||||
|
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 HtmlDocument();
|
||||||
pack.LoadHtml(html);
|
pack.LoadHtml(html);
|
||||||
var divSpell = pack.DocumentNode.SelectNodes("//div[contains(@class,'bloc')]").FirstOrDefault();
|
var divSpell = pack.DocumentNode.SelectNodes("//div[contains(@class,'bloc')]").FirstOrDefault();
|
||||||
|
|
@ -87,14 +130,13 @@ namespace AideDeJeuLib.Spells
|
||||||
public async Task<IEnumerable<string>> GetSpellIds(string classe, string niveauMin = "Z", string niveauMax = "9")
|
public async Task<IEnumerable<string>> GetSpellIds(string classe, string niveauMin = "Z", string niveauMax = "9")
|
||||||
{
|
{
|
||||||
string html = null;
|
string html = null;
|
||||||
using (var client = GetHttpClient())
|
var client = GetHttpClient();
|
||||||
{
|
// https://www.aidedd.org/dnd/sorts.php?vo=ray-of-frost
|
||||||
// https://www.aidedd.org/dnd/sorts.php?vo=ray-of-frost
|
// https://www.aidedd.org/dnd/sorts.php?vf=rayon-de-givre
|
||||||
// https://www.aidedd.org/dnd/sorts.php?vf=rayon-de-givre
|
// https://www.aidedd.org/regles/sorts/
|
||||||
// https://www.aidedd.org/regles/sorts/
|
|
||||||
|
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 HtmlDocument();
|
||||||
pack.LoadHtml(html);
|
pack.LoadHtml(html);
|
||||||
return pack.DocumentNode.SelectNodes("//input[@name='select_sorts[]']").Select(node => node.GetAttributeValue("value", ""));
|
return pack.DocumentNode.SelectNodes("//input[@name='select_sorts[]']").Select(node => node.GetAttributeValue("value", ""));
|
||||||
|
|
@ -103,17 +145,16 @@ namespace AideDeJeuLib.Spells
|
||||||
public async Task<IEnumerable<Spell>> GetSpells(IEnumerable<string> spellIds)
|
public async Task<IEnumerable<Spell>> GetSpells(IEnumerable<string> spellIds)
|
||||||
{
|
{
|
||||||
string html = null;
|
string html = null;
|
||||||
using (var client = GetHttpClient())
|
var client = GetHttpClient();
|
||||||
|
var content = new MultipartFormDataContent();
|
||||||
|
content.Add(new StringContent("card"), "format");
|
||||||
|
foreach (var spellId in spellIds)
|
||||||
{
|
{
|
||||||
var content = new MultipartFormDataContent();
|
content.Add(new StringContent(spellId), "select_sorts[]");
|
||||||
content.Add(new StringContent("card"), "format");
|
|
||||||
foreach (var spellId in spellIds)
|
|
||||||
{
|
|
||||||
content.Add(new StringContent(spellId), "select_sorts[]");
|
|
||||||
}
|
|
||||||
var response = await client.PostAsync("http://www.aidedd.org/dnd/sorts.php", content);
|
|
||||||
html = await response.Content.ReadAsStringAsync();
|
|
||||||
}
|
}
|
||||||
|
var response = await client.PostAsync("http://www.aidedd.org/dnd/sorts.php", content);
|
||||||
|
html = await response.Content.ReadAsStringAsync();
|
||||||
|
|
||||||
var pack = new HtmlDocument();
|
var pack = new HtmlDocument();
|
||||||
pack.LoadHtml(html);
|
pack.LoadHtml(html);
|
||||||
var newSpells = new List<Spell>();
|
var newSpells = new List<Spell>();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue