Example #1
0
 public virtual IEnumerable <TEntity> FindAll(QueryLimits queryLimits)
 {
     using (var entityContext = ContextCreator())
     {
         return(entityContext.Set <TEntity>().OrderBy(queryLimits.OrderBy + " " + queryLimits.Orientation)
                .Skip(queryLimits.Limit * (queryLimits.Page - 1))
                .Take(queryLimits.Limit)
                .ToList());
     }
 }
Example #2
0
 public virtual IEnumerable <TEntity> FindAll(QueryLimits queryLimits, IEnumerable <string> clauses)
 {
     using (var entityContext = ContextCreator())
     {
         IQueryable <TEntity> temporaryQuery = entityContext.Set <TEntity>();
         foreach (var clause in clauses)
         {
             temporaryQuery = temporaryQuery.Where(clause);
         }
         return(temporaryQuery.OrderBy(queryLimits.OrderBy + " " + queryLimits.Orientation)
                .Skip(queryLimits.Limit * (queryLimits.Page - 1))
                .Take(queryLimits.Limit)
                .ToList());
     }
 }
Example #3
0
        public virtual IEnumerable <TEntity> FindAllIncludingNestedProps(QueryLimits queryLimits,
                                                                         params string[] includeProperties)
        {
            using (var entityContext = ContextCreator())
            {
                IQueryable <TEntity> query;

                query = entityContext.Set <TEntity>().OrderBy(queryLimits.OrderBy + " " + queryLimits.Orientation)
                        .Skip(queryLimits.Limit * (queryLimits.Page - 1))
                        .Take(queryLimits.Limit);

                query = includeProperties.Aggregate(query,
                                                    (current, property) => current.Include(property));
                return(query.ToList());
            }
        }
Example #4
0
        public virtual IEnumerable <TEntity> FindAllIncluding(QueryLimits queryLimits,
                                                              IEnumerable <string> clauses,
                                                              params Expression <Func <TEntity, object> >[] includeProperties)
        {
            using (var entityContext = ContextCreator())
            {
                IQueryable <TEntity> temporaryQuery = entityContext.Set <TEntity>();
                foreach (var clause in clauses)
                {
                    temporaryQuery = temporaryQuery.Where(clause);
                }

                var query = temporaryQuery.OrderBy(queryLimits.OrderBy + " " + queryLimits.Orientation)
                            .Skip(queryLimits.Limit * (queryLimits.Page - 1))
                            .Take(queryLimits.Limit);

                query = includeProperties.Aggregate(query,
                                                    (current, property) => current.Include(property));
                return(query.ToList());
            }
        }
        public async Task CreateRateLimitedUser(string username, Limits limits)
        {
            var jsonLimits = new JObject();

            if (limits.KeyValueLimits != null)
            {
                KeyValueLimits kv = limits.KeyValueLimits;
                jsonLimits.Add("kv", new JObject
                {
                    { "num_connections", kv.NumConnections },
                    { "num_ops_per_min", kv.NumOpsPerMin },
                    { "ingress_mib_per_min", kv.IngressMibPerMin },
                    { "egress_mib_per_min", kv.EgressMibPerMin }
                });
            }

            if (limits.QueryLimits != null)
            {
                QueryLimits query = limits.QueryLimits;
                jsonLimits.Add("query", new JObject
                {
                    { "num_queries_per_min", query.NumQueriesPerMin },
                    { "num_concurrent_requests", query.NumConcurrentRequests },
                    { "ingress_mib_per_min", query.IngressMibPerMin },
                    { "egress_mib_per_min", query.EgressMibPerMin }
                });
            }

            if (limits.SearchLimits != null)
            {
                SearchLimits search = limits.SearchLimits;
                jsonLimits.Add("fts", new JObject
                {
                    { "num_queries_per_min", search.NumQueriesPerMin },
                    { "num_concurrent_requests", search.NumConcurrentRequests },
                    { "ingress_mib_per_min", search.IngressMibPerMin },
                    { "egress_mib_per_min", search.EgressMibPerMin }
                });
            }

            if (limits.ClusterManagerLimits != null)
            {
                ClusterManagerLimits cm = limits.ClusterManagerLimits;
                jsonLimits.Add("clusterManager", new JObject
                {
                    { "num_concurrent_requests", cm.NumConcurrentRequests },
                    { "ingress_mib_per_min", cm.IngressMibPerMin },
                    { "egress_mib_per_min", cm.EgressMibPerMin }
                });
            }

            var content = new FormUrlEncodedContent(new[]
            {
                new KeyValuePair <string, string>("password", RlPassword),
                new KeyValuePair <string, string>("roles", "admin"),
                new KeyValuePair <string, string>("limits", jsonLimits.ToString())
            });

            var response = await _httpClient.PutAsync($"/settings/rbac/users/local/{username}", content);

            Assert.True(response.IsSuccessStatusCode);
        }