Exemplo n.º 1
0
 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());
     }
 }
Exemplo n.º 2
0
 /// <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;
 }
Exemplo n.º 3
0
        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)}");
        }
Exemplo n.º 4
0
 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);
         }
     }
 }
Exemplo n.º 5
0
 /// <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;
 }