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

28 lines
815 B
C#
Raw Normal View History

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>();
public void SaveRequest(string id)
{
_requests[id] = DateTime.Now;
DeleteOldRequests();
}
public void DeleteOldRequests(int minutes = 6)
{
_requests = _requests.Where(dValue => (DateTime.Now - dValue.Value).Minutes < minutes).ToDictionary(dValue => dValue.Key, dValue => dValue.Value);
}
public IEnumerable<string> GetRequests()
{
DeleteOldRequests();
return _requests.Keys;
}
}
}