forked from ddrilling/AsbCloudServer
Правки к предыдущему коммиту по задаче CS2-6
This commit is contained in:
parent
a1eb94901e
commit
7bbcdf8483
@ -5,7 +5,6 @@ namespace AsbCloudApp.Services
|
|||||||
public interface ITelemetryTracker
|
public interface ITelemetryTracker
|
||||||
{
|
{
|
||||||
void SaveRequest(string id);
|
void SaveRequest(string id);
|
||||||
void DeleteOldRequests(int minutes);
|
|
||||||
IEnumerable<string> GetRequests();
|
IEnumerable<string> GetRequests();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,19 +8,22 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
public class TelemetryTracker : ITelemetryTracker
|
public class TelemetryTracker : ITelemetryTracker
|
||||||
{
|
{
|
||||||
private IDictionary<string, DateTime> _requests = new Dictionary<string, DateTime>();
|
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)
|
public void SaveRequest(string id)
|
||||||
{
|
{
|
||||||
_requests[id] = DateTime.Now;
|
_requests[id] = DateTime.Now;
|
||||||
DeleteOldRequests();
|
_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()
|
public IEnumerable<string> GetRequests()
|
||||||
{
|
{
|
||||||
DeleteOldRequests();
|
_deleteOldRequests();
|
||||||
return _requests.Keys;
|
return _requests.Keys;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,10 +20,14 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
|
|
||||||
public IEnumerable<WellDto> GetTransmittingWells(int idCustomer)
|
public IEnumerable<WellDto> GetTransmittingWells(int idCustomer)
|
||||||
{
|
{
|
||||||
|
var wells = new List<Well>();
|
||||||
IEnumerable<string> activeTelemetriesUids = telemetryTracker.GetRequests();
|
IEnumerable<string> activeTelemetriesUids = telemetryTracker.GetRequests();
|
||||||
var wells = db.GetWellsByCustomer(idCustomer)
|
if (activeTelemetriesUids.Count() > 0)
|
||||||
.Where(w => activeTelemetriesUids.Contains(w.Telemetry.RemoteUid))
|
{
|
||||||
.ToList();
|
wells = db.GetWellsByCustomer(idCustomer)
|
||||||
|
.Where(w => activeTelemetriesUids.Contains(w.Telemetry.RemoteUid))
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
return wells.Select(w => From(w));
|
return wells.Select(w => From(w));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,9 +42,16 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
this.telemetryHubContext = telemetryHubContext;
|
this.telemetryHubContext = telemetryHubContext;
|
||||||
this.telemetryTracker = telemetryTracker;
|
this.telemetryTracker = telemetryTracker;
|
||||||
|
|
||||||
Request.Query.TryGetValue("uid", out Microsoft.Extensions.Primitives.StringValues pId);
|
_registerRequest();
|
||||||
string panelId = pId;
|
}
|
||||||
telemetryTracker.SaveRequest(panelId);
|
|
||||||
|
private void _registerRequest()
|
||||||
|
{
|
||||||
|
if (Request.Query.TryGetValue("uid", out Microsoft.Extensions.Primitives.StringValues pId) && pId.Count > 0)
|
||||||
|
{
|
||||||
|
string panelId = pId.First();
|
||||||
|
telemetryTracker.SaveRequest(panelId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -45,7 +45,7 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
return NoContent();
|
return NoContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
IEnumerable<WellDto> transmittingWells = wellService.GetTransmittingWells((int)idCustomer);
|
var transmittingWells = wellService.GetTransmittingWells((int)idCustomer);
|
||||||
|
|
||||||
return Ok(transmittingWells);
|
return Ok(transmittingWells);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user