public IEnumerable <DisplayItem> GetTopCountries(TweetStorageSelectBy countType = TweetStorageSelectBy.All, int max = 10) { lock (_items) { var res = (from item in _items where SelectPredicate(countType)(item) && item.Country != TweetStorageItem.UnknownCountry group item by item.Country into grp orderby grp.Count() descending select new DisplayItem { Name = grp.Key, Value = grp.Count() }).Take(max); return(res.ToList()); } }
/// <summary> /// Initializes a new instance of the <see cref="SelectPredicateAttribute"/> class. /// </summary> /// <param name="selectPredicate">The select predicate.</param> /// <param name="parameter">The parameter.</param> public SelectPredicateAttribute(SelectPredicate selectPredicate, int parameter) { if (selectPredicate == SelectPredicate.Distinct) { throw new ArgumentException("Invalid SelectPredicateAttribute initialization; Optional parameter only to be specified with a TOP or TOP_PERCENT select predicate!"); } this.Predicate = selectPredicate; this.PredicateParameter = parameter; }
public override string ToString() { var oDataQueryParts = new List <string>(10) { FormatPredicate.ToString() }; if (CountPredicate != null) { oDataQueryParts.Add(CountPredicate.ToString()); } if (ExpandPredicate != null) { oDataQueryParts.Add(ExpandPredicate.ToString()); } if (FilterPredicate != null) { oDataQueryParts.Add(FilterPredicate.ToString()); } if (OrderByPredicate != null) { oDataQueryParts.Add(OrderByPredicate.ToString()); } if (SelectPredicate != null) { oDataQueryParts.Add(SelectPredicate.ToString()); } if (SkipPredicate != null) { oDataQueryParts.Add(SkipPredicate.ToString()); } if (SkipTokenPredicate != null) { oDataQueryParts.Add(SkipTokenPredicate.ToString()); } if (TopPredicate != null) { oDataQueryParts.Add(TopPredicate.ToString()); } if (InlineCountPredicate != null) { oDataQueryParts.Add(InlineCountPredicate.ToString()); } return($"?{String.Join("&", oDataQueryParts)}"); }
public static IEnumerable <TOut?> SelectWhere <TIn, TOut>(this IEnumerable <TIn?> source, SelectPredicate <TIn?, TOut?> selectWhere) { foreach (TIn?value in source) { if (selectWhere(value, out TOut? result)) { yield return(result); } } }
/// <summary> /// Initializes a new instance of the <see cref="SelectPredicateAttribute"/> class. /// </summary> /// <param name="selectPredicate">The select predicate.</param> public SelectPredicateAttribute(SelectPredicate selectPredicate) { this.Predicate = selectPredicate; }