mirror of
				https://github.com/Nioux/AideDeJeu.git
				synced 2025-10-31 07:26:09 +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 | EndProject | ||||||
| Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AideDeJeuLib", "AideDeJeu\AideDeJeuLib\AideDeJeuLib.csproj", "{948BB32D-BAB8-485D-8A6F-BE5391E824A3}" | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AideDeJeuLib", "AideDeJeu\AideDeJeuLib\AideDeJeuLib.csproj", "{948BB32D-BAB8-485D-8A6F-BE5391E824A3}" | ||||||
| EndProject | 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 | EndProject | ||||||
| Global | Global | ||||||
| 	GlobalSection(SolutionConfigurationPlatforms) = preSolution | 	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|x64.Build.0 = Release|Any CPU | ||||||
| 		{D5065DC7-7B51-4D25-8FA5-DDF0F3E6FCE4}.Release|x86.ActiveCfg = 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 | 		{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 | 	EndGlobalSection | ||||||
| 	GlobalSection(SolutionProperties) = preSolution | 	GlobalSection(SolutionProperties) = preSolution | ||||||
| 		HideSolutionNode = FALSE | 		HideSolutionNode = FALSE | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ | ||||||
|   </PropertyGroup> |   </PropertyGroup> | ||||||
| 
 | 
 | ||||||
|   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> |   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> | ||||||
|     <DebugType>portable</DebugType> |     <DebugType>pdbonly</DebugType> | ||||||
|     <DebugSymbols>true</DebugSymbols> |     <DebugSymbols>true</DebugSymbols> | ||||||
|   </PropertyGroup> |   </PropertyGroup> | ||||||
| 
 | 
 | ||||||
|  | @ -17,13 +17,19 @@ | ||||||
|     <None Remove="OGL.txt" /> |     <None Remove="OGL.txt" /> | ||||||
|   </ItemGroup> |   </ItemGroup> | ||||||
| 
 | 
 | ||||||
|  |   <ItemGroup> | ||||||
|  |     <EmbeddedResource Include="..\..\Data\monsters.json" Link="monsters.json" /> | ||||||
|  |   </ItemGroup> | ||||||
|  | 
 | ||||||
|  |   <ItemGroup> | ||||||
|  |     <EmbeddedResource Include="..\..\Data\spells.json" Link="spells.json" /> | ||||||
|  |   </ItemGroup> | ||||||
|  | 
 | ||||||
|   <ItemGroup> |   <ItemGroup> | ||||||
|     <EmbeddedResource Include="OGL.txt" /> |     <EmbeddedResource Include="OGL.txt" /> | ||||||
|   </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> | ||||||
|  | @ -49,6 +55,7 @@ | ||||||
| 
 | 
 | ||||||
|   <ItemGroup> |   <ItemGroup> | ||||||
|     <Folder Include="Models\" /> |     <Folder Include="Models\" /> | ||||||
|  |     <Folder Include="Services\" /> | ||||||
|   </ItemGroup> |   </ItemGroup> | ||||||
| 
 | 
 | ||||||
| </Project> | </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.Monsters; | ||||||
| using AideDeJeuLib.Spells; | using AideDeJeuLib.Spells; | ||||||
| using System; | using System; | ||||||
|  | @ -52,36 +51,36 @@ namespace AideDeJeu.ViewModels | ||||||
|         private int countUpdateData = 0; |         private int countUpdateData = 0; | ||||||
|         private async Task ExecuteUpdateDataCommandAsync() |         private async Task ExecuteUpdateDataCommandAsync() | ||||||
|         { |         { | ||||||
|             if (countUpdateData++ != 5) return; |             //if (countUpdateData++ != 5) return; | ||||||
| 
 | 
 | ||||||
|             IsBusy = true; |             //IsBusy = true; | ||||||
|             var helper = new ItemDatabaseHelper<ItemDatabaseContext>(); |             //var helper = new ItemDatabaseHelper(); | ||||||
| 
 | 
 | ||||||
|             using (var spellsScrappers = new SpellsScrappers()) |             //using (var spellsScrappers = new SpellsScrappers()) | ||||||
|             { |             //{ | ||||||
|                 var partialSpells = await spellsScrappers.GetSpells(); |             //    var partialSpells = await spellsScrappers.GetSpells(); | ||||||
|                 var spells = new List<Spell>(); |             //    var spells = new List<Spell>(); | ||||||
|                 foreach (var partialSpell in partialSpells) |             //    foreach (var partialSpell in partialSpells) | ||||||
|                 { |             //    { | ||||||
|                     var spell = await spellsScrappers.GetSpell(partialSpell.Id); |             //        var spell = await spellsScrappers.GetSpell(partialSpell.Id); | ||||||
|                     spells.Add(spell); |             //        spells.Add(spell); | ||||||
|                 } |             //    } | ||||||
|                 await helper.AddOrUpdateSpellsAsync(spells); |             //    await helper.AddOrUpdateSpellsAsync(spells); | ||||||
|             } |             //} | ||||||
| 
 | 
 | ||||||
|             using (var monstersScrappers = new MonstersScrappers()) |             //using (var monstersScrappers = new MonstersScrappers()) | ||||||
|             { |             //{ | ||||||
|                 var partialMonsters = await monstersScrappers.GetMonsters(); |             //    var partialMonsters = await monstersScrappers.GetMonsters(); | ||||||
|                 var monsters = new List<Monster>(); |             //    var monsters = new List<Monster>(); | ||||||
|                 foreach (var partialMonster in partialMonsters) |             //    foreach (var partialMonster in partialMonsters) | ||||||
|                 { |             //    { | ||||||
|                     var monster = await monstersScrappers.GetMonster(partialMonster.Id); |             //        var monster = await monstersScrappers.GetMonster(partialMonster.Id); | ||||||
|                     monsters.Add(monster); |             //        monsters.Add(monster); | ||||||
|                 } |             //    } | ||||||
|                 await helper.AddOrUpdateMonstersAsync(monsters); |             //    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; | ||||||
| using AideDeJeuLib.Monsters; | using AideDeJeuLib.Monsters; | ||||||
| using System; | using System; | ||||||
| using System.Collections.Generic; | using System.Collections.Generic; | ||||||
| using System.Collections.ObjectModel; | using System.Collections.ObjectModel; | ||||||
| using System.Diagnostics; | using System.Diagnostics; | ||||||
|  | using System.IO; | ||||||
| using System.Linq; | using System.Linq; | ||||||
|  | using System.Reflection; | ||||||
|  | using System.Runtime.Serialization.Json; | ||||||
| using System.Threading.Tasks; | using System.Threading.Tasks; | ||||||
| 
 | 
 | ||||||
| namespace AideDeJeu.ViewModels | 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() |         public override async Task ExecuteLoadItemsCommandAsync() | ||||||
|         { |         { | ||||||
|             if (IsBusy) |             if (IsBusy) | ||||||
|  | @ -239,12 +296,13 @@ namespace AideDeJeu.ViewModels | ||||||
|                 AllItems.Clear(); |                 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); |                 //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>(); |                 //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 = 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(); |                 //var aitems = items.ToArray(); | ||||||
|                 Array.Sort(aitems, new ItemComparer()); |                 //Array.Sort(aitems, new ItemComparer()); | ||||||
|                 foreach (var item in aitems) |                 foreach (var item in items) | ||||||
|                 { |                 { | ||||||
|                     AllItems.Add(item); |                     AllItems.Add(item); | ||||||
|                 } |                 } | ||||||
|  |  | ||||||
|  | @ -1,12 +1,13 @@ | ||||||
| using AideDeJeu.Services; | using AideDeJeuLib; | ||||||
| using AideDeJeu.Tools; |  | ||||||
| using AideDeJeuLib; |  | ||||||
| using AideDeJeuLib.Spells; | using AideDeJeuLib.Spells; | ||||||
| using System; | using System; | ||||||
| using System.Collections.Generic; | using System.Collections.Generic; | ||||||
| using System.Collections.ObjectModel; | using System.Collections.ObjectModel; | ||||||
| using System.Diagnostics; | using System.Diagnostics; | ||||||
|  | using System.IO; | ||||||
| using System.Linq; | using System.Linq; | ||||||
|  | using System.Reflection; | ||||||
|  | using System.Runtime.Serialization.Json; | ||||||
| using System.Threading.Tasks; | using System.Threading.Tasks; | ||||||
| 
 | 
 | ||||||
| namespace AideDeJeu.ViewModels | 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() |         public override async Task ExecuteLoadItemsCommandAsync() | ||||||
|         { |         { | ||||||
|             if (IsBusy) |             if (IsBusy) | ||||||
|  | @ -194,9 +246,10 @@ 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); |                 //    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>(); |                 //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 = 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 |                 //try | ||||||
|                 //{ |                 //{ | ||||||
|  | @ -208,9 +261,9 @@ namespace AideDeJeu.ViewModels | ||||||
|                 //{ |                 //{ | ||||||
|                 //    Debug.WriteLine(ex); |                 //    Debug.WriteLine(ex); | ||||||
|                 //} |                 //} | ||||||
|                 var aitems = items.ToArray(); |                 //var aitems = items.ToArray(); | ||||||
|                 Array.Sort(aitems, new ItemComparer()); |                 //Array.Sort(aitems, new ItemComparer()); | ||||||
|                 foreach (var item in aitems) |                 foreach (var item in items) | ||||||
|                 { |                 { | ||||||
|                     AllItems.Add(item); |                     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 | 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.EnsureCreatedAsync().ConfigureAwait(false); | ||||||
|             await postDatabaseContext.Database.MigrateAsync().ConfigureAwait(false); |             await postDatabaseContext.Database.MigrateAsync().ConfigureAwait(false); | ||||||
|             return postDatabaseContext; |             return postDatabaseContext; | ||||||
|  | @ -34,7 +40,7 @@ namespace AideDeJeu.Services | ||||||
|                                         spell.Source.Contains(classe) && |                                         spell.Source.Contains(classe) && | ||||||
|                                         spell.Type.Contains(rituel) |                                         spell.Type.Contains(rituel) | ||||||
|                                         ) |                                         ) | ||||||
|                                     //.OrderByDescending(spell => spell.NamePHB) |                                     .OrderBy(spell => spell.NamePHB) | ||||||
|                                     .ToListAsync().ConfigureAwait(false); |                                     .ToListAsync().ConfigureAwait(false); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  | @ -66,7 +72,7 @@ namespace AideDeJeu.Services | ||||||
|                                         powerComparer.Compare(monster.Challenge, minPower) >= 0 && |                                         powerComparer.Compare(monster.Challenge, minPower) >= 0 && | ||||||
|                                         powerComparer.Compare(monster.Challenge, maxPower) <= 0 |                                         powerComparer.Compare(monster.Challenge, maxPower) <= 0 | ||||||
|                                         ) |                                         ) | ||||||
|                                     //.OrderByDescending(monster => monster.Id) |                                     .OrderBy(monster => monster.NamePHB) | ||||||
|                                     .ToListAsync().ConfigureAwait(false); |                                     .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> |   <ItemGroup> | ||||||
|     <PackageReference Include="HtmlAgilityPack" Version="1.8.2" /> |     <PackageReference Include="HtmlAgilityPack" Version="1.8.2" /> | ||||||
|     <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="2.0.3" /> |  | ||||||
|   </ItemGroup> |   </ItemGroup> | ||||||
| 
 | 
 | ||||||
|   <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
	
	 Yan Maniez
						Yan Maniez