diff options
| author | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2025-08-17 19:50:32 +0300 |
|---|---|---|
| committer | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2025-08-17 19:50:32 +0300 |
| commit | 4fcf044cc0a4265f6c9c2aad2a3a7aad92eafefa (patch) | |
| tree | a3b146dadddc5bd67350ee837af0499c53308478 /Software/Visual_Studio/Tango.Telemetry/Sources/TelemetryEventsHistorySource.cs | |
| parent | d150ca010285dc76add9d9f5606dd6d150a610c5 (diff) | |
| download | Tango-4fcf044cc0a4265f6c9c2aad2a3a7aad92eafefa.tar.gz Tango-4fcf044cc0a4265f6c9c2aad2a3a7aad92eafefa.zip | |
Telemetry Logs & Events.
Diffstat (limited to 'Software/Visual_Studio/Tango.Telemetry/Sources/TelemetryEventsHistorySource.cs')
| -rw-r--r-- | Software/Visual_Studio/Tango.Telemetry/Sources/TelemetryEventsHistorySource.cs | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/Software/Visual_Studio/Tango.Telemetry/Sources/TelemetryEventsHistorySource.cs b/Software/Visual_Studio/Tango.Telemetry/Sources/TelemetryEventsHistorySource.cs new file mode 100644 index 000000000..57abee66b --- /dev/null +++ b/Software/Visual_Studio/Tango.Telemetry/Sources/TelemetryEventsHistorySource.cs @@ -0,0 +1,79 @@ +using System; +using System.Collections.Generic; +using System.Data.Entity; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.BL; +using Tango.Telemetry.Mappers; +using Tango.Telemetry.Telemetries; + +namespace Tango.Telemetry.Sources +{ + public class TelemetryEventsHistorySource : ITelemetryHistorySource + { + private bool _isBusy; + + public TelemetryHistorySourceDirection Direction { get; } = TelemetryHistorySourceDirection.Descending; + public string Name { get; } = "Events History"; + public bool RequiresTelemetryDuplicationTracking { get; } = true; + + public async Task<bool> CanRequestHistory(DateTime from) + { + if (_isBusy) + { + return false; + } + else + { + try + { + using (ObservablesContext db = ObservablesContext.CreateDefault()) + { + return await db.MachinesEvents.CountAsync(x => x.LastUpdated < from) > 0; + } + } + catch + { + return false; + } + } + } + + public async Task<IEnumerable<ITelemetry>> RequestHistory(DateTime from) + { + try + { + _isBusy = true; + + using (ObservablesContext db = ObservablesContext.CreateDefault()) + { + var events = await db.MachinesEvents + .OrderByDescending(x => x.LastUpdated) + .Where(x => x.LastUpdated < from) + .Take(10) + .ToListAsync(); + + List<TelemetryEvent> tRuns = new List<TelemetryEvent>(); + + foreach (var ev in events) + { + var tEvent = EventMapper.MapEvent(ev); + tRuns.Add(tEvent); + } + + return tRuns; + } + } + finally + { + _isBusy = false; + } + } + + public void Dispose() + { + + } + } +} |
