using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Tango.Core; using Tango.Integration.Operation; using Tango.Telemetry.Mappers; namespace Tango.Telemetry.Sources { public class TelemetryJobRunsStreamingSource : ExtendedObject, ITelemetryStreamingSource { private IMachineOperator _machineOperator; public string Name { get; } = "JobRuns Streaming"; public bool RequiresTelemetryDuplicationTracking { get; } = false; public bool IsStarted { get; private set; } public event EventHandler TelemetryAvailable; public TelemetryJobRunsStreamingSource(IMachineOperator machineOperator) { _machineOperator = machineOperator; } private void JobRunsLogger_JobRunAvailable(object sender, Integration.JobRuns.JobRunAvailableEventArgs e) { Task.Factory.StartNew(() => { if (IsStarted) { var tRun = JobRunMapper.MapJobRun(e.JobRun); TelemetryAvailable?.Invoke(this, new TelemetryAvailableEventArgs() { TelemetryObject = tRun }); } }); } public void Dispose() { Stop(); } public void Start() { if (!IsStarted) { _machineOperator.JobRunsLogger.JobRunAvailable += JobRunsLogger_JobRunAvailable; IsStarted = true; } } public void Stop() { if (IsStarted) { _machineOperator.JobRunsLogger.JobRunAvailable -= JobRunsLogger_JobRunAvailable; IsStarted = false; } } } }