Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        /// <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);
        }
Ejemplo n.º 3
0
        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());
        }
Ejemplo n.º 4
0
        public Task <List <Show> > FindShows(int offset, int limit)
        {
            var sort = SortBuilder.Ascending(x => x.ExternalId);

            return(this.Collection
                   .Find(x => true)
                   .Limit(limit)
                   .Skip(offset * limit)
                   .Sort(sort)
                   .ToListAsync());
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Sugere uma tecnologia com base em uma palavra chave
        /// </summary>
        /// <param name="text">palavra chave</param>
        /// <returns></returns>
        public async Task <List <Techie> > SugestTechie(string text)
        {
            var filter = FilterBuilder.Regex(a => a.Name, BsonRegularExpression.Create(new Regex(text, RegexOptions.IgnoreCase)))
                         & FilterBuilder.Exists(a => a.DeletedAt, false);
            var sort = SortBuilder.Ascending(a => a.Name);

            return(await Collection
                   .Find(filter)
                   .Sort(sort)
                   .Limit(5)
                   .ToListAsync());
        }