public ActionResponse <IEnumerable <TEntity> > Find <TValue>(string fieldName, TValue value, MatchingStrategy strategy, int limit = 100) { FilterDefinition <TEntity> filter; switch (strategy) { case MatchingStrategy.LessThan: filter = FilterBuilder.Lt(fieldName, value); break; case MatchingStrategy.GreaterThan: filter = FilterBuilder.Gt(fieldName, value); break; default: filter = FilterBuilder.Eq(fieldName, value); break; } var hits = Collection.Find(filter).Sort(SortBuilder.Descending(fieldName)).Limit(limit); return(new ActionResponse <IEnumerable <TEntity> > { Code = AppStatusCode.Ok, Data = hits.ToList() }); }
public List <TriggerKey> GetTriggersToAcquire(DateTimeOffset noLaterThan, DateTimeOffset noEarlierThan, int maxCount) { if (maxCount < 1) { maxCount = 1; } var noLaterThanDateTime = noLaterThan.UtcDateTime; var noEarlierThanDateTime = noEarlierThan.UtcDateTime; return(Collection.Find(trigger => trigger.Id.InstanceName == InstanceName && trigger.State == Models.TriggerState.Waiting && trigger.NextFireTime <= noLaterThanDateTime && (trigger.MisfireInstruction == -1 || (trigger.MisfireInstruction != -1 && trigger.NextFireTime >= noEarlierThanDateTime))) .Sort(SortBuilder.Combine( SortBuilder.Ascending(trigger => trigger.NextFireTime), SortBuilder.Descending(trigger => trigger.Priority) )) .Limit(maxCount) .Project(trigger => trigger.Id.GetTriggerKey()) .ToList()); }
public QueryBuilder <T> Sorting(Expression <Func <T, object> > sort, bool desc) { if (sort == null) { sort = x => x.Id; } if (Sort == null) { if (desc) { Sort = SortBuilder.Descending(sort); } else { Sort = SortBuilder.Ascending(sort); } } else { if (desc) { Sort = Sort.Descending(sort); } else { Sort = Sort.Ascending(sort); } } return(this); }
/// <summary> /// Get the names of all of the triggers in the given state that have /// misfired - according to the given timestamp. No more than count will /// be returned. /// </summary> /// <param name="nextFireTime"></param> /// <param name="maxResults"></param> /// <param name="results"></param> /// <returns></returns> public bool HasMisfiredTriggers(DateTime nextFireTime, int maxResults, out List <TriggerKey> results) { var cursor = Collection.Find( trigger => trigger.Id.InstanceName == InstanceName && trigger.MisfireInstruction != MisfireInstruction.IgnoreMisfirePolicy && trigger.NextFireTime < nextFireTime && trigger.State == Models.TriggerState.Waiting) .Project(trigger => trigger.Id.GetTriggerKey()) .Sort(SortBuilder.Combine( SortBuilder.Ascending(trigger => trigger.NextFireTime), SortBuilder.Descending(trigger => trigger.Priority) )).ToCursor(); results = new List <TriggerKey>(); var hasReachedLimit = false; while (cursor.MoveNext() && !hasReachedLimit) { foreach (var triggerKey in cursor.Current) { if (results.Count == maxResults) { hasReachedLimit = true; } else { results.Add(triggerKey); } } } return(hasReachedLimit); }
public Task <Show> FindLastShow() { var sort = SortBuilder.Descending(x => x.ExternalId); return(this.Collection .Find(x => true) .Limit(1) .Sort(sort) .FirstOrDefaultAsync()); }
public async Task <List <Publication> > ListPublications() { var filter = FilterBuilder.Exists(a => a.DeletedAt, false); var sort = SortBuilder.Descending(a => a.DateCreation); var projection = ProjectionBuilder.Slice(a => a.Comments, 0, 3); return(await Collection .Find(filter) .Sort(sort) .Project <Publication>(projection) .ToListAsync()); }
/// <summary> /// Lista todas as publicações /// </summary> /// <returns>Lista de publicações</returns> public async Task <List <Publication> > ListPublications(int page) { var filter = FilterBuilder.Exists(a => a.DeletedAt, false); var sort = SortBuilder.Descending(a => a.DateCreation); var projection = ProjectionBuilder.Slice(a => a.Comments, 0, 3); return(await Collection .Find(filter) .Sort(sort) .Skip((page - 1) * UtilBO.QUANTIDADE_PAGINAS) .Limit(UtilBO.QUANTIDADE_PAGINAS) .Project <Publication>(projection) .ToListAsync()); }
/// <summary> /// Busca publicações com base em uma palavra chave /// </summary> /// <param name="text">palavra chave</param> /// <param name="techiesId">Lista de tecnologias que a palavra chave se encaixa no nome</param> /// <param name="page">numero da pagina para paginação</param> /// <returns></returns> public async Task <List <Publication> > SearchPublications(string text, List <ObjectId> techiesId, int page) { var filter = FilterBuilder.Regex(a => a.Title, BsonRegularExpression.Create(new Regex(text, RegexOptions.IgnoreCase))) | FilterBuilder.Regex(a => a.Description, BsonRegularExpression.Create(new Regex(text, RegexOptions.IgnoreCase))) | FilterBuilder.AnyIn(a => a.Techies, techiesId) & FilterBuilder.Exists(a => a.DeletedAt, false); var sort = SortBuilder.Descending(a => a.DateCreation); var projection = ProjectionBuilder.Slice(a => a.Comments, 0, 3); return(await Collection .Find(filter) .Sort(sort) .Skip((page - 1) * UtilBO.QUANTIDADE_PAGINAS) .Limit(UtilBO.QUANTIDADE_PAGINAS) .Project <Publication>(projection) .ToListAsync()); }