forked from ddrilling/AsbCloudServer
31 lines
869 B
C#
31 lines
869 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;
|
|
}
|
|
}
|
|
}
|