diff options
Diffstat (limited to 'Software/Visual_Studio/Tango.Telemetry/Sources/TelemetryMachineUpdatesStreamingSource.cs')
| -rw-r--r-- | Software/Visual_Studio/Tango.Telemetry/Sources/TelemetryMachineUpdatesStreamingSource.cs | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/Software/Visual_Studio/Tango.Telemetry/Sources/TelemetryMachineUpdatesStreamingSource.cs b/Software/Visual_Studio/Tango.Telemetry/Sources/TelemetryMachineUpdatesStreamingSource.cs new file mode 100644 index 000000000..85d5309a5 --- /dev/null +++ b/Software/Visual_Studio/Tango.Telemetry/Sources/TelemetryMachineUpdatesStreamingSource.cs @@ -0,0 +1,66 @@ +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.BL.Entities; +using Tango.BL.Enumerations; +using Tango.Telemetry.Mappers; +using Tango.Telemetry.Telemetries; + +namespace Tango.Telemetry.Sources +{ + public class TelemetryMachineUpdatesStreamingSource : ITelemetryStreamingSource + { + public string Name { get; } = "Machine Updates Streaming"; + + public bool RequiresTelemetryDuplicationTracking { get; } = true; + + public bool IsStarted { get; private set; } + + public event EventHandler<TelemetryAvailableEventArgs> TelemetryAvailable; + + public void Start() + { + if (!IsStarted) + { + IsStarted = true; + TangoUpdate.TangoUpdateSaved += TangoUpdate_UpdateSaved; + } + } + + public void Stop() + { + if (IsStarted) + { + IsStarted = false; + TangoUpdate.TangoUpdateSaved -= TangoUpdate_UpdateSaved; + } + } + + private void TangoUpdate_UpdateSaved(object sender, TangoUpdate update) + { + if (IsStarted) + { + if (!update.IsSynchronization) + { + using (ObservablesContext db = ObservablesContext.CreateDefault()) + { + if (db.TangoUpdates.Any(x => x.Guid == update.Guid)) return; + + TelemetryMachineUpdate tUpdate = MachineUpdateMapper.MapMachineUpdate(update); + + TelemetryAvailable?.Invoke(this, new TelemetryAvailableEventArgs() { TelemetryObject = tUpdate }); + } + } + } + } + + public void Dispose() + { + Stop(); + } + } +} |
