2021-07-21 15:29:19 +05:00
|
|
|
|
using AsbCloudApp.Services;
|
|
|
|
|
using System;
|
2021-05-12 16:03:14 +05:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
namespace AsbCloudInfrastructure.Services
|
|
|
|
|
{
|
|
|
|
|
public class TelemetryTracker : ITelemetryTracker
|
|
|
|
|
{
|
2021-05-13 10:26:24 +05:00
|
|
|
|
private IDictionary<string, DateTime> requests = new Dictionary<string, DateTime>();
|
|
|
|
|
private readonly TimeSpan timeout = TimeSpan.FromMinutes(6);
|
2021-05-12 17:25:52 +05:00
|
|
|
|
|
2021-05-14 09:58:02 +05:00
|
|
|
|
private void DeleteOldRequestDates()
|
2021-05-12 16:03:14 +05:00
|
|
|
|
{
|
2021-05-13 10:26:24 +05:00
|
|
|
|
requests = requests.Where(dValue => (DateTime.Now - dValue.Value) < timeout).ToDictionary(dValue => dValue.Key, dValue => dValue.Value);
|
2021-05-12 16:03:14 +05:00
|
|
|
|
}
|
2021-05-12 17:25:52 +05:00
|
|
|
|
|
2021-05-14 09:58:02 +05:00
|
|
|
|
public void SaveRequestDate(string uid)
|
2021-05-12 16:03:14 +05:00
|
|
|
|
{
|
2021-05-14 09:58:02 +05:00
|
|
|
|
requests[uid] = DateTime.Now;
|
|
|
|
|
DeleteOldRequestDates();
|
2021-05-12 16:03:14 +05:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-14 10:58:23 +05:00
|
|
|
|
public IEnumerable<string> GetTransmittingTelemetryUids()
|
2021-05-12 16:03:14 +05:00
|
|
|
|
{
|
2021-05-14 09:58:02 +05:00
|
|
|
|
DeleteOldRequestDates();
|
2021-05-13 10:26:24 +05:00
|
|
|
|
return requests.Keys;
|
2021-05-12 16:03:14 +05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|