Exemplo n.º 1
0
        // Public members

        public override async Task ApplyAsync(ISearchContext context, ISearchResult result)
        {
            switch (ParseFormatBy(Value))
            {
            case FormatBy.CommonName:
                await result.FormatByAsync(new CommonNameTaxonFormatter());

                break;

            case FormatBy.FullName:
                await result.FormatByAsync(new BinomialNameTaxonFormatter()
                {
                    NameFormat = BinomialNameFormat.Full
                });

                break;

            case FormatBy.SpeciesOnly:
                await result.FormatByAsync(new BinomialNameTaxonFormatter()
                {
                    NameFormat = BinomialNameFormat.Species
                });

                break;

            case FormatBy.Gallery:
                result.DisplayFormat = SearchResultDisplayFormat.Gallery;
                break;

            case FormatBy.Leaderboard:

                result.DisplayFormat = SearchResultDisplayFormat.Leaderboard;

                // If the ordering has not already been modified, order the groups by the number of items in each.

                if (result.HasDefaultOrdering)
                {
                    await result.OrderByAsync(Comparer <ISearchResultGroup> .Create((lhs, rhs) => lhs.Count().CompareTo(rhs.Count())));
                }

                break;

            default:
            case FormatBy.ShortName:
                await result.FormatByAsync(new BinomialNameTaxonFormatter());

                break;
            }
        }
Exemplo n.º 2
0
        // Public members

        public override async Task ApplyAsync(ISearchContext context, ISearchResult result)
        {
            switch (ParseOrderBy(Value))
            {
            case OrderBy.Newest:
                await result.OrderByAsync(Comparer <ISpecies> .Create((lhs, rhs) => rhs.CreationDate.CompareTo(lhs.CreationDate)));

                break;

            case OrderBy.Oldest:
                await result.OrderByAsync(Comparer <ISpecies> .Create((lhs, rhs) => lhs.CreationDate.CompareTo(rhs.CreationDate)));

                break;

            case OrderBy.Smallest:
                await result.OrderByAsync(Comparer <ISpecies> .Create((lhs, rhs) => SpeciesSizeMatch.Match(lhs.Description).MaxSize.ToMeters().CompareTo(SpeciesSizeMatch.Match(rhs.Description).MaxSize.ToMeters())));

                break;

            case OrderBy.Largest:
                await result.OrderByAsync(Comparer <ISpecies> .Create((lhs, rhs) => SpeciesSizeMatch.Match(rhs.Description).MaxSize.ToMeters().CompareTo(SpeciesSizeMatch.Match(lhs.Description).MaxSize.ToMeters())));

                break;

            case OrderBy.Count:
                await result.OrderByAsync(Comparer <ISearchResultGroup> .Create((lhs, rhs) => rhs.Count().CompareTo(lhs.Count())));

                break;

            case OrderBy.Suffix:
                await result.OrderByAsync(Comparer <ISpecies> .Create((lhs, rhs) => {
                    string lhsStr = new string(result.TaxonFormatter.GetString(lhs, false).Reverse().ToArray());
                    string rhsStr = new string(result.TaxonFormatter.GetString(rhs, false).Reverse().ToArray());

                    return(lhsStr.CompareTo(rhsStr));
                }));

                break;

            default:
            case OrderBy.Default:
                await result.OrderByAsync(Comparer <ISpecies> .Create((lhs, rhs) => result.TaxonFormatter.GetString(lhs, false).CompareTo(result.TaxonFormatter.GetString(rhs, false))));

                break;
            }
        }