diff options
Diffstat (limited to 'Software/Visual_Studio/Tango.Telemetry/Mappers/JobRunMapper.cs')
| -rw-r--r-- | Software/Visual_Studio/Tango.Telemetry/Mappers/JobRunMapper.cs | 54 |
1 files changed, 37 insertions, 17 deletions
diff --git a/Software/Visual_Studio/Tango.Telemetry/Mappers/JobRunMapper.cs b/Software/Visual_Studio/Tango.Telemetry/Mappers/JobRunMapper.cs index 8d8023c95..81bff1eb4 100644 --- a/Software/Visual_Studio/Tango.Telemetry/Mappers/JobRunMapper.cs +++ b/Software/Visual_Studio/Tango.Telemetry/Mappers/JobRunMapper.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Data.Entity; using System.IO; using System.Linq; +using System.Reflection; using System.Text; using System.Threading.Tasks; using Tango.BL; @@ -63,6 +64,8 @@ namespace Tango.Telemetry.Mappers } } + + public static TelemetryJobRun MapJobRun(JobRun run) { Init(); @@ -106,23 +109,7 @@ namespace Tango.Telemetry.Mappers tRun.Status = run.JobRunStatus.ToString(); - tRun.OutputCyan = run.CyanQuantity; - tRun.OutputMagenta = run.MagentaQuantity; - tRun.OutputYellow = run.YellowQuantity; - tRun.OutputBlack = run.BlackQuantity; - tRun.OutputLightCyan = run.LightCyanQuantity; - tRun.OutputLightMagenta = run.LightMagentaQuantity; - tRun.OutputLightYellow = run.LightYellowQuantity; - tRun.OutputBlue = run.BlueQuantity; - tRun.OutputLightBlue = run.LightBlueQuantity; - tRun.OutputOrange = run.OrangeQuantity; - tRun.OutputLightOrange = run.LightOrangeQuantity; - tRun.OutputRubine = run.RubineQuantity; - tRun.OutputLightRubine = run.LightRubineQuantity; - tRun.OutputNavy = run.NavyQuantity; - tRun.OutputViolet = run.VioletQuantity; - tRun.OutputTransparent = run.TransparentQuantity; - tRun.OutputLubricant = run.LubricantQuantity; + MapToOutputs(run, tRun); tRun.FailureReason = run.FailedMessage; @@ -319,5 +306,38 @@ namespace Tango.Telemetry.Mappers return tRun; } + + public static void MapToOutputs(JobRun run, TelemetryJobRun tRun) + { + if (run == null || tRun == null) return; + + var runProps = run.GetType() + .GetProperties(BindingFlags.Instance | BindingFlags.Public) + .Where(p => p.CanRead && p.PropertyType == typeof(long)) + .Where(p => p.Name.EndsWith("Quantity", StringComparison.OrdinalIgnoreCase)) + .ToDictionary(p => p.Name.ToLower(), p => p); + + var tRunProps = tRun.GetType() + .GetProperties(BindingFlags.Instance | BindingFlags.Public) + .Where(p => p.CanWrite && p.PropertyType == typeof(long)) + .Where(p => p.Name.StartsWith("Output", StringComparison.OrdinalIgnoreCase)) + .ToDictionary(p => p.Name.ToLower(), p => p); + + foreach (var tProp in tRunProps.Values) + { + // "OutputCyan" -> "CyanQuantity" + var baseName = tProp.Name.Substring("Output".Length); + var runKey = (baseName + "Quantity").ToLower(); + + if (!runProps.TryGetValue(runKey, out var runProp)) + { + LogManager.Default.Log($"Could not locate liquid quantity field {runKey} for JobRun Telemetry object.", LogCategory.Warning); + continue; + } + + var value = (long)(runProp.GetValue(run) ?? 0L); + tProp.SetValue(tRun, value); + } + } } } |
