forked from ddrilling/AsbCloudServer
31 lines
859 B
C#
31 lines
859 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 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<string> GetRequests()
|
|
{
|
|
DeleteOldRequests();
|
|
return requests.Keys;
|
|
}
|
|
}
|
|
}
|