From 4fcf044cc0a4265f6c9c2aad2a3a7aad92eafefa Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Sun, 17 Aug 2025 19:50:32 +0300 Subject: Telemetry Logs & Events. --- .../Sources/TelemetryEventsHistorySource.cs | 79 ++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 Software/Visual_Studio/Tango.Telemetry/Sources/TelemetryEventsHistorySource.cs (limited to 'Software/Visual_Studio/Tango.Telemetry/Sources/TelemetryEventsHistorySource.cs') 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 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> 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 tRuns = new List(); + + foreach (var ev in events) + { + var tEvent = EventMapper.MapEvent(ev); + tRuns.Add(tEvent); + } + + return tRuns; + } + } + finally + { + _isBusy = false; + } + } + + public void Dispose() + { + + } + } +} -- cgit v1.3.1