Ejemplo n.º 1
0
        public override async Task <IEnumerable <Item> > GetFilteredItemsAsync(CancellationToken token = default)
        {
            var type       = Filters.SingleOrDefault(filter => filter.Key == FilterKeys.Type).SelectedKey ?? "";
            var rarity     = Filters.SingleOrDefault(filter => filter.Key == FilterKeys.Rarity).SelectedKey ?? "";
            var attunement = Filters.SingleOrDefault(filter => filter.Key == FilterKeys.Attunement).SelectedKey ?? "";

            try
            {
                await StoreViewModel.SemaphoreLibrary.WaitAsync();

                using (var context = await StoreViewModel.GetLibraryContextAsync())
                {
                    return(context.MagicItems.AsEnumerable().Where(magicitem =>
                                                                   MatchContains(magicitem.Type, type) &&
                                                                   MatchContains(magicitem.Rarity, rarity) &&
                                                                   MatchContains(magicitem.Attunement, attunement) &&
                                                                   MatchSearch(magicitem)
                                                                   ).OrderBy(eq => eq.Name).ToList());
                }
            }
            catch
            {
                return(new List <Item>());
            }
            finally
            {
                StoreViewModel.SemaphoreLibrary.Release();
            }
        }
Ejemplo n.º 2
0
        public override async Task <IEnumerable <Item> > GetFilteredItemsAsync(CancellationToken token = default)
        {
            var priceComparer = new PriceComparer();
            var type          = Filters.SingleOrDefault(filter => filter.Key == FilterKeys.Type).SelectedKey ?? "";
            var minPrice      = PriceConverter(Filters.SingleOrDefault(filter => filter.Key == FilterKeys.MinPrice).SelectedKey) ?? "0 pc";
            var maxPrice      = PriceConverter(Filters.SingleOrDefault(filter => filter.Key == FilterKeys.MaxPrice).SelectedKey) ?? "1 000 000 po";

            try
            {
                await StoreViewModel.SemaphoreLibrary.WaitAsync();

                using (var context = await StoreViewModel.GetLibraryContextAsync())
                {
                    return(context.Equipments.AsEnumerable().Where(equipment =>
                                                                   equipment.Type.ToLower().Contains(type.ToLower()) &&
                                                                   priceComparer.Compare(equipment.Price, minPrice) >= 0 &&
                                                                   priceComparer.Compare(equipment.Price, maxPrice) <= 0 &&
                                                                   (
                                                                       (Helpers.RemoveDiacritics(equipment.Name).ToLower().Contains(Helpers.RemoveDiacritics(SearchText ?? string.Empty).ToLower())) ||
                                                                       (Helpers.RemoveDiacritics(equipment.AltNameText ?? string.Empty).ToLower().Contains(Helpers.RemoveDiacritics(SearchText ?? string.Empty).ToLower()))
                                                                   )
                                                                   ).OrderBy(eq => eq.Name)
                           .ToList());
                }
            }
            catch
            {
                return(new List <Item>());
            }
            finally
            {
                StoreViewModel.SemaphoreLibrary.Release();
            }
        }
Ejemplo n.º 3
0
        public override async Task <IEnumerable <Item> > GetFilteredItemsAsync(CancellationToken token = default)
        {
            var challengeComparer = new ChallengeComparer();

            var type         = Filters.SingleOrDefault(filter => filter.Key == FilterKeys.Type).SelectedKey ?? "";
            var minChallenge = ChallengeConverter(Filters.SingleOrDefault(filter => filter.Key == FilterKeys.MinChallenge).SelectedKey) ?? "0 (0 PX)";
            var maxChallenge = ChallengeConverter(Filters.SingleOrDefault(filter => filter.Key == FilterKeys.MaxChallenge).SelectedKey) ?? "30 (155000 PX)";
            var size         = Filters.SingleOrDefault(filter => filter.Key == FilterKeys.Size).SelectedKey ?? "";
            var source       = Filters.SingleOrDefault(filter => filter.Key == FilterKeys.Source).SelectedKey ?? "";
            var terrain      = Filters.SingleOrDefault(filter => filter.Key == FilterKeys.Terrain).SelectedKey ?? "";

            token.ThrowIfCancellationRequested();

            try
            {
                await StoreViewModel.SemaphoreLibrary.WaitAsync();

                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.AsEnumerable().Where(monster =>
                                                                 (string.IsNullOrEmpty(this.Family) || (monster.Family != null && monster.Family.ToLower().Equals(this.Family.ToLower()))) &&
                                                                 (string.IsNullOrEmpty(size) || (monster.Size != null && monster.Size.ToLower().Equals(size.ToLower()))) &&
                                                                 (string.IsNullOrEmpty(type) || (monster.Type != null && monster.Type.ToLower().Contains(type.ToLower()))) &&
                                                                 (string.IsNullOrEmpty(terrain) || (monster.Terrain != null && monster.Terrain.ToLower().Contains(terrain.ToLower()))) &&
                                                                 (
                                                                     (string.IsNullOrEmpty(minChallenge) || monster.XP >= MonsterItem.ChallengeToXP(minChallenge)) &&
                                                                     (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
            {
                return(new List <Item>());
            }
            finally
            {
                StoreViewModel.SemaphoreLibrary.Release();
            }
        }
Ejemplo n.º 4
0
        public override async Task <IEnumerable <Item> > GetFilteredItemsAsync(CancellationToken token = default)
        {
            var levelComparer     = new LevelComparer();
            var classe            = Filters.SingleOrDefault(filter => filter.Key == FilterKeys.Class).SelectedKey ?? "";
            var levelMin          = LevelConverter(Filters.SingleOrDefault(filter => filter.Key == FilterKeys.MinLevel).SelectedKey) ?? "0";
            var levelMax          = LevelConverter(Filters.SingleOrDefault(filter => filter.Key == FilterKeys.MaxLevel).SelectedKey) ?? "9";
            var school            = Filters.SingleOrDefault(filter => filter.Key == FilterKeys.School).SelectedKey ?? "";
            var ritual            = Filters.SingleOrDefault(filter => filter.Key == FilterKeys.Ritual).SelectedKey ?? "";
            var castingTime       = Filters.SingleOrDefault(filter => filter.Key == FilterKeys.CastingTime).SelectedKey ?? "";
            var range             = Filters.SingleOrDefault(filter => filter.Key == FilterKeys.Range).SelectedKey ?? "";
            var verbalComponent   = Filters.SingleOrDefault(filter => filter.Key == FilterKeys.VerbalComponent).SelectedKey ?? "";
            var somaticComponent  = Filters.SingleOrDefault(filter => filter.Key == FilterKeys.SomaticComponent).SelectedKey ?? "";
            var materialComponent = Filters.SingleOrDefault(filter => filter.Key == FilterKeys.MaterialComponent).SelectedKey ?? "";
            var concentration     = Filters.SingleOrDefault(filter => filter.Key == FilterKeys.Concentration).SelectedKey ?? "";
            var duration          = Filters.SingleOrDefault(filter => filter.Key == FilterKeys.Duration).SelectedKey ?? "";
            var source            = Filters.SingleOrDefault(filter => filter.Key == FilterKeys.Source).SelectedKey ?? "";

            try
            {
                await StoreViewModel.SemaphoreLibrary.WaitAsync();

                using (var context = await StoreViewModel.GetLibraryContextAsync())
                {
                    return(context.Spells.AsEnumerable().Where(spell =>
                                                               spell.Family == this.Family &&
                                                               levelComparer.Compare(spell.Level, levelMin) >= 0 &&
                                                               levelComparer.Compare(spell.Level, levelMax) <= 0 &&
                                                               spell.Type.ToLower().Contains(school.ToLower()) &&
                                                               (spell.Source != null && spell.Source.Contains(source)) &&
                                                               (spell.Classes != null && spell.Classes.Contains(classe)) &&
                                                               MatchContainsOrNot(spell.Ritual, ritual) &&
                                                               (spell.CastingTime != null) && spell.CastingTime.Contains(castingTime) &&
                                                               (spell.Range != null) && spell.Range.Contains(range) &&
                                                               MatchContainsOrNot(spell.VerbalComponent, verbalComponent) &&
                                                               MatchContainsOrNot(spell.SomaticComponent, somaticComponent) &&
                                                               MatchContainsOrNot(spell.MaterialComponent, materialComponent) &&
                                                               MatchContainsOrNot(spell.Concentration, concentration) &&
                                                               (spell.Duration != null) && spell.Duration.Contains(duration) &&
                                                               (
                                                                   (Helpers.RemoveDiacritics(spell.Name).ToLower().Contains(Helpers.RemoveDiacritics(SearchText ?? string.Empty).ToLower())) ||
                                                                   (Helpers.RemoveDiacritics(spell.AltNameText ?? string.Empty).ToLower().Contains(Helpers.RemoveDiacritics(SearchText ?? string.Empty).ToLower()))
                                                               )).OrderBy(spell => Helpers.RemoveDiacritics(spell.Name)
                                                                          ).ToList());
                }
            }
            catch
            {
                return(new List <Item>());
            }
            finally
            {
                StoreViewModel.SemaphoreLibrary.Release();
            }
        }
Ejemplo n.º 5
0
        public async Task LoadDetailsAsync()
        {
            using (var context = await StoreViewModel.GetLibraryContextAsync())
            {
                HitPoints = await context.ClassHitPoints.Where(c => c.ParentLink == Class.Id).FirstOrDefaultAsync();

                Proficiencies = await context.ClassProficiencies.Where(c => c.ParentLink == Class.Id).FirstOrDefaultAsync();

                Equipment = await context.ClassEquipments.Where(c => c.ParentLink == Class.Id).FirstOrDefaultAsync();

                Evolution = await context.ClassEvolutions.Where(c => c.ParentLink == Class.Id).FirstOrDefaultAsync();

                Features = await context.ClassFeatures.Where(c => c.ParentLink == Class.Id).ToListAsync();
            }
        }
Ejemplo n.º 6
0
        public async Task LoadBookmarkCollectionsAsync()
        {
            if (true)
            {
                await InitBookmarkCollectionsAsync();

                using (var context = await StoreViewModel.GetLibraryContextAsync())
                {
                    var spells = context.Spells.ToList();
                    var spell  = spells.Take(1).FirstOrDefault();
                    Repository._BookmarkCollections["Grimoire"].Add(new Item()
                    {
                        Id = spell.Id, Name = spell.Name
                    });
                }
                await SaveBookmarkCollectionsAsync();
            }
        }
Ejemplo n.º 7
0
        public async Task <IEnumerable <SearchedItem> > DeepSearchAllItemsAsync(string searchText)
        {
            try
            {
                await StoreViewModel.SemaphoreLibrary.WaitAsync();

                using (var context = await StoreViewModel.GetLibraryContextAsync())
                {
                    var primary = await context.Items.
                                  Where(item => EF.Functions.Like(item.Name, $"%{searchText}%")).
                                  Select(item => new SearchedItem()
                    {
                        Item = item, Preview = item.ParentName != null ? $"> {item.ParentName}" : ""
                    }).
                                  ToListAsync();

                    var secondary = await context.Items.
                                    Where(item => EF.Functions.Like(item.Markdown, $"%{searchText}%")).
                                    Select(item => new SearchedItem()
                    {
                        Item    = item,
                        Preview = (item.ParentName != null ? $"> {item.ParentName} > " : "") + GetPreview(item.Markdown, searchText)
                    }).ToListAsync();

                    //var primary = await context.Items.
                    //    Where(item => item.Name.Contains(searchText)).
                    //    Select(item => new SearchedItem() { Item = item, Preview = item.Name }).
                    //    ToListAsync();
                    //var secondary = await context.Items.
                    //    Where(item => item.Markdown.Contains(searchText)).
                    //    Select(item => new SearchedItem()
                    //    {
                    //        Item = item,
                    //        Preview = GetPreview(item.Markdown, searchText)
                    //    }).ToListAsync();
                    primary.AddRange(secondary);
                    return(primary.ToList());
                }



                //List<SearchedItem> primaryItems = new List<SearchedItem>();
                //List<SearchedItem> secondaryItems = new List<SearchedItem>();
                //var cleanSearchText = Tools.Helpers.RemoveDiacritics(searchText ?? string.Empty).ToLower();
                //foreach (var item in Store._AllItems)
                //{
                //    var name = item.Value.Name;
                //    var cleanName = Tools.Helpers.RemoveDiacritics(name).ToLower();
                //    if (cleanName.Contains(cleanSearchText))
                //    {
                //        primaryItems.Add(new SearchedItem() { Item = item.Value, Preview = name });
                //    }
                //    else
                //    {
                //        var markdown = item.Value.Markdown;
                //        var cleanMarkdown = Tools.Helpers.RemoveDiacritics(markdown).ToLower();
                //        if (cleanMarkdown.Contains(cleanSearchText))
                //        {
                //            int position = cleanMarkdown.IndexOf(cleanSearchText);
                //            int startPosition = Math.Max(0, position - 30);
                //            int endPosition = Math.Min(markdown.Length, position + searchText.Length + 30);
                //            var preview = markdown.Substring(startPosition, endPosition - startPosition - 1);
                //            secondaryItems.Add(new SearchedItem() { Item = item.Value, Preview = preview });
                //        }
                //    }
                //}
                //primaryItems.AddRange(secondaryItems);
                //return primaryItems;
            }
            catch
            {
                return(new List <SearchedItem>());
            }
            finally
            {
                StoreViewModel.SemaphoreLibrary.Release();
            }
        }