public UsageStatistics LimitEntries(int maxEntries = MAX_STORED_ENTRIES) { return(new UsageStatistics { Scope = Scope, TopUsed = TopUsed.OrderByDescending(e => e.CountUsed).Take(maxEntries).ToList(), LastUsed = LastUsed.OrderByDescending(e => e.TimeUsed).Take(maxEntries).ToList() }); }
public void SetUsed(string usedItem) { // Part 1: stats by usage counter var nameCounts = TopUsed?.ToList() ?? new List <NameCount>(); var existingEntry = nameCounts.FirstOrDefault(e => e.Name == usedItem); if (existingEntry != null) { existingEntry.CountUsed++; } else { // Limit list of stored items if (nameCounts.Count >= MAX_STORED_ENTRIES) { nameCounts.Remove(nameCounts.OrderByDescending(e => e.CountUsed).Last()); } nameCounts.Add(new NameCount { CountUsed = 1, Name = usedItem }); } TopUsed = nameCounts; // Part 2: stats by usage counter var nameTime = LastUsed?.ToList() ?? new List <NameTime>(); var existingTimeEntry = nameTime.FirstOrDefault(e => e.Name == usedItem); if (existingEntry != null) { existingTimeEntry.TimeUsed = DateTime.Now; } else { nameTime.Insert(0, new NameTime { TimeUsed = DateTime.Now, Name = usedItem }); } LastUsed = nameTime; }