Ejemplo n.º 1
0
        public ICollection <Stack> GetNew(string projectId, DateTime utcStart, DateTime utcEnd, PagingOptions paging, bool includeHidden = false, bool includeFixed = false, bool includeNotFound = true)
        {
            var options = new MultiOptions().WithProjectId(projectId).WithSort(SortBy.Descending(FieldNames.FirstOccurrence)).WithPaging(paging);

            options.Query = options.Query.And(Query.GTE(FieldNames.FirstOccurrence, utcStart), Query.LTE(FieldNames.FirstOccurrence, utcEnd));

            if (!includeFixed)
            {
                options.Query = options.Query.And(Query.NotExists(FieldNames.DateFixed));
            }

            if (!includeHidden)
            {
                options.Query = options.Query.And(Query.NE(FieldNames.IsHidden, true));
            }

            if (!includeNotFound)
            {
                options.Query = options.Query.And(Query.NotExists(FieldNames.SignatureInfo_Path));
            }

            return(Find <Stack>(options));
        }
Ejemplo n.º 2
0
        protected ICollection <TModel> Find <TModel>(MultiOptions <T> options) where TModel : class, new()
        {
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            ICollection <TModel> result = null;

            if (options.UseCache)
            {
                result = Cache.Get <ICollection <TModel> >(GetScopedCacheKey(options.CacheKey));
            }

            if (result != null)
            {
                return(result);
            }

            var query = options.ApplyFilter(Collection.AsQueryable());

            if (options.UsePaging)
            {
                query = query.Skip(options.GetSkip());
            }
            if (options.UseLimit)
            {
                query = query.Take(options.GetLimit() + 1);
            }
            //if (options.Fields.Count > 0)
            //    cursor.SetFields(Fields.Include(options.Fields.ToArray()));
            //if (options.SortBy != null)
            //    query = query.OrderBy(options.SortBy);

            if (Mapper.FindTypeMapFor <T, TModel>() == null)
            {
                Mapper.CreateMap <T, TModel>();
            }

            result = new Collection <TModel>();
            foreach (var doc in query.ToList())
            {
                result.Add(Mapper.Map <T, TModel>(doc));
            }

            if (options.UseLimit)
            {
                if (result.Count > options.GetLimit())
                {
                    options.HasMore = true;
                }
                result = result.Take(options.GetLimit()).ToList();
            }

            if (options.UseCache)
            {
                Cache.Set(GetScopedCacheKey(options.CacheKey), result, options.GetCacheExpirationDate());
            }

            return(result);
        }
Ejemplo n.º 3
0
        public ICollection <Organization> GetByCriteria(string criteria, PagingOptions paging, OrganizationSortBy sortBy, bool?paid = null, bool?suspended = null)
        {
            var options = new MultiOptions().WithPaging(paging);

            if (!String.IsNullOrWhiteSpace(criteria))
            {
                options.Query = options.Query.And(Query.Matches(FieldNames.Name, new BsonRegularExpression(String.Format("/{0}/i", criteria))));
            }

            if (paid.HasValue)
            {
                if (paid.Value)
                {
                    options.Query = options.Query.And(Query.NE(FieldNames.PlanId, new BsonString(BillingManager.FreePlan.Id)));
                }
                else
                {
                    options.Query = options.Query.And(Query.EQ(FieldNames.PlanId, new BsonString(BillingManager.FreePlan.Id)));
                }
            }

            if (suspended.HasValue)
            {
                if (suspended.Value)
                {
                    options.Query = options.Query.And(
                        Query.Or(
                            Query.And(
                                Query.NE(FieldNames.BillingStatus, new BsonInt32((int)BillingStatus.Active)),
                                Query.NE(FieldNames.BillingStatus, new BsonInt32((int)BillingStatus.Trialing)),
                                Query.NE(FieldNames.BillingStatus, new BsonInt32((int)BillingStatus.Canceled))
                                ),
                            Query.EQ(FieldNames.IsSuspended, new BsonBoolean(true))));
                }
                else
                {
                    options.Query = options.Query.And(
                        Query.Or(
                            Query.EQ(FieldNames.BillingStatus, new BsonInt32((int)BillingStatus.Active)),
                            Query.EQ(FieldNames.BillingStatus, new BsonInt32((int)BillingStatus.Trialing)),
                            Query.EQ(FieldNames.BillingStatus, new BsonInt32((int)BillingStatus.Canceled))
                            ),
                        Query.EQ(FieldNames.IsSuspended, new BsonBoolean(false)));
                }
            }

            switch (sortBy)
            {
            case OrganizationSortBy.Newest:
                options.SortBy = SortBy.Descending(FieldNames.Id);
                break;

            case OrganizationSortBy.Subscribed:
                options.SortBy = SortBy.Descending(FieldNames.SubscribeDate);
                break;

            case OrganizationSortBy.MostActive:
                options.SortBy = SortBy.Descending(FieldNames.TotalEventCount);
                break;

            default:
                options.SortBy = SortBy.Ascending(FieldNames.Name);
                break;
            }

            return(Find <Organization>(options));
        }