mirror of
				https://github.com/Nioux/AideDeJeu.git
				synced 2025-10-31 07:26:09 +00:00 
			
		
		
		
	Première version entitydb fonctionnelle
This commit is contained in:
		
							parent
							
								
									c85727686c
								
							
						
					
					
						commit
						0f6c47f2da
					
				
					 6 changed files with 67 additions and 46 deletions
				
			
		|  | @ -73,6 +73,12 @@ | ||||||
|     <PackageReference Include="sqlite-net-pcl"> |     <PackageReference Include="sqlite-net-pcl"> | ||||||
|       <Version>1.5.231</Version> |       <Version>1.5.231</Version> | ||||||
|     </PackageReference> |     </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"> |     <PackageReference Include="Xamarin.Forms"> | ||||||
|       <Version>3.2.0.871581</Version> |       <Version>3.2.0.871581</Version> | ||||||
|     </PackageReference> |     </PackageReference> | ||||||
|  |  | ||||||
|  | @ -29,36 +29,36 @@ namespace AideDeJeu.Droid | ||||||
| 
 | 
 | ||||||
|         public string GetDatabasePath(string databaseName) |         public string GetDatabasePath(string databaseName) | ||||||
|         { |         { | ||||||
|             string path = Environment.GetFolderPath(Environment.SpecialFolder.Personal); |             //string path = Environment.GetFolderPath(Environment.SpecialFolder.Personal); | ||||||
|             string dbPath = Path.Combine(path, databaseName); |             //string dbPath = Path.Combine(path, databaseName); | ||||||
|             return dbPath; |             //return dbPath; | ||||||
|             //var documentsDirectoryPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal); |             var documentsDirectoryPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal); | ||||||
|             //var path = Path.Combine(documentsDirectoryPath, databaseName); |             var path = Path.Combine(documentsDirectoryPath, databaseName); | ||||||
| 
 | 
 | ||||||
|             //// This is where we copy in our pre-created database |             // This is where we copy in our pre-created database | ||||||
|             //if (!File.Exists(path)) |             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 inStream = Android.App.Application.Context.Assets.Open(databaseName)) |                 //    using (var binaryWriter = new BinaryWriter(new FileStream(path, FileMode.Create))) | ||||||
|                 //    { |                 //    { | ||||||
|             //        using (var outStream = new FileStream(path, FileMode.Create)) |                 //        byte[] buffer = new byte[2048]; | ||||||
|  |                 //        int length = 0; | ||||||
|  |                 //        while ((length = binaryReader.Read(buffer, 0, buffer.Length)) > 0) | ||||||
|                 //        { |                 //        { | ||||||
|             //            inStream.CopyTo(outStream); |                 //            binaryWriter.Write(buffer, 0, length); | ||||||
|                 //        } |                 //        } | ||||||
|                 //    } |                 //    } | ||||||
|             //    //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; |             } | ||||||
|  |             return path; | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | @ -354,6 +354,7 @@ namespace AideDeJeu.ViewModels | ||||||
|                             { |                             { | ||||||
|                                 var anchors = new Dictionary<string, Item>(); |                                 var anchors = new Dictionary<string, Item>(); | ||||||
|                                 //MakeAnchors(source, anchors, item); |                                 //MakeAnchors(source, anchors, item); | ||||||
|  |                                 item.Id = $"{source}.md"; | ||||||
|                                 _AllItems[source] = item; |                                 _AllItems[source] = item; | ||||||
|                             } |                             } | ||||||
|                         } |                         } | ||||||
|  | @ -365,38 +366,43 @@ namespace AideDeJeu.ViewModels | ||||||
| 
 | 
 | ||||||
|         public class AideDeJeuContext : DbContext |         public class AideDeJeuContext : DbContext | ||||||
|         { |         { | ||||||
|  |             public DbSet<Item> Items { get; set; } | ||||||
|  |             public DbSet<Equipment> Equipments { get; set; } | ||||||
|             public DbSet<Spell> Spells { get; set; } |             public DbSet<Spell> Spells { get; set; } | ||||||
|             public DbSet<Monster> Monsters { 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) |             protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) | ||||||
|             { |             { | ||||||
|                 var dbPath = DependencyService.Get<INativeAPI>().GetDatabasePath("database.db"); |                 var dbPath = DependencyService.Get<INativeAPI>().GetDatabasePath("database.db"); | ||||||
|                 optionsBuilder.UseSqlite($"Data Source='{dbPath}'"); |                 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) |         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()) |             using (var context = new AideDeJeuContext()) | ||||||
|             { |             { | ||||||
|                 //var monsters = await context.Monsters.ToListAsync(); |                 return await context.Items.Where(item => item.Id == id).FirstOrDefaultAsync(); | ||||||
|                 await context.SaveChangesAsync(); |             } | ||||||
|         } |         } | ||||||
|             return null; |  | ||||||
| 
 | 
 | ||||||
| 
 |         public async Task<Item> GetItemFromDataAsyncOld(string source, string anchor) | ||||||
|             var id = $"{source}.md#{anchor}"; |         { | ||||||
|  |             var id = $"{source}.md".TrimStart('/'); | ||||||
|             //await Task.Delay(3000); |             //await Task.Delay(3000); | ||||||
|             if (!_AllItems.ContainsKey(id) && !_AllItems.ContainsKey(source)) |             if (!_AllItems.ContainsKey(id) && !_AllItems.ContainsKey(source)) | ||||||
|             { |             { | ||||||
|  |  | ||||||
|  | @ -24,7 +24,7 @@ namespace AideDeJeu.Cmd | ||||||
| 
 | 
 | ||||||
|         public string GetDatabasePath(string databaseName) |         public string GetDatabasePath(string databaseName) | ||||||
|         { |         { | ||||||
|             return Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), databaseName); |             return Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), @"..\..\..\..\..\Data\" + databaseName); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | @ -297,11 +297,20 @@ namespace AideDeJeuCmd | ||||||
|             //var store = new StoreViewModel(); |             //var store = new StoreViewModel(); | ||||||
|             //await store.GetItemFromDataAsync("test", "truc"); |             //await store.GetItemFromDataAsync("test", "truc"); | ||||||
| 
 | 
 | ||||||
|  |             var store = new StoreViewModel(); | ||||||
|  |             await store.PreloadAllItemsAsync(); | ||||||
|  | 
 | ||||||
|             using (var context = new StoreViewModel.AideDeJeuContext()) |             using (var context = new StoreViewModel.AideDeJeuContext()) | ||||||
|             { |             { | ||||||
|                 await context.Database.EnsureDeletedAsync(); |                 await context.Database.EnsureDeletedAsync(); | ||||||
|                 await context.Database.EnsureCreatedAsync(); |                 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 monsters = await context.Monsters.ToListAsync(); | ||||||
|  |                 var spells = await context.Spells.ToListAsync(); | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             return; |             return; | ||||||
|  |  | ||||||
							
								
								
									
										
											BIN
										
									
								
								Data/database.db
									
										
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								Data/database.db
									
										
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Yan Maniez
						Yan Maniez