mirror of
https://github.com/Nioux/AideDeJeu.git
synced 2025-10-30 15:06:06 +00:00
Ajout database et début utilisation pour les spells
This commit is contained in:
parent
da08a4d387
commit
1f23facbb7
14 changed files with 197 additions and 10 deletions
|
|
@ -66,7 +66,7 @@
|
||||||
<Compile Include="MainActivity.cs" />
|
<Compile Include="MainActivity.cs" />
|
||||||
<Compile Include="Resources\Resource.Designer.cs" />
|
<Compile Include="Resources\Resource.Designer.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="Version.cs" />
|
<Compile Include="NativeAPI.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<AndroidAsset Include="Assets\LinLibertine_R.ttf" />
|
<AndroidAsset Include="Assets\LinLibertine_R.ttf" />
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,12 @@
|
||||||
using AideDeJeu.Tools;
|
using AideDeJeu.Tools;
|
||||||
using Android.Content.PM;
|
using Android.Content.PM;
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
[assembly: Xamarin.Forms.Dependency(typeof(AideDeJeu.Droid.Version_Android))]
|
[assembly: Xamarin.Forms.Dependency(typeof(AideDeJeu.Droid.Version_Android))]
|
||||||
namespace AideDeJeu.Droid
|
namespace AideDeJeu.Droid
|
||||||
{
|
{
|
||||||
public class Version_Android : IAppVersion
|
public class Version_Android : INativeAPI
|
||||||
{
|
{
|
||||||
public string GetVersion()
|
public string GetVersion()
|
||||||
{
|
{
|
||||||
|
|
@ -24,5 +26,10 @@ namespace AideDeJeu.Droid
|
||||||
|
|
||||||
return info.VersionCode;
|
return info.VersionCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string GetDatabasePath(string databaseName)
|
||||||
|
{
|
||||||
|
return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), databaseName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -95,6 +95,7 @@
|
||||||
<Compile Include="MainPage.xaml.cs">
|
<Compile Include="MainPage.xaml.cs">
|
||||||
<DependentUpon>MainPage.xaml</DependentUpon>
|
<DependentUpon>MainPage.xaml</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="NativeAPI.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
|
||||||
24
AideDeJeu/AideDeJeu.UWP/NativeAPI.cs
Normal file
24
AideDeJeu/AideDeJeu.UWP/NativeAPI.cs
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
using AideDeJeu.Tools;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
|
[assembly: Xamarin.Forms.Dependency(typeof(AideDeJeu.Droid.Version_Android))]
|
||||||
|
namespace AideDeJeu.Droid
|
||||||
|
{
|
||||||
|
public class Version_Android : INativeAPI
|
||||||
|
{
|
||||||
|
public string GetVersion()
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public int GetBuild()
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetDatabasePath(string databaseName)
|
||||||
|
{
|
||||||
|
return Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, databaseName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -4,11 +4,18 @@
|
||||||
<TargetFramework>netstandard2.0</TargetFramework>
|
<TargetFramework>netstandard2.0</TargetFramework>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||||
|
<DebugType>pdbonly</DebugType>
|
||||||
|
<DebugSymbols>true</DebugSymbols>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<EmbeddedResource Remove="Resources\AdJTheme.xaml" />
|
<EmbeddedResource Remove="Resources\AdJTheme.xaml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<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="SkiaSharp.Views.Forms" Version="1.60.0" />
|
||||||
<PackageReference Include="Xamarin.Forms" Version="3.0.0.446417" />
|
<PackageReference Include="Xamarin.Forms" Version="3.0.0.446417" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
@ -34,7 +41,6 @@
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="Models\" />
|
<Folder Include="Models\" />
|
||||||
<Folder Include="Services\" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
43
AideDeJeu/AideDeJeu/Services/ItemDatabaseContext.cs
Normal file
43
AideDeJeu/AideDeJeu/Services/ItemDatabaseContext.cs
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
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}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
46
AideDeJeu/AideDeJeu/Services/ItemDatabaseHelper.cs
Normal file
46
AideDeJeu/AideDeJeu/Services/ItemDatabaseHelper.cs
Normal file
|
|
@ -0,0 +1,46 @@
|
||||||
|
using AideDeJeuLib.Spells;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AideDeJeu.Services
|
||||||
|
{
|
||||||
|
public class ItemDatabaseHelper<T> where T : ItemDatabaseContext
|
||||||
|
{
|
||||||
|
protected T CreateContext()
|
||||||
|
{
|
||||||
|
T postDatabaseContext = (T)Activator.CreateInstance(typeof(T));
|
||||||
|
postDatabaseContext.Database.EnsureCreated();
|
||||||
|
postDatabaseContext.Database.Migrate();
|
||||||
|
return postDatabaseContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IEnumerable<Spell>> GetSpellsAsync()
|
||||||
|
{
|
||||||
|
using (var context = CreateContext())
|
||||||
|
{
|
||||||
|
//We use OrderByDescending because Posts are generally displayed from most recent to oldest
|
||||||
|
return await context.Spells
|
||||||
|
.AsNoTracking()
|
||||||
|
.OrderByDescending(spell => spell.Id)
|
||||||
|
.ToListAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task AddOrUpdateSpellsAsync(IEnumerable<Spell> spells)
|
||||||
|
{
|
||||||
|
using (var context = CreateContext())
|
||||||
|
{
|
||||||
|
// add posts that do not exist in the database
|
||||||
|
var newSpells = spells.Where(
|
||||||
|
spell => context.Spells.Any(dbSpell => dbSpell.Id == spell.Id) == false
|
||||||
|
);
|
||||||
|
await context.Spells.AddRangeAsync(newSpells);
|
||||||
|
await context.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -4,9 +4,10 @@ using System.Text;
|
||||||
|
|
||||||
namespace AideDeJeu.Tools
|
namespace AideDeJeu.Tools
|
||||||
{
|
{
|
||||||
public interface IAppVersion
|
public interface INativeAPI
|
||||||
{
|
{
|
||||||
string GetVersion();
|
string GetVersion();
|
||||||
int GetBuild();
|
int GetBuild();
|
||||||
|
string GetDatabasePath(string databaseName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -20,7 +20,7 @@ namespace AideDeJeu.ViewModels
|
||||||
public string Version {
|
public string Version {
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return DependencyService.Get<IAppVersion>().GetVersion();
|
return DependencyService.Get<INativeAPI>().GetVersion();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
using AideDeJeu.Tools;
|
using AideDeJeu.Services;
|
||||||
|
using AideDeJeu.Tools;
|
||||||
using AideDeJeuLib;
|
using AideDeJeuLib;
|
||||||
using AideDeJeuLib.Spells;
|
using AideDeJeuLib.Spells;
|
||||||
using System;
|
using System;
|
||||||
|
|
@ -170,7 +171,18 @@ namespace AideDeJeu.ViewModels
|
||||||
{
|
{
|
||||||
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);
|
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);
|
||||||
var aitems = items.ToArray();
|
|
||||||
|
//try
|
||||||
|
//{
|
||||||
|
ItemDatabaseHelper<ItemDatabaseContext> helper = new ItemDatabaseHelper<ItemDatabaseContext>();
|
||||||
|
await helper.AddOrUpdateSpellsAsync(items);
|
||||||
|
var items2 = await helper.GetSpellsAsync();
|
||||||
|
//}
|
||||||
|
//catch(Exception ex)
|
||||||
|
//{
|
||||||
|
// Debug.WriteLine(ex);
|
||||||
|
//}
|
||||||
|
var aitems = items2.ToArray();
|
||||||
Array.Sort(aitems, new ItemComparer());
|
Array.Sort(aitems, new ItemComparer());
|
||||||
foreach (var item in aitems)
|
foreach (var item in aitems)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -8,4 +8,10 @@
|
||||||
<PackageReference Include="HtmlAgilityPack" Version="1.8.1" />
|
<PackageReference Include="HtmlAgilityPack" Version="1.8.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="System.ComponentModel.Annotations">
|
||||||
|
<HintPath>..\..\..\..\..\..\..\..\Program Files (x86)\Microsoft SDKs\UWPNuGetPackages\microsoft.netcore.universalwindowsplatform\6.1.4\ref\uap10.0.15138\System.ComponentModel.Annotations.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,13 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace AideDeJeuLib
|
namespace AideDeJeuLib
|
||||||
{
|
{
|
||||||
public class Item
|
public class Item
|
||||||
{
|
{
|
||||||
|
[Key]
|
||||||
public string Id { get; set; }
|
public string Id { get; set; }
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
public string NameVO { get; set; }
|
public string NameVO { get; set; }
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,9 @@
|
||||||
using HtmlAgilityPack;
|
using HtmlAgilityPack;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Runtime.Serialization;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
|
|
@ -35,8 +38,33 @@ namespace AideDeJeuLib.Monsters
|
||||||
public string Description { get; set; }
|
public string Description { get; set; }
|
||||||
public string Picture { get; set; }
|
public string Picture { get; set; }
|
||||||
|
|
||||||
|
[IgnoreDataMember]
|
||||||
|
[NotMapped]
|
||||||
public List<HtmlNode> SpecialFeatures { get; set; }
|
public List<HtmlNode> SpecialFeatures { get; set; }
|
||||||
|
//public List<string> SpecialFeaturesPersist
|
||||||
|
//{
|
||||||
|
// get
|
||||||
|
// {
|
||||||
|
// return SpecialFeatures.Select(node => node.OuterHtml).ToList();
|
||||||
|
// }
|
||||||
|
// set
|
||||||
|
// {
|
||||||
|
// List<HtmlNode> nodes = new List<HtmlNode>();
|
||||||
|
// foreach (var str in value)
|
||||||
|
// {
|
||||||
|
// HtmlDocument doc = new HtmlDocument();
|
||||||
|
// doc.LoadHtml(str);
|
||||||
|
// nodes.Add(doc.DocumentNode);
|
||||||
|
// }
|
||||||
|
// SpecialFeatures = nodes;
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
|
[IgnoreDataMember]
|
||||||
|
[NotMapped]
|
||||||
public List<HtmlNode> Actions { get; set; }
|
public List<HtmlNode> Actions { get; set; }
|
||||||
|
[IgnoreDataMember]
|
||||||
|
[NotMapped]
|
||||||
public List<HtmlNode> LegendaryActions { get; set; }
|
public List<HtmlNode> LegendaryActions { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
using HtmlAgilityPack;
|
using HtmlAgilityPack;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
using System.Runtime.Serialization;
|
using System.Runtime.Serialization;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
|
@ -26,9 +28,16 @@ namespace AideDeJeuLib.Spells
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
HtmlDocument doc = new HtmlDocument();
|
if (value != null)
|
||||||
doc.LoadHtml(value);
|
{
|
||||||
DescriptionDiv = doc.DocumentNode;
|
HtmlDocument doc = new HtmlDocument();
|
||||||
|
doc.LoadHtml(value);
|
||||||
|
DescriptionDiv = doc.DocumentNode;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DescriptionDiv = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public string DescriptionText
|
public string DescriptionText
|
||||||
|
|
@ -39,7 +48,9 @@ namespace AideDeJeuLib.Spells
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
[IgnoreDataMember]
|
[IgnoreDataMember]
|
||||||
|
[NotMapped]
|
||||||
public HtmlNode DescriptionDiv { get; set; }
|
public HtmlNode DescriptionDiv { get; set; }
|
||||||
|
|
||||||
public string Overflow { get; set; }
|
public string Overflow { get; set; }
|
||||||
public string NoOverflow { get; set; }
|
public string NoOverflow { get; set; }
|
||||||
public string Source { get; set; }
|
public string Source { get; set; }
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue