mirror of
				https://github.com/Nioux/AideDeJeu.git
				synced 2025-11-04 01:00:23 +00:00 
			
		
		
		
	Suppression dernières dépendances au site web
This commit is contained in:
		
							parent
							
								
									184994c0d8
								
							
						
					
					
						commit
						d2fad57ca6
					
				
					 3 changed files with 69 additions and 53 deletions
				
			
		| 
						 | 
					@ -11,17 +11,17 @@ namespace AideDeJeu.Services
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    public class ItemDatabaseHelper<T> where T : ItemDatabaseContext
 | 
					    public class ItemDatabaseHelper<T> where T : ItemDatabaseContext
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        protected T CreateContext()
 | 
					        protected async Task<T> CreateContextAsync()
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            T postDatabaseContext = (T)Activator.CreateInstance(typeof(T));
 | 
					            T postDatabaseContext = (T)Activator.CreateInstance(typeof(T));
 | 
				
			||||||
            postDatabaseContext.Database.EnsureCreated();
 | 
					            await postDatabaseContext.Database.EnsureCreatedAsync().ConfigureAwait(false);
 | 
				
			||||||
            postDatabaseContext.Database.Migrate();
 | 
					            await postDatabaseContext.Database.MigrateAsync().ConfigureAwait(false);
 | 
				
			||||||
            return postDatabaseContext;
 | 
					            return postDatabaseContext;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public async Task<IEnumerable<Spell>> GetSpellsAsync(string classe, string niveauMin, string niveauMax, string ecole, string rituel, string source)
 | 
					        public async Task<IEnumerable<Spell>> GetSpellsAsync(string classe, string niveauMin, string niveauMax, string ecole, string rituel, string source)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            using (var context = CreateContext())
 | 
					            using (var context = await CreateContextAsync().ConfigureAwait(false))
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                //We use OrderByDescending because Posts are generally displayed from most recent to oldest
 | 
					                //We use OrderByDescending because Posts are generally displayed from most recent to oldest
 | 
				
			||||||
                return await context.Spells
 | 
					                return await context.Spells
 | 
				
			||||||
| 
						 | 
					@ -34,27 +34,27 @@ namespace AideDeJeu.Services
 | 
				
			||||||
                                        spell.Source.Contains(classe) &&
 | 
					                                        spell.Source.Contains(classe) &&
 | 
				
			||||||
                                        spell.Type.Contains(rituel)
 | 
					                                        spell.Type.Contains(rituel)
 | 
				
			||||||
                                        )
 | 
					                                        )
 | 
				
			||||||
                                    .OrderByDescending(spell => spell.NamePHB)
 | 
					                                    //.OrderByDescending(spell => spell.NamePHB)
 | 
				
			||||||
                                    .ToListAsync();
 | 
					                                    .ToListAsync().ConfigureAwait(false);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public async Task AddOrUpdateSpellsAsync(IEnumerable<Spell> spells)
 | 
					        public async Task AddOrUpdateSpellsAsync(IEnumerable<Spell> spells)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            using (var context = CreateContext())
 | 
					            using (var context = await CreateContextAsync().ConfigureAwait(false))
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                // add posts that do not exist in the database
 | 
					                // add posts that do not exist in the database
 | 
				
			||||||
                var newSpells = spells.Where(
 | 
					                var newSpells = spells.Where(
 | 
				
			||||||
                    spell => context.Spells.Any(dbSpell => dbSpell.Id == spell.Id) == false
 | 
					                    spell => context.Spells.Any(dbSpell => dbSpell.Id == spell.Id) == false
 | 
				
			||||||
                );
 | 
					                );
 | 
				
			||||||
                await context.Spells.AddRangeAsync(newSpells);
 | 
					                await context.Spells.AddRangeAsync(newSpells).ConfigureAwait(false);
 | 
				
			||||||
                await context.SaveChangesAsync();
 | 
					                await context.SaveChangesAsync().ConfigureAwait(false);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public async Task<IEnumerable<Monster>> GetMonstersAsync(string category, string type, string minPower, string maxPower, string size, string legendary, string source)
 | 
					        public async Task<IEnumerable<Monster>> GetMonstersAsync(string category, string type, string minPower, string maxPower, string size, string legendary, string source)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            using (var context = CreateContext())
 | 
					            using (var context = await CreateContextAsync().ConfigureAwait(false))
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                //We use OrderByDescending because Posts are generally displayed from most recent to oldest
 | 
					                //We use OrderByDescending because Posts are generally displayed from most recent to oldest
 | 
				
			||||||
                return await context.Monsters
 | 
					                return await context.Monsters
 | 
				
			||||||
| 
						 | 
					@ -64,21 +64,21 @@ namespace AideDeJeu.Services
 | 
				
			||||||
                                        //("[" + monster.Size.Trim().ToUpper() + "]").Contains("[" + size.ToUpper() + "]") &&
 | 
					                                        //("[" + monster.Size.Trim().ToUpper() + "]").Contains("[" + size.ToUpper() + "]") &&
 | 
				
			||||||
                                        monster.Source.Contains(source)
 | 
					                                        monster.Source.Contains(source)
 | 
				
			||||||
                                        )
 | 
					                                        )
 | 
				
			||||||
                                    .OrderByDescending(monster => monster.Id)
 | 
					                                    //.OrderByDescending(monster => monster.Id)
 | 
				
			||||||
                                    .ToListAsync();
 | 
					                                    .ToListAsync().ConfigureAwait(false);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public async Task AddOrUpdateMonstersAsync(IEnumerable<Monster> monsters)
 | 
					        public async Task AddOrUpdateMonstersAsync(IEnumerable<Monster> monsters)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            using (var context = CreateContext())
 | 
					            using (var context = await CreateContextAsync().ConfigureAwait(false))
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                // add posts that do not exist in the database
 | 
					                // add posts that do not exist in the database
 | 
				
			||||||
                var newMonsters = monsters.Where(
 | 
					                var newMonsters = monsters.Where(
 | 
				
			||||||
                    monster => context.Monsters.Any(dbMonster => dbMonster.Id == monster.Id) == false
 | 
					                    monster => context.Monsters.Any(dbMonster => dbMonster.Id == monster.Id) == false
 | 
				
			||||||
                );
 | 
					                );
 | 
				
			||||||
                await context.Monsters.AddRangeAsync(newMonsters);
 | 
					                await context.Monsters.AddRangeAsync(newMonsters).ConfigureAwait(false);
 | 
				
			||||||
                await context.SaveChangesAsync();
 | 
					                await context.SaveChangesAsync().ConfigureAwait(false);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -294,9 +294,11 @@ namespace AideDeJeu.ViewModels
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            try
 | 
					            try
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
 | 
					                Item.ParseHtml();
 | 
				
			||||||
 | 
					                Item = _Item;
 | 
				
			||||||
                //Items.Clear();
 | 
					                //Items.Clear();
 | 
				
			||||||
                var item = await new MonstersScrappers().GetMonster(Item.Id);
 | 
					                //var item = await new MonstersScrappers().GetMonster(Item.Id);
 | 
				
			||||||
                Item = item;
 | 
					                //Item = item;
 | 
				
			||||||
                //foreach (var item in items)
 | 
					                //foreach (var item in items)
 | 
				
			||||||
                //{
 | 
					                //{
 | 
				
			||||||
                //    Items.Add(item);
 | 
					                //    Items.Add(item);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -83,24 +83,32 @@ namespace AideDeJeuLib.Monsters
 | 
				
			||||||
        public List<HtmlNode> LegendaryActions { get; set; }
 | 
					        public List<HtmlNode> LegendaryActions { get; set; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        public void ParseHtml()
 | 
				
			||||||
        public static Monster FromHtml(HtmlNode divBloc)
 | 
					 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            var monster = new Monster();
 | 
					            var pack = new HtmlDocument();
 | 
				
			||||||
            monster.Html = divBloc.OuterHtml;
 | 
					            pack.LoadHtml(this.Html);
 | 
				
			||||||
 | 
					            var divSpell = pack.DocumentNode.SelectNodes("//div[contains(@class,'bloc')]").FirstOrDefault();
 | 
				
			||||||
 | 
					            ParseNode(divSpell);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        //public static Monster FromHtml(HtmlNode divBloc)
 | 
				
			||||||
 | 
					        //{
 | 
				
			||||||
 | 
					        public void ParseNode(HtmlNode divBloc)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            //monster.Html = divBloc.OuterHtml;
 | 
				
			||||||
            var divMonster = divBloc?.SelectSingleNode("div[contains(@class,'monstre')]");
 | 
					            var divMonster = divBloc?.SelectSingleNode("div[contains(@class,'monstre')]");
 | 
				
			||||||
            monster.Name = divMonster?.SelectSingleNode("h1").InnerText;
 | 
					            this.Name = divMonster?.SelectSingleNode("h1").InnerText;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            var altNames = divMonster.SelectSingleNode("div[@class='trad']")?.InnerText;
 | 
					            var altNames = divMonster.SelectSingleNode("div[@class='trad']")?.InnerText;
 | 
				
			||||||
            if (altNames != null)
 | 
					            if (altNames != null)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                var matchNames = new Regex(@"\[ (?<vo>.*?) \](?: \[ (?<alt>.*?) \])?").Match(altNames);
 | 
					                var matchNames = new Regex(@"\[ (?<vo>.*?) \](?: \[ (?<alt>.*?) \])?").Match(altNames);
 | 
				
			||||||
                monster.NameVO = matchNames.Groups["vo"].Value;
 | 
					                this.NameVO = matchNames.Groups["vo"].Value;
 | 
				
			||||||
                monster.NamePHB = string.IsNullOrEmpty(matchNames.Groups["alt"].Value) ? monster.Name : matchNames.Groups["alt"].Value;
 | 
					                this.NamePHB = string.IsNullOrEmpty(matchNames.Groups["alt"].Value) ? this.Name : matchNames.Groups["alt"].Value;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            else
 | 
					            else
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                monster.NamePHB = monster.Name;
 | 
					                this.NamePHB = this.Name;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            var divSansSerif = divMonster?.SelectSingleNode("div[contains(@class,'sansSerif')]");
 | 
					            var divSansSerif = divMonster?.SelectSingleNode("div[contains(@class,'sansSerif')]");
 | 
				
			||||||
| 
						 | 
					@ -108,34 +116,34 @@ namespace AideDeJeuLib.Monsters
 | 
				
			||||||
            if (typeSizeAlignment != null)
 | 
					            if (typeSizeAlignment != null)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                var matchesTypeSizeAlignment = new Regex("(?<type>.*) de taille (?<size>.*), (?<alignment>.*)").Match(typeSizeAlignment);
 | 
					                var matchesTypeSizeAlignment = new Regex("(?<type>.*) de taille (?<size>.*), (?<alignment>.*)").Match(typeSizeAlignment);
 | 
				
			||||||
                monster.Type = matchesTypeSizeAlignment?.Groups["type"]?.Value?.Trim();
 | 
					                this.Type = matchesTypeSizeAlignment?.Groups["type"]?.Value?.Trim();
 | 
				
			||||||
                monster.Size = matchesTypeSizeAlignment?.Groups["size"]?.Value?.Trim();
 | 
					                this.Size = matchesTypeSizeAlignment?.Groups["size"]?.Value?.Trim();
 | 
				
			||||||
                monster.Alignment = matchesTypeSizeAlignment?.Groups["alignment"]?.Value?.Trim();
 | 
					                this.Alignment = matchesTypeSizeAlignment?.Groups["alignment"]?.Value?.Trim();
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            var divRed = divSansSerif?.SelectSingleNode("div[contains(@class,'red')]");
 | 
					            var divRed = divSansSerif?.SelectSingleNode("div[contains(@class,'red')]");
 | 
				
			||||||
            monster.ArmorClass = divRed?.SelectSingleNode("strong[contains(text(),'armure')]")?.NextSibling?.InnerText;
 | 
					            this.ArmorClass = divRed?.SelectSingleNode("strong[contains(text(),'armure')]")?.NextSibling?.InnerText;
 | 
				
			||||||
            monster.HitPoints = divRed?.SelectSingleNode("strong[contains(text(),'Points de vie')]")?.NextSibling?.InnerText;
 | 
					            this.HitPoints = divRed?.SelectSingleNode("strong[contains(text(),'Points de vie')]")?.NextSibling?.InnerText;
 | 
				
			||||||
            monster.Speed = divRed?.SelectSingleNode("strong[contains(text(),'Vitesse')]")?.NextSibling?.InnerText;
 | 
					            this.Speed = divRed?.SelectSingleNode("strong[contains(text(),'Vitesse')]")?.NextSibling?.InnerText;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            monster.Strength = divRed?.SelectSingleNode("div[contains(@class,'carac')]/strong[contains(text(),'FOR')]")?.NextSibling?.NextSibling?.InnerText;
 | 
					            this.Strength = divRed?.SelectSingleNode("div[contains(@class,'carac')]/strong[contains(text(),'FOR')]")?.NextSibling?.NextSibling?.InnerText;
 | 
				
			||||||
            monster.Dexterity = divRed?.SelectSingleNode("div[contains(@class,'carac')]/strong[contains(text(),'DEX')]")?.NextSibling?.NextSibling?.InnerText;
 | 
					            this.Dexterity = divRed?.SelectSingleNode("div[contains(@class,'carac')]/strong[contains(text(),'DEX')]")?.NextSibling?.NextSibling?.InnerText;
 | 
				
			||||||
            monster.Constitution = divRed?.SelectSingleNode("div[contains(@class,'carac')]/strong[contains(text(),'CON')]")?.NextSibling?.NextSibling?.InnerText;
 | 
					            this.Constitution = divRed?.SelectSingleNode("div[contains(@class,'carac')]/strong[contains(text(),'CON')]")?.NextSibling?.NextSibling?.InnerText;
 | 
				
			||||||
            monster.Intelligence = divRed?.SelectSingleNode("div[contains(@class,'carac')]/strong[contains(text(),'INT')]")?.NextSibling?.NextSibling?.InnerText;
 | 
					            this.Intelligence = divRed?.SelectSingleNode("div[contains(@class,'carac')]/strong[contains(text(),'INT')]")?.NextSibling?.NextSibling?.InnerText;
 | 
				
			||||||
            monster.Wisdom = divRed?.SelectSingleNode("div[contains(@class,'carac')]/strong[contains(text(),'SAG')]")?.NextSibling?.NextSibling?.InnerText;
 | 
					            this.Wisdom = divRed?.SelectSingleNode("div[contains(@class,'carac')]/strong[contains(text(),'SAG')]")?.NextSibling?.NextSibling?.InnerText;
 | 
				
			||||||
            monster.Charisma = divRed?.SelectSingleNode("div[contains(@class,'carac')]/strong[contains(text(),'CHA')]")?.NextSibling?.NextSibling?.InnerText;
 | 
					            this.Charisma = divRed?.SelectSingleNode("div[contains(@class,'carac')]/strong[contains(text(),'CHA')]")?.NextSibling?.NextSibling?.InnerText;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            monster.SavingThrows = divRed?.SelectSingleNode("strong[contains(text(),'Jets de sauvegarde')]")?.NextSibling?.InnerText;
 | 
					            this.SavingThrows = divRed?.SelectSingleNode("strong[contains(text(),'Jets de sauvegarde')]")?.NextSibling?.InnerText;
 | 
				
			||||||
            monster.Skills = divRed?.SelectSingleNode("strong[contains(text(),'Compétences')]")?.NextSibling?.InnerText;
 | 
					            this.Skills = divRed?.SelectSingleNode("strong[contains(text(),'Compétences')]")?.NextSibling?.InnerText;
 | 
				
			||||||
            
 | 
					            
 | 
				
			||||||
            monster.DamageVulnerabilities = divRed?.SelectSingleNode("strong[contains(text(),'Vulnérabilités aux dégâts')]")?.NextSibling?.InnerText;
 | 
					            this.DamageVulnerabilities = divRed?.SelectSingleNode("strong[contains(text(),'Vulnérabilités aux dégâts')]")?.NextSibling?.InnerText;
 | 
				
			||||||
            monster.DamageResistances = divRed?.SelectSingleNode("strong[contains(text(),'Résistances aux dégâts')]")?.NextSibling?.InnerText;
 | 
					            this.DamageResistances = divRed?.SelectSingleNode("strong[contains(text(),'Résistances aux dégâts')]")?.NextSibling?.InnerText;
 | 
				
			||||||
            monster.DamageImmunities = divRed?.SelectSingleNode("strong[contains(text(),'Immunités aux dégâts')]")?.NextSibling?.InnerText;
 | 
					            this.DamageImmunities = divRed?.SelectSingleNode("strong[contains(text(),'Immunités aux dégâts')]")?.NextSibling?.InnerText;
 | 
				
			||||||
            monster.ConditionImmunities = divRed?.SelectSingleNode("strong[contains(text(),'Immunités aux conditions')]")?.NextSibling?.InnerText;
 | 
					            this.ConditionImmunities = divRed?.SelectSingleNode("strong[contains(text(),'Immunités aux conditions')]")?.NextSibling?.InnerText;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            monster.Senses = divRed?.SelectSingleNode("strong[contains(text(),'Sens')]")?.NextSibling?.InnerText;
 | 
					            this.Senses = divRed?.SelectSingleNode("strong[contains(text(),'Sens')]")?.NextSibling?.InnerText;
 | 
				
			||||||
            monster.Languages = divRed?.SelectSingleNode("strong[contains(text(),'Langues')]")?.NextSibling?.InnerText;
 | 
					            this.Languages = divRed?.SelectSingleNode("strong[contains(text(),'Langues')]")?.NextSibling?.InnerText;
 | 
				
			||||||
            monster.Challenge = divRed?.SelectSingleNode("strong[contains(text(),'Puissance')]")?.NextSibling?.InnerText;
 | 
					            this.Challenge = divRed?.SelectSingleNode("strong[contains(text(),'Puissance')]")?.NextSibling?.InnerText;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            List<HtmlNode> nodes = new List<HtmlNode>();
 | 
					            List<HtmlNode> nodes = new List<HtmlNode>();
 | 
				
			||||||
            List<HtmlNode> specialFeatures = null;
 | 
					            List<HtmlNode> specialFeatures = null;
 | 
				
			||||||
| 
						 | 
					@ -179,20 +187,26 @@ namespace AideDeJeuLib.Monsters
 | 
				
			||||||
                legendaryActions = nodes;
 | 
					                legendaryActions = nodes;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            monster.SpecialFeatures = specialFeatures;
 | 
					            this.SpecialFeatures = specialFeatures;
 | 
				
			||||||
            monster.Actions = actions;
 | 
					            this.Actions = actions;
 | 
				
			||||||
            monster.LegendaryActions = legendaryActions;
 | 
					            this.LegendaryActions = legendaryActions;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            var divDescription = divBloc?.SelectSingleNode("div[contains(@class,'description')]");
 | 
					            var divDescription = divBloc?.SelectSingleNode("div[contains(@class,'description')]");
 | 
				
			||||||
            monster.Description = divDescription?.InnerText;
 | 
					            this.Description = divDescription?.InnerText;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            var divSource = divBloc?.SelectSingleNode("div[contains(@class,'source')]");
 | 
					            var divSource = divBloc?.SelectSingleNode("div[contains(@class,'source')]");
 | 
				
			||||||
            monster.Source = divSource?.InnerText;
 | 
					            this.Source = divSource?.InnerText;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            var img = divBloc?.SelectSingleNode("div[contains(@class,'center')]/img[contains(@class,'picture')]");
 | 
					            var img = divBloc?.SelectSingleNode("div[contains(@class,'center')]/img[contains(@class,'picture')]");
 | 
				
			||||||
            monster.Picture = img?.GetAttributeValue("src", null);
 | 
					            this.Picture = img?.GetAttributeValue("src", null);
 | 
				
			||||||
            return monster;
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        public static Monster FromHtml(HtmlNode node)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            var monster = new Monster();
 | 
				
			||||||
 | 
					            monster.Html = node.OuterHtml;
 | 
				
			||||||
 | 
					            monster.ParseNode(node);
 | 
				
			||||||
 | 
					            return monster;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue