DD.WellWorkover.Cloud/AsbCloudInfrastructure/Services/TelemetryTracker.cs

31 lines
894 B
C#

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