mirror of
https://github.com/Nioux/AideDeJeu.git
synced 2025-12-17 07:40:41 +00:00
Tests EF, index
This commit is contained in:
parent
9d9c52e34d
commit
a13aff170e
10 changed files with 6799 additions and 5816 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using SQLite;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Runtime.Serialization;
|
using System.Runtime.Serialization;
|
||||||
|
|
@ -9,6 +10,8 @@ namespace AideDeJeuLib
|
||||||
|
|
||||||
public class FilteredItems : Items
|
public class FilteredItems : Items
|
||||||
{
|
{
|
||||||
|
[DataMember]
|
||||||
|
[Indexed]
|
||||||
public string Family { get; set; }
|
public string Family { get; set; }
|
||||||
|
|
||||||
public List<KeyValuePair<string, string>> Split(string collapsed)
|
public List<KeyValuePair<string, string>> Split(string collapsed)
|
||||||
|
|
|
||||||
|
|
@ -133,6 +133,17 @@ namespace AideDeJeuLib
|
||||||
[Indexed]
|
[Indexed]
|
||||||
public virtual string Name { get; set; }
|
public virtual string Name { get; set; }
|
||||||
|
|
||||||
|
[DataMember]
|
||||||
|
[Indexed]
|
||||||
|
public virtual string NormalizedName
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return Helpers.RemoveDiacritics(Name);
|
||||||
|
}
|
||||||
|
private set { }
|
||||||
|
}
|
||||||
|
|
||||||
[DataMember(Name = "Item_ParentName", Order = 4)]
|
[DataMember(Name = "Item_ParentName", Order = 4)]
|
||||||
[Indexed]
|
[Indexed]
|
||||||
public virtual string ParentName { get; set; }
|
public virtual string ParentName { get; set; }
|
||||||
|
|
@ -168,8 +179,9 @@ namespace AideDeJeuLib
|
||||||
[Indexed]
|
[Indexed]
|
||||||
public virtual string AltName { get; set; }
|
public virtual string AltName { get; set; }
|
||||||
|
|
||||||
|
[DataMember]
|
||||||
|
//[DatabaseGenerated(DatabaseGeneratedOption.Computed)]
|
||||||
[YamlIgnore]
|
[YamlIgnore]
|
||||||
[IgnoreDataMember]
|
|
||||||
public virtual string AltNameText
|
public virtual string AltNameText
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
|
@ -191,7 +203,20 @@ namespace AideDeJeuLib
|
||||||
return AltName ?? string.Empty;
|
return AltName ?? string.Empty;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private set { }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[DataMember]
|
||||||
|
[Indexed]
|
||||||
|
public virtual string NormalizedAltName
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return Helpers.RemoveDiacritics(AltNameText) ?? string.Empty;
|
||||||
|
}
|
||||||
|
private set { }
|
||||||
|
}
|
||||||
|
|
||||||
[DataMember(Name = "Item_Source", Order = 7)]
|
[DataMember(Name = "Item_Source", Order = 7)]
|
||||||
[Indexed]
|
[Indexed]
|
||||||
public virtual string Source { get; set; }
|
public virtual string Source { get; set; }
|
||||||
|
|
|
||||||
|
|
@ -44,5 +44,23 @@ namespace AideDeJeuLib
|
||||||
public string Languages { get; set; }
|
public string Languages { get; set; }
|
||||||
[Indexed]
|
[Indexed]
|
||||||
public string Challenge { get; set; }
|
public string Challenge { get; set; }
|
||||||
|
[Indexed]
|
||||||
|
public int XP
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return ChallengeToXP(Challenge);
|
||||||
|
}
|
||||||
|
private set { }
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int ChallengeToXP(string challenge)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(challenge)) return 0;
|
||||||
|
var regex = new Regex(@"\((?<xp>\d?\d?\d?\s?\d?\d?\d??) (PX|XP)\)");
|
||||||
|
int xp = 0;
|
||||||
|
int.TryParse(regex.Match(challenge).Groups["xp"].Value.Replace(" ", ""), out xp);
|
||||||
|
return xp;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
using AideDeJeu.Tools;
|
using AideDeJeu.Tools;
|
||||||
using AideDeJeuLib;
|
using AideDeJeuLib;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Linq.Expressions;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
|
|
@ -53,6 +55,8 @@ namespace AideDeJeu.ViewModels.Library
|
||||||
return string.IsNullOrEmpty(filterValue) || (itemValue != null && itemValue.ToLower().Equals(filterValue.ToLower()));
|
return string.IsNullOrEmpty(filterValue) || (itemValue != null && itemValue.ToLower().Equals(filterValue.ToLower()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Expression<Func<Item, bool>> funcPred = p => p.JobTitle == "Design Engineer";
|
||||||
|
|
||||||
public bool MatchRange(string itemValue, string filterMinValue, string filterMaxValue, IComparer<string> comparer)
|
public bool MatchRange(string itemValue, string filterMinValue, string filterMaxValue, IComparer<string> comparer)
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
|
|
@ -425,14 +429,35 @@ namespace AideDeJeu.ViewModels.Library
|
||||||
await StoreViewModel.SemaphoreLibrary.WaitAsync();
|
await StoreViewModel.SemaphoreLibrary.WaitAsync();
|
||||||
using (var context = await StoreViewModel.GetLibraryContextAsync())
|
using (var context = await StoreViewModel.GetLibraryContextAsync())
|
||||||
{
|
{
|
||||||
|
//Expression<Func<MonsterItem, bool>> funcSize = m => true;
|
||||||
|
//if (!string.IsNullOrEmpty(size))
|
||||||
|
//{
|
||||||
|
// funcSize = m => m.Size == size;
|
||||||
|
//}
|
||||||
|
//Expression<Func<MonsterItem, bool>> funcFamily = m => Expression.Equal( m.Family, Expression.Constant(this.Family));
|
||||||
|
//var funcAll = Expression.AndAlso(funcSize.Body, funcFamily.Body);
|
||||||
|
//var lambdaAll = Expression.Lambda<Func<MonsterItem, bool>>(funcAll, funcSize.Parameters[0]);
|
||||||
|
//return context.Monsters.Where(lambdaAll).ToList();
|
||||||
return context.Monsters.Where(monster =>
|
return context.Monsters.Where(monster =>
|
||||||
MatchEquals(monster.Family, this.Family) &&
|
(string.IsNullOrEmpty(this.Family) || (monster.Family != null && monster.Family.ToLower().Equals(this.Family.ToLower()))) &&
|
||||||
MatchContains(monster.Type, type) &&
|
(string.IsNullOrEmpty(size) || (monster.Size != null && monster.Size.ToLower().Equals(size.ToLower()))) &&
|
||||||
MatchEquals(monster.Size, size) &&
|
(string.IsNullOrEmpty(type) || (monster.Type != null && monster.Type.ToLower().Contains(type.ToLower()))) &&
|
||||||
MatchContains(monster.Terrain, terrain) &&
|
(string.IsNullOrEmpty(terrain) || (monster.Terrain != null && monster.Terrain.ToLower().Contains(terrain.ToLower()))) &&
|
||||||
MatchRange(monster.Challenge, minChallenge, maxChallenge, challengeComparer) &&
|
(
|
||||||
MatchSearch(monster)
|
(string.IsNullOrEmpty(minChallenge) || monster.XP >= MonsterItem.ChallengeToXP(minChallenge)) &&
|
||||||
).OrderBy(monster => Helpers.RemoveDiacritics(monster.Name)).ToList();
|
(string.IsNullOrEmpty(maxChallenge) || monster.XP <= MonsterItem.ChallengeToXP(maxChallenge))
|
||||||
|
) &&
|
||||||
|
(
|
||||||
|
monster.NormalizedName.ToLower().Contains(Helpers.RemoveDiacritics(SearchText ?? string.Empty).ToLower()) ||
|
||||||
|
monster.NormalizedAltName.ToLower().Contains(Helpers.RemoveDiacritics(SearchText ?? string.Empty).ToLower())
|
||||||
|
)
|
||||||
|
//MatchEquals(monster.Family, this.Family) &&
|
||||||
|
//MatchContains(monster.Type, type) &&
|
||||||
|
//MatchEquals(monster.Size, size) &&
|
||||||
|
//MatchContains(monster.Terrain, terrain) &&
|
||||||
|
//MatchRange(monster.Challenge, minChallenge, maxChallenge, challengeComparer) &&
|
||||||
|
//MatchSearch(monster)
|
||||||
|
).OrderBy(monster => monster.NormalizedName).ToList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
|
|
|
||||||
|
|
@ -689,7 +689,9 @@ namespace AideDeJeu.ViewModels
|
||||||
|
|
||||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||||
{
|
{
|
||||||
optionsBuilder.UseSqlite($"Data Source='{DbPath}'");
|
optionsBuilder
|
||||||
|
.UseSqlite($"Data Source='{DbPath}'");
|
||||||
|
//.ConfigureWarnings(warnings => warnings.Throw(Microsoft.EntityFrameworkCore.Diagnostics.RelationalEventId.QueryClientEvaluationWarning));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
|
|
@ -707,7 +709,7 @@ namespace AideDeJeu.ViewModels
|
||||||
|
|
||||||
modelBuilder.Entity<AlignmentItem>();
|
modelBuilder.Entity<AlignmentItem>();
|
||||||
modelBuilder.Entity<GenericItem>();
|
modelBuilder.Entity<GenericItem>();
|
||||||
modelBuilder.Entity<MonsterItem>();
|
modelBuilder.Entity<MonsterItem>().HasIndex(i => new { i.Id, i.Family, i.Type, i.Size, i.Terrain, i.Challenge, i.XP, i.Name, i.AltNameText, i.NormalizedName, i.NormalizedAltName });
|
||||||
modelBuilder.Entity<MonsterItems>();
|
modelBuilder.Entity<MonsterItems>();
|
||||||
modelBuilder.Entity<SpellItem>();
|
modelBuilder.Entity<SpellItem>();
|
||||||
modelBuilder.Entity<SpellItems>();
|
modelBuilder.Entity<SpellItems>();
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
BIN
Data/library.db
BIN
Data/library.db
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue