forked from ddrilling/AsbCloudServer
eab95cb7a1
Add State and LastTelemetryDate into StatWellDto.
35 lines
1.0 KiB
C#
35 lines
1.0 KiB
C#
using AsbCloudApp.Services;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace AsbCloudInfrastructure.Services
|
|
{
|
|
public class TelemetryTracker : ITelemetryTracker
|
|
{
|
|
private Dictionary<string, DateTime> requests = new Dictionary<string, DateTime>();
|
|
private readonly TimeSpan timeout = TimeSpan.FromDays(7);
|
|
|
|
public void SaveRequestDate(string uid)
|
|
{
|
|
requests[uid] = DateTime.Now;
|
|
DeleteOldRequestDates();
|
|
}
|
|
|
|
public DateTime GetLastTelemetryDateByUid(string uid) =>
|
|
requests.GetValueOrDefault(uid, DateTime.MinValue);
|
|
|
|
public IEnumerable<string> GetTransmittingTelemetryUids()
|
|
{
|
|
DeleteOldRequestDates();
|
|
return requests.Keys;
|
|
}
|
|
|
|
private void DeleteOldRequestDates()
|
|
{
|
|
requests = requests.Where(dValue => (DateTime.Now - dValue.Value) < timeout)
|
|
.ToDictionary(dValue => dValue.Key, dValue => dValue.Value);
|
|
}
|
|
}
|
|
}
|