Exemplo n.º 1
0
 public override async Task <IEnumerable <Item> > FilterItems(IEnumerable <Item> items, CancellationToken token = default)
 {
     return(await Task.Run(() =>
     {
         var levelComparer = new LevelComparer();
         var classe = Filters.SingleOrDefault(filter => filter.Key == FilterKeys.Class).SelectedKey ?? "";
         var niveauMin = Filters.SingleOrDefault(filter => filter.Key == FilterKeys.MinLevel).SelectedKey ?? "0";
         var niveauMax = Filters.SingleOrDefault(filter => filter.Key == FilterKeys.MaxLevel).SelectedKey ?? "9";
         var ecole = Filters.SingleOrDefault(filter => filter.Key == FilterKeys.School).SelectedKey ?? "";
         var ritual = Filters.SingleOrDefault(filter => filter.Key == FilterKeys.Ritual).SelectedKey ?? "";
         var source = Filters.SingleOrDefault(filter => filter.Key == FilterKeys.Source).SelectedKey ?? "";
         //token.ThrowIfCancellationRequested();
         return items.Where(item =>
         {
             var spell = item as Spell;
             return
             levelComparer.Compare(spell.Level, niveauMin) >= 0 &&
             levelComparer.Compare(spell.Level, niveauMax) <= 0 &&
             spell.Type.ToLower().Contains(ecole.ToLower()) &&
             (spell.Source != null && spell.Source.Contains(source)) &&
             (spell.Classes != null && spell.Classes.Contains(classe)) &&
             (string.IsNullOrEmpty(ritual) || (spell.Ritual != null && spell.Ritual.Contains(ritual))) &&
             (
                 (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 => spell.Name)
         .AsEnumerable();
     }, token));
 }
Exemplo n.º 2
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();
            }
        }