using System; using System.Collections.Generic; using System.Linq; using AsbCloudApp.Services; namespace AsbCloudInfrastructure.Services { public class TelemetryTracker : ITelemetryTracker { private IDictionary requests = new Dictionary(); private readonly TimeSpan timeout = TimeSpan.FromMinutes(6); private void DeleteOldRequests() { requests = requests.Where(dValue => (DateTime.Now - dValue.Value) < timeout).ToDictionary(dValue => dValue.Key, dValue => dValue.Value); } public void SaveRequest(string id) { requests[id] = DateTime.Now; DeleteOldRequests(); } public IEnumerable GetRequests() { DeleteOldRequests(); return requests.Keys; } } }