Exemplo n.º 1
0
 private void ConsumerThread()
 {
     foreach (var query in queries_.GetConsumingEnumerable(cancellation_.Token))
     {
         using (var file = query.Item1)
         {
             var filter = query.Item2;
             statsCache_.GetStats(file, filter);
         }
     }
 }
Exemplo n.º 2
0
        public LogAccumulator Consume(ILogFile logFile)
        {
            if (IsComplete)
            {
                return(this);
            }

            var filter = query_.CreateFilter();

            var stats             = statsCache_.GetStats(logFile, filter);
            var matchesTimeWindow = query_.MinTimestamp <= stats.LatestTimestamp &&
                                    stats.EarliestTimestamp <= query_.MaxTimestamp;

            if (!matchesTimeWindow)
            {
                return(this);
            }

            var matchingEvents = stats.GroupStats
                                 .Where(kvp => groupFilter_.Apply(kvp.Key))
                                 .Sum(kvp => kvp.Value);

            if (matchingEvents > skipRemaining_)
            {
                var fileEvents         = logFile.GetEventsReverse();
                var filteredFileEvents = filter != null
                    ? fileEvents.Where(filter)
                    : fileEvents;

                var selectedFileEvents = filteredFileEvents
                                         .Skip(skipRemaining_)
                                         .Take(query_.Quantity - events_.Count)
                                         .Select(x => new EventModel(x));
                events_.AddRange(selectedFileEvents);

                skipRemaining_ = 0;
            }
            else
            {
                skipRemaining_ -= matchingEvents;
            }

            return(this);
        }