mirror of
https://github.com/Nioux/AideDeJeu.git
synced 2025-10-29 14:35:45 +00:00
Suppression EF
This commit is contained in:
parent
e832b896e8
commit
357fafda80
14 changed files with 332 additions and 98 deletions
|
|
@ -13,7 +13,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AideDeJeu", "AideDeJeu\Aide
|
|||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AideDeJeuLib", "AideDeJeu\AideDeJeuLib\AideDeJeuLib.csproj", "{948BB32D-BAB8-485D-8A6F-BE5391E824A3}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AideDeJeuWeb", "AideDeJeu\AideDeJeuWeb\AideDeJeuWeb.csproj", "{D5065DC7-7B51-4D25-8FA5-DDF0F3E6FCE4}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AideDeJeuWeb", "AideDeJeu\AideDeJeuWeb\AideDeJeuWeb.csproj", "{D5065DC7-7B51-4D25-8FA5-DDF0F3E6FCE4}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AideDeJeuCmd", "AideDeJeu\AideDeJeuCmd\AideDeJeuCmd.csproj", "{9DDAEA8E-7B4F-4CC1-80FC-0D511D230689}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{C0597D88-5C09-4314-80A3-64712B02D0E9} = {C0597D88-5C09-4314-80A3-64712B02D0E9}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
|
|
@ -351,6 +356,54 @@ Global
|
|||
{D5065DC7-7B51-4D25-8FA5-DDF0F3E6FCE4}.Release|x64.Build.0 = Release|Any CPU
|
||||
{D5065DC7-7B51-4D25-8FA5-DDF0F3E6FCE4}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{D5065DC7-7B51-4D25-8FA5-DDF0F3E6FCE4}.Release|x86.Build.0 = Release|Any CPU
|
||||
{9DDAEA8E-7B4F-4CC1-80FC-0D511D230689}.Ad-Hoc|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{9DDAEA8E-7B4F-4CC1-80FC-0D511D230689}.Ad-Hoc|Any CPU.Build.0 = Debug|Any CPU
|
||||
{9DDAEA8E-7B4F-4CC1-80FC-0D511D230689}.Ad-Hoc|ARM.ActiveCfg = Debug|Any CPU
|
||||
{9DDAEA8E-7B4F-4CC1-80FC-0D511D230689}.Ad-Hoc|ARM.Build.0 = Debug|Any CPU
|
||||
{9DDAEA8E-7B4F-4CC1-80FC-0D511D230689}.Ad-Hoc|iPhone.ActiveCfg = Debug|Any CPU
|
||||
{9DDAEA8E-7B4F-4CC1-80FC-0D511D230689}.Ad-Hoc|iPhone.Build.0 = Debug|Any CPU
|
||||
{9DDAEA8E-7B4F-4CC1-80FC-0D511D230689}.Ad-Hoc|iPhoneSimulator.ActiveCfg = Debug|Any CPU
|
||||
{9DDAEA8E-7B4F-4CC1-80FC-0D511D230689}.Ad-Hoc|iPhoneSimulator.Build.0 = Debug|Any CPU
|
||||
{9DDAEA8E-7B4F-4CC1-80FC-0D511D230689}.Ad-Hoc|x64.ActiveCfg = Debug|Any CPU
|
||||
{9DDAEA8E-7B4F-4CC1-80FC-0D511D230689}.Ad-Hoc|x64.Build.0 = Debug|Any CPU
|
||||
{9DDAEA8E-7B4F-4CC1-80FC-0D511D230689}.Ad-Hoc|x86.ActiveCfg = Debug|Any CPU
|
||||
{9DDAEA8E-7B4F-4CC1-80FC-0D511D230689}.Ad-Hoc|x86.Build.0 = Debug|Any CPU
|
||||
{9DDAEA8E-7B4F-4CC1-80FC-0D511D230689}.AppStore|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{9DDAEA8E-7B4F-4CC1-80FC-0D511D230689}.AppStore|Any CPU.Build.0 = Debug|Any CPU
|
||||
{9DDAEA8E-7B4F-4CC1-80FC-0D511D230689}.AppStore|ARM.ActiveCfg = Debug|Any CPU
|
||||
{9DDAEA8E-7B4F-4CC1-80FC-0D511D230689}.AppStore|ARM.Build.0 = Debug|Any CPU
|
||||
{9DDAEA8E-7B4F-4CC1-80FC-0D511D230689}.AppStore|iPhone.ActiveCfg = Debug|Any CPU
|
||||
{9DDAEA8E-7B4F-4CC1-80FC-0D511D230689}.AppStore|iPhone.Build.0 = Debug|Any CPU
|
||||
{9DDAEA8E-7B4F-4CC1-80FC-0D511D230689}.AppStore|iPhoneSimulator.ActiveCfg = Debug|Any CPU
|
||||
{9DDAEA8E-7B4F-4CC1-80FC-0D511D230689}.AppStore|iPhoneSimulator.Build.0 = Debug|Any CPU
|
||||
{9DDAEA8E-7B4F-4CC1-80FC-0D511D230689}.AppStore|x64.ActiveCfg = Debug|Any CPU
|
||||
{9DDAEA8E-7B4F-4CC1-80FC-0D511D230689}.AppStore|x64.Build.0 = Debug|Any CPU
|
||||
{9DDAEA8E-7B4F-4CC1-80FC-0D511D230689}.AppStore|x86.ActiveCfg = Debug|Any CPU
|
||||
{9DDAEA8E-7B4F-4CC1-80FC-0D511D230689}.AppStore|x86.Build.0 = Debug|Any CPU
|
||||
{9DDAEA8E-7B4F-4CC1-80FC-0D511D230689}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{9DDAEA8E-7B4F-4CC1-80FC-0D511D230689}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{9DDAEA8E-7B4F-4CC1-80FC-0D511D230689}.Debug|ARM.ActiveCfg = Debug|Any CPU
|
||||
{9DDAEA8E-7B4F-4CC1-80FC-0D511D230689}.Debug|ARM.Build.0 = Debug|Any CPU
|
||||
{9DDAEA8E-7B4F-4CC1-80FC-0D511D230689}.Debug|iPhone.ActiveCfg = Debug|Any CPU
|
||||
{9DDAEA8E-7B4F-4CC1-80FC-0D511D230689}.Debug|iPhone.Build.0 = Debug|Any CPU
|
||||
{9DDAEA8E-7B4F-4CC1-80FC-0D511D230689}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
|
||||
{9DDAEA8E-7B4F-4CC1-80FC-0D511D230689}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU
|
||||
{9DDAEA8E-7B4F-4CC1-80FC-0D511D230689}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{9DDAEA8E-7B4F-4CC1-80FC-0D511D230689}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{9DDAEA8E-7B4F-4CC1-80FC-0D511D230689}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{9DDAEA8E-7B4F-4CC1-80FC-0D511D230689}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{9DDAEA8E-7B4F-4CC1-80FC-0D511D230689}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{9DDAEA8E-7B4F-4CC1-80FC-0D511D230689}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{9DDAEA8E-7B4F-4CC1-80FC-0D511D230689}.Release|ARM.ActiveCfg = Release|Any CPU
|
||||
{9DDAEA8E-7B4F-4CC1-80FC-0D511D230689}.Release|ARM.Build.0 = Release|Any CPU
|
||||
{9DDAEA8E-7B4F-4CC1-80FC-0D511D230689}.Release|iPhone.ActiveCfg = Release|Any CPU
|
||||
{9DDAEA8E-7B4F-4CC1-80FC-0D511D230689}.Release|iPhone.Build.0 = Release|Any CPU
|
||||
{9DDAEA8E-7B4F-4CC1-80FC-0D511D230689}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
|
||||
{9DDAEA8E-7B4F-4CC1-80FC-0D511D230689}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
|
||||
{9DDAEA8E-7B4F-4CC1-80FC-0D511D230689}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{9DDAEA8E-7B4F-4CC1-80FC-0D511D230689}.Release|x64.Build.0 = Release|Any CPU
|
||||
{9DDAEA8E-7B4F-4CC1-80FC-0D511D230689}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{9DDAEA8E-7B4F-4CC1-80FC-0D511D230689}.Release|x86.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
<DebugType>portable</DebugType>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
</PropertyGroup>
|
||||
|
||||
|
|
@ -17,13 +17,19 @@
|
|||
<None Remove="OGL.txt" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="..\..\Data\monsters.json" Link="monsters.json" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="..\..\Data\spells.json" Link="spells.json" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="OGL.txt" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.0.3" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.0.3" />
|
||||
<PackageReference Include="SkiaSharp.Views.Forms" Version="1.60.0" />
|
||||
<PackageReference Include="Xamarin.Forms" Version="3.0.0.446417" />
|
||||
</ItemGroup>
|
||||
|
|
@ -49,6 +55,7 @@
|
|||
|
||||
<ItemGroup>
|
||||
<Folder Include="Models\" />
|
||||
<Folder Include="Services\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
@ -1,43 +0,0 @@
|
|||
using AideDeJeu.Tools;
|
||||
using AideDeJeuLib.Monsters;
|
||||
using AideDeJeuLib.Spells;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using Xamarin.Forms;
|
||||
|
||||
namespace AideDeJeu.Services
|
||||
{
|
||||
public class ItemDatabaseContext : DbContext
|
||||
{
|
||||
private const string databaseName = "database.db";
|
||||
|
||||
public DbSet<Spell> Spells { get; set; }
|
||||
|
||||
public DbSet<Monster> Monsters { get; set; }
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
String databasePath = "";
|
||||
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<INativeAPI>().GetDatabasePath(databaseName);
|
||||
break;
|
||||
case Device.UWP:
|
||||
databasePath = DependencyService.Get<INativeAPI>().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}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,4 @@
|
|||
using AideDeJeu.Services;
|
||||
using AideDeJeu.Tools;
|
||||
using AideDeJeu.Tools;
|
||||
using AideDeJeuLib.Monsters;
|
||||
using AideDeJeuLib.Spells;
|
||||
using System;
|
||||
|
|
@ -52,36 +51,36 @@ namespace AideDeJeu.ViewModels
|
|||
private int countUpdateData = 0;
|
||||
private async Task ExecuteUpdateDataCommandAsync()
|
||||
{
|
||||
if (countUpdateData++ != 5) return;
|
||||
//if (countUpdateData++ != 5) return;
|
||||
|
||||
IsBusy = true;
|
||||
var helper = new ItemDatabaseHelper<ItemDatabaseContext>();
|
||||
//IsBusy = true;
|
||||
//var helper = new ItemDatabaseHelper();
|
||||
|
||||
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 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);
|
||||
}
|
||||
//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;
|
||||
//IsBusy = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,12 +1,14 @@
|
|||
using AideDeJeu.Services;
|
||||
using AideDeJeu.Tools;
|
||||
using AideDeJeu.Tools;
|
||||
using AideDeJeuLib;
|
||||
using AideDeJeuLib.Monsters;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.Serialization.Json;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AideDeJeu.ViewModels
|
||||
|
|
@ -227,6 +229,61 @@ namespace AideDeJeu.ViewModels
|
|||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private string MonstersJson
|
||||
{
|
||||
get
|
||||
{
|
||||
var assembly = typeof(AboutViewModel).GetTypeInfo().Assembly;
|
||||
//var names = assembly.GetManifestResourceNames();
|
||||
using (var stream = assembly.GetManifestResourceStream("AideDeJeu.monsters.json"))
|
||||
{
|
||||
using (var reader = new System.IO.StreamReader(stream))
|
||||
{
|
||||
return reader.ReadToEnd();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerable<Monster> _Monsters = null;
|
||||
private IEnumerable<Monster> Monsters
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_Monsters == null)
|
||||
{
|
||||
DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(IEnumerable<Monster>));
|
||||
MemoryStream stream = new MemoryStream();
|
||||
var writer = new StreamWriter(stream);
|
||||
writer.Write(MonstersJson);
|
||||
writer.Flush();
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
_Monsters = serializer.ReadObject(stream) as IEnumerable<Monster>;
|
||||
}
|
||||
return _Monsters;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<Monster> GetMonsters(string category, string type, string minPower, string maxPower, string size, string legendary, string source)
|
||||
{
|
||||
var powerComparer = new PowerComparer();
|
||||
return Monsters.Where(monster =>
|
||||
monster.Type.Contains(type) &&
|
||||
(string.IsNullOrEmpty(size) || monster.Size.Equals(size)) &&
|
||||
monster.Source.Contains(source) &&
|
||||
powerComparer.Compare(monster.Challenge, minPower) >= 0 &&
|
||||
powerComparer.Compare(monster.Challenge, maxPower) <= 0
|
||||
)
|
||||
.OrderBy(monster => monster.NamePHB)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
|
||||
public override async Task ExecuteLoadItemsCommandAsync()
|
||||
{
|
||||
if (IsBusy)
|
||||
|
|
@ -239,12 +296,13 @@ namespace AideDeJeu.ViewModels
|
|||
AllItems.Clear();
|
||||
//var items = await new MonstersScrappers().GetMonsters(category: Categories[Category].Key, type: Types[Type].Key, minPower: Powers[MinPower].Key, maxPower: Powers[MaxPower].Key, size: Sizes[Size].Key, legendary:Legendaries[Legendary].Key, source: Sources[Source].Key);
|
||||
|
||||
ItemDatabaseHelper<ItemDatabaseContext> helper = new ItemDatabaseHelper<ItemDatabaseContext>();
|
||||
var items = await helper.GetMonstersAsync(category: Categories[Category].Key, type: Types[Type].Key, minPower: Powers[MinPower].Key, maxPower: Powers[MaxPower].Key, size: Sizes[Size].Key, legendary: Legendaries[Legendary].Key, source: Sources[Source].Key);
|
||||
//ItemDatabaseHelper helper = new ItemDatabaseHelper();
|
||||
//var items = await helper.GetMonstersAsync(category: Categories[Category].Key, type: Types[Type].Key, minPower: Powers[MinPower].Key, maxPower: Powers[MaxPower].Key, size: Sizes[Size].Key, legendary: Legendaries[Legendary].Key, source: Sources[Source].Key);
|
||||
var items = GetMonsters(category: Categories[Category].Key, type: Types[Type].Key, minPower: Powers[MinPower].Key, maxPower: Powers[MaxPower].Key, size: Sizes[Size].Key, legendary: Legendaries[Legendary].Key, source: Sources[Source].Key);
|
||||
|
||||
var aitems = items.ToArray();
|
||||
Array.Sort(aitems, new ItemComparer());
|
||||
foreach (var item in aitems)
|
||||
//var aitems = items.ToArray();
|
||||
//Array.Sort(aitems, new ItemComparer());
|
||||
foreach (var item in items)
|
||||
{
|
||||
AllItems.Add(item);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,13 @@
|
|||
using AideDeJeu.Services;
|
||||
using AideDeJeu.Tools;
|
||||
using AideDeJeuLib;
|
||||
using AideDeJeuLib;
|
||||
using AideDeJeuLib.Spells;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.Serialization.Json;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AideDeJeu.ViewModels
|
||||
|
|
@ -178,6 +179,57 @@ namespace AideDeJeu.ViewModels
|
|||
{
|
||||
}
|
||||
|
||||
private string SpellsJson
|
||||
{
|
||||
get
|
||||
{
|
||||
var assembly = typeof(AboutViewModel).GetTypeInfo().Assembly;
|
||||
//var names = assembly.GetManifestResourceNames();
|
||||
using (var stream = assembly.GetManifestResourceStream("AideDeJeu.spells.json"))
|
||||
{
|
||||
using (var reader = new System.IO.StreamReader(stream))
|
||||
{
|
||||
return reader.ReadToEnd();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerable<Spell> _Spells = null;
|
||||
private IEnumerable<Spell> Spells
|
||||
{
|
||||
get
|
||||
{
|
||||
if(_Spells == null)
|
||||
{
|
||||
DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(IEnumerable<Spell>));
|
||||
MemoryStream stream = new MemoryStream();
|
||||
var writer = new StreamWriter(stream);
|
||||
writer.Write(SpellsJson);
|
||||
writer.Flush();
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
_Spells = serializer.ReadObject(stream) as IEnumerable<Spell>;
|
||||
}
|
||||
return _Spells;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<Spell> GetSpells(string classe, string niveauMin, string niveauMax, string ecole, string rituel, string source)
|
||||
{
|
||||
return Spells.Where(spell =>
|
||||
(int.Parse(spell.Level) >= int.Parse(niveauMin)) &&
|
||||
(int.Parse(spell.Level) <= int.Parse(niveauMax)) &&
|
||||
spell.Type.Contains(ecole) &&
|
||||
spell.Source.Contains(source) &&
|
||||
spell.Source.Contains(classe) &&
|
||||
spell.Type.Contains(rituel)
|
||||
)
|
||||
.OrderBy(spell => spell.NamePHB)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
|
||||
public override async Task ExecuteLoadItemsCommandAsync()
|
||||
{
|
||||
if (IsBusy)
|
||||
|
|
@ -194,10 +246,11 @@ namespace AideDeJeu.ViewModels
|
|||
// 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);
|
||||
//}
|
||||
|
||||
ItemDatabaseHelper<ItemDatabaseContext> helper = new ItemDatabaseHelper<ItemDatabaseContext>();
|
||||
items = await helper.GetSpellsAsync(classe: Classes[Classe].Key, niveauMin: Niveaux[NiveauMin].Key, niveauMax: Niveaux[NiveauMax].Key, ecole: Ecoles[Ecole].Key, rituel: Rituels[Rituel].Key, source: Sources[Source].Key);
|
||||
|
||||
|
||||
//ItemDatabaseHelper helper = new ItemDatabaseHelper();
|
||||
//items = await helper.GetSpellsAsync(classe: Classes[Classe].Key, niveauMin: Niveaux[NiveauMin].Key, niveauMax: Niveaux[NiveauMax].Key, ecole: Ecoles[Ecole].Key, rituel: Rituels[Rituel].Key, source: Sources[Source].Key);
|
||||
items = 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);
|
||||
//items = Spells;
|
||||
|
||||
//try
|
||||
//{
|
||||
//ItemDatabaseHelper<ItemDatabaseContext> helper = new ItemDatabaseHelper<ItemDatabaseContext>();
|
||||
|
|
@ -208,9 +261,9 @@ namespace AideDeJeu.ViewModels
|
|||
//{
|
||||
// Debug.WriteLine(ex);
|
||||
//}
|
||||
var aitems = items.ToArray();
|
||||
Array.Sort(aitems, new ItemComparer());
|
||||
foreach (var item in aitems)
|
||||
//var aitems = items.ToArray();
|
||||
//Array.Sort(aitems, new ItemComparer());
|
||||
foreach (var item in items)
|
||||
{
|
||||
AllItems.Add(item);
|
||||
}
|
||||
|
|
|
|||
18
AideDeJeu/AideDeJeuCmd/AideDeJeuCmd.csproj
Normal file
18
AideDeJeu/AideDeJeuCmd/AideDeJeuCmd.csproj
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp2.0</TargetFramework>
|
||||
<LangVersion>latest</LangVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.0.3" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="2.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\AideDeJeu\AideDeJeu.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
50
AideDeJeu/AideDeJeuCmd/ItemDatabaseContext.cs
Normal file
50
AideDeJeu/AideDeJeuCmd/ItemDatabaseContext.cs
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
using AideDeJeu.Tools;
|
||||
using AideDeJeuLib.Monsters;
|
||||
using AideDeJeuLib.Spells;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using Xamarin.Forms;
|
||||
|
||||
namespace AideDeJeu.Services
|
||||
{
|
||||
public class ItemDatabaseContext : DbContext
|
||||
{
|
||||
public ItemDatabaseContext(string databasePath)
|
||||
{
|
||||
DatabasePath = databasePath;
|
||||
}
|
||||
private string DatabasePath = null;
|
||||
private string DatabaseName = "database.db";
|
||||
|
||||
public DbSet<Spell> Spells { get; set; }
|
||||
|
||||
public DbSet<Monster> Monsters { get; set; }
|
||||
|
||||
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<INativeAPI>().GetDatabasePath(DatabaseName);
|
||||
break;
|
||||
case Device.UWP:
|
||||
DatabasePath = DependencyService.Get<INativeAPI>().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}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -10,11 +10,17 @@ using System.Threading.Tasks;
|
|||
|
||||
namespace AideDeJeu.Services
|
||||
{
|
||||
public class ItemDatabaseHelper<T> where T : ItemDatabaseContext
|
||||
public class ItemDatabaseHelper
|
||||
{
|
||||
protected async Task<T> CreateContextAsync()
|
||||
private string DatabasePath = null;
|
||||
public ItemDatabaseHelper(string databasePath = null)
|
||||
{
|
||||
T postDatabaseContext = (T)Activator.CreateInstance(typeof(T));
|
||||
DatabasePath = databasePath;
|
||||
}
|
||||
|
||||
protected async Task<ItemDatabaseContext> CreateContextAsync()
|
||||
{
|
||||
ItemDatabaseContext postDatabaseContext = (ItemDatabaseContext)Activator.CreateInstance(typeof(ItemDatabaseContext), DatabasePath);
|
||||
await postDatabaseContext.Database.EnsureCreatedAsync().ConfigureAwait(false);
|
||||
await postDatabaseContext.Database.MigrateAsync().ConfigureAwait(false);
|
||||
return postDatabaseContext;
|
||||
|
|
@ -34,7 +40,7 @@ namespace AideDeJeu.Services
|
|||
spell.Source.Contains(classe) &&
|
||||
spell.Type.Contains(rituel)
|
||||
)
|
||||
//.OrderByDescending(spell => spell.NamePHB)
|
||||
.OrderBy(spell => spell.NamePHB)
|
||||
.ToListAsync().ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
|
@ -66,7 +72,7 @@ namespace AideDeJeu.Services
|
|||
powerComparer.Compare(monster.Challenge, minPower) >= 0 &&
|
||||
powerComparer.Compare(monster.Challenge, maxPower) <= 0
|
||||
)
|
||||
//.OrderByDescending(monster => monster.Id)
|
||||
.OrderBy(monster => monster.NamePHB)
|
||||
.ToListAsync().ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
32
AideDeJeu/AideDeJeuCmd/Program.cs
Normal file
32
AideDeJeu/AideDeJeuCmd/Program.cs
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
using AideDeJeu.Services;
|
||||
using AideDeJeuLib.Spells;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Runtime.Serialization.Json;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AideDeJeuCmd
|
||||
{
|
||||
class Program
|
||||
{
|
||||
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)");
|
||||
|
||||
foreach (var item in items)
|
||||
{
|
||||
|
||||
}
|
||||
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!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -6,7 +6,6 @@
|
|||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="HtmlAgilityPack" Version="1.8.2" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="2.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
|||
BIN
Data/database_idx.db
Normal file
BIN
Data/database_idx.db
Normal file
Binary file not shown.
1
Data/monsters.json
Normal file
1
Data/monsters.json
Normal file
File diff suppressed because one or more lines are too long
1
Data/spells.json
Normal file
1
Data/spells.json
Normal file
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue