aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.Integration/JobRuns/BasicJobRunsLogger.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Software/Visual_Studio/Tango.Integration/JobRuns/BasicJobRunsLogger.cs')
-rw-r--r--Software/Visual_Studio/Tango.Integration/JobRuns/BasicJobRunsLogger.cs51
1 files changed, 20 insertions, 31 deletions
diff --git a/Software/Visual_Studio/Tango.Integration/JobRuns/BasicJobRunsLogger.cs b/Software/Visual_Studio/Tango.Integration/JobRuns/BasicJobRunsLogger.cs
index e128a5949..4f442152d 100644
--- a/Software/Visual_Studio/Tango.Integration/JobRuns/BasicJobRunsLogger.cs
+++ b/Software/Visual_Studio/Tango.Integration/JobRuns/BasicJobRunsLogger.cs
@@ -15,6 +15,7 @@ using Tango.BL.Enumerations;
using Tango.Core;
using Tango.Core.ExtensionMethods;
using Tango.Integration.Operation;
+using Tango.Logging;
using Tango.PMR.MachineStatus;
using Tango.PMR.Printing;
@@ -399,44 +400,32 @@ namespace Tango.Integration.JobRuns
}
}
- private void SetJobRunLiquidQuantities(JobRun run, List<BL.ValueObjects.JobRunLiquidQuantity> quantities, bool update = false)
+
+ public void SetJobRunLiquidQuantities(JobRun run, IEnumerable<BL.ValueObjects.JobRunLiquidQuantity> quantities, bool update = false)
{
- if (run == null || quantities == null)
- return;
+ if (run == null || quantities == null) return;
- // Map each LiquidType to the corresponding JobRun property updater
- var setters = new Dictionary<LiquidTypes, Action<long>>
- {
- { LiquidTypes.Cyan, q => run.CyanQuantity = update ? run.CyanQuantity + q : q },
- { LiquidTypes.Magenta, q => run.MagentaQuantity = update ? run.MagentaQuantity + q : q },
- { LiquidTypes.Yellow, q => run.YellowQuantity = update ? run.YellowQuantity + q : q },
- { LiquidTypes.Black, q => run.BlackQuantity = update ? run.BlackQuantity + q : q },
- { LiquidTypes.Transparent, q => run.TransparentQuantity = update ? run.TransparentQuantity + q : q },
- { LiquidTypes.Lubricant, q => run.LubricantQuantity = update ? run.LubricantQuantity + q : q },
- { LiquidTypes.Cleaner, q => run.CleanerQuantity = update ? run.CleanerQuantity + q : q },
- { LiquidTypes.LightCyan, q => run.LightCyanQuantity = update ? run.LightCyanQuantity + q : q },
- { LiquidTypes.LightMagenta, q => run.LightMagentaQuantity = update ? run.LightMagentaQuantity + q : q },
- { LiquidTypes.LightYellow, q => run.LightYellowQuantity = update ? run.LightYellowQuantity + q : q },
- { LiquidTypes.Blue, q => run.BlueQuantity = update ? run.BlueQuantity + q : q },
- { LiquidTypes.LightBlue, q => run.LightBlueQuantity = update ? run.LightBlueQuantity + q : q },
- { LiquidTypes.Orange, q => run.OrangeQuantity = update ? run.OrangeQuantity + q : q },
- { LiquidTypes.LightOrange, q => run.LightOrangeQuantity = update ? run.LightOrangeQuantity + q : q },
- { LiquidTypes.Rubine, q => run.RubineQuantity = update ? run.RubineQuantity + q : q },
- { LiquidTypes.LightRubine, q => run.LightRubineQuantity = update ? run.LightRubineQuantity + q : q },
- { LiquidTypes.Navy, q => run.NavyQuantity = update ? run.NavyQuantity + q : q },
- { LiquidTypes.Violet, q => run.VioletQuantity = update ? run.VioletQuantity + q : q },
- { LiquidTypes.TWCyan, q => run.TwCyanQuantity = update ? run.VioletQuantity + q : q }
- };
+ var props = run.GetType()
+ .GetProperties(BindingFlags.Instance | BindingFlags.Public)
+ .Where(p => p.CanRead && p.CanWrite && p.PropertyType == typeof(long))
+ .Where(p => p.Name.EndsWith("Quantity", StringComparison.OrdinalIgnoreCase))
+ .ToDictionary(p => p.Name.ToLower(), p => p);
- foreach (var liquidType in setters.Keys)
+ foreach (var q in quantities)
{
- var quantityObj = quantities.SingleOrDefault(x => x.LiquidType == liquidType);
- var quantity = quantityObj?.Quantity ?? 0;
- setters[liquidType](quantity);
+ var key = (q.LiquidType.ToString() + "Quantity").ToLower();
+ if (!props.TryGetValue(key, out var prop))
+ {
+ LogManager.Log($"Could not locate liquid quantity field for {q.LiquidType} on JobRun object.", LogCategory.Error);
+ continue;
+ }
+
+ var currentVal = (long)(prop.GetValue(run) ?? 0L);
+ var newVal = update ? currentVal + q.Quantity : q.Quantity;
+ prop.SetValue(run, newVal);
}
}
-
#endregion
#region Public Methods