1
0
Fork 0
mirror of https://github.com/Nioux/AideDeJeu.git synced 2025-10-29 22:45:44 +00:00

Première version entitydb fonctionnelle

This commit is contained in:
Yan Maniez 2018-10-14 18:27:32 +02:00
parent c85727686c
commit 0f6c47f2da
6 changed files with 67 additions and 46 deletions

View file

@ -73,6 +73,12 @@
<PackageReference Include="sqlite-net-pcl">
<Version>1.5.231</Version>
</PackageReference>
<PackageReference Include="System.Buffers">
<Version>4.5.0</Version>
</PackageReference>
<PackageReference Include="System.Memory">
<Version>4.5.1</Version>
</PackageReference>
<PackageReference Include="Xamarin.Forms">
<Version>3.2.0.871581</Version>
</PackageReference>

View file

@ -29,36 +29,36 @@ namespace AideDeJeu.Droid
public string GetDatabasePath(string databaseName)
{
string path = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
string dbPath = Path.Combine(path, databaseName);
return dbPath;
//var documentsDirectoryPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
//var path = Path.Combine(documentsDirectoryPath, databaseName);
//string path = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
//string dbPath = Path.Combine(path, databaseName);
//return dbPath;
var documentsDirectoryPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
var path = Path.Combine(documentsDirectoryPath, databaseName);
//// This is where we copy in our pre-created database
//if (!File.Exists(path))
//{
// using (var inStream = Android.App.Application.Context.Assets.Open(databaseName))
// {
// using (var outStream = new FileStream(path, FileMode.Create))
// {
// inStream.CopyTo(outStream);
// }
// }
// //using (var binaryReader = new BinaryReader(Android.App.Application.Context.Assets.Open(databaseName)))
// //{
// // using (var binaryWriter = new BinaryWriter(new FileStream(path, FileMode.Create)))
// // {
// // byte[] buffer = new byte[2048];
// // int length = 0;
// // while ((length = binaryReader.Read(buffer, 0, buffer.Length)) > 0)
// // {
// // binaryWriter.Write(buffer, 0, length);
// // }
// // }
// //}
//}
//return path;
// This is where we copy in our pre-created database
if (!File.Exists(path))
{
using (var inStream = Android.App.Application.Context.Assets.Open(databaseName))
{
using (var outStream = new FileStream(path, FileMode.Create))
{
inStream.CopyTo(outStream);
}
}
//using (var binaryReader = new BinaryReader(Android.App.Application.Context.Assets.Open(databaseName)))
//{
// using (var binaryWriter = new BinaryWriter(new FileStream(path, FileMode.Create)))
// {
// byte[] buffer = new byte[2048];
// int length = 0;
// while ((length = binaryReader.Read(buffer, 0, buffer.Length)) > 0)
// {
// binaryWriter.Write(buffer, 0, length);
// }
// }
//}
}
return path;
}
}
}

View file

@ -354,6 +354,7 @@ namespace AideDeJeu.ViewModels
{
var anchors = new Dictionary<string, Item>();
//MakeAnchors(source, anchors, item);
item.Id = $"{source}.md";
_AllItems[source] = item;
}
}
@ -365,38 +366,43 @@ namespace AideDeJeu.ViewModels
public class AideDeJeuContext : DbContext
{
public DbSet<Item> Items { get; set; }
public DbSet<Equipment> Equipments { get; set; }
public DbSet<Spell> Spells { get; set; }
public DbSet<Monster> Monsters { get; set; }
//private static bool _created = false;
//public AideDeJeuContext()
//{
// if (!_created)
// {
// _created = true;
// Database.EnsureDeleted();
// Database.EnsureCreated();
// }
//}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
var dbPath = DependencyService.Get<INativeAPI>().GetDatabasePath("database.db");
optionsBuilder.UseSqlite($"Data Source='{dbPath}'");
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<MonstersHD>();
modelBuilder.Entity<MonstersVO>();
modelBuilder.Entity<SpellsHD>();
modelBuilder.Entity<SpellsVO>();
}
}
public async Task<Item> GetItemFromDataAsync(string source, string anchor)
{
var id = $"{source}.md".TrimStart('/');
if (!string.IsNullOrEmpty(anchor))
{
id += $"#{anchor}";
}
using (var context = new AideDeJeuContext())
{
//var monsters = await context.Monsters.ToListAsync();
await context.SaveChangesAsync();
return await context.Items.Where(item => item.Id == id).FirstOrDefaultAsync();
}
return null;
}
var id = $"{source}.md#{anchor}";
public async Task<Item> GetItemFromDataAsyncOld(string source, string anchor)
{
var id = $"{source}.md".TrimStart('/');
//await Task.Delay(3000);
if (!_AllItems.ContainsKey(id) && !_AllItems.ContainsKey(source))
{

View file

@ -24,7 +24,7 @@ namespace AideDeJeu.Cmd
public string GetDatabasePath(string databaseName)
{
return Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), databaseName);
return Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), @"..\..\..\..\..\Data\" + databaseName);
}
}
}

View file

@ -297,11 +297,20 @@ namespace AideDeJeuCmd
//var store = new StoreViewModel();
//await store.GetItemFromDataAsync("test", "truc");
var store = new StoreViewModel();
await store.PreloadAllItemsAsync();
using (var context = new StoreViewModel.AideDeJeuContext())
{
await context.Database.EnsureDeletedAsync();
await context.Database.EnsureCreatedAsync();
await context.Items.AddRangeAsync(store._AllItems.Values);
await context.SaveChangesAsync();
var items = await context.Items.Where(item => (item.Source != null && item.Source.Contains("SRD"))).ToListAsync();
var monsters = await context.Monsters.ToListAsync();
var spells = await context.Spells.ToListAsync();
}
return;

Binary file not shown.