using AsbCloudApp.Services; using System; using System.Collections.Generic; using System.Linq; namespace AsbCloudInfrastructure.Services { public class TelemetryTracker : ITelemetryTracker { private Dictionary requests = new Dictionary(); private readonly TimeSpan timeout = TimeSpan.FromDays(7); public void SaveRequestDate(string uid) { requests[uid] = DateTime.Now; DeleteOldRequestDates(); } public DateTime GetLastTelemetryDateByUid(string uid) => requests.GetValueOrDefault(uid, DateTime.MinValue); public IEnumerable GetTransmittingTelemetryUids() { DeleteOldRequestDates(); return requests.Keys; } private void DeleteOldRequestDates() { requests = requests.Where(dValue => (DateTime.Now - dValue.Value) < timeout) .ToDictionary(dValue => dValue.Key, dValue => dValue.Value); } } }