Exemplo n.º 1
0
        /// <summary>
        /// Gets a descending range of events from the database.
        /// </summary>
        /// <returns>The list of rows within the range</returns>
        /// <param name="range">The amount of rows we want</param>
        public List <EventRow> GetEvents(int range)
        {
            try
            {
                _dbLock.EnterReadLock();
                // Get event collection
                var events = _db.GetCollection <Event>(COLLECTION_NAME);

                var result = events.FindAll()
                             .OrderBy(x => x.CreatedAt)
                             .Take(range)
                             .Select(x => new EventRow(x.Id, TrackerPayload.From(x.Payload)))
                             .ToList();

                Log.Verbose($"Got events: {string.Join(",", result.Select(x => x.GetRowId()))}");

                return(result);
            }
            catch (Exception e)
            {
                Log.Error($"EventStore: Get Events failed");
                Log.Error(e.ToString());
                return(new List <EventRow>());
            }
            finally
            {
                _dbLock.ExitReadLock();
            }
        }