From 1cbef6c4d79a1db8c8d3923edfec2e50277caa51 Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Tue, 9 Sep 2025 06:51:14 +0300 Subject: RMl Default Liquid Factor + Machine Type + Improved RML Filter Loading. --- .../JobRuns/BasicJobRunsLogger.cs | 53 +++++++++------------- 1 file changed, 21 insertions(+), 32 deletions(-) (limited to 'Software/Visual_Studio/Tango.Integration/JobRuns/BasicJobRunsLogger.cs') 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 quantities, bool update = false) + + public void SetJobRunLiquidQuantities(JobRun run, IEnumerable 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.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 } - }; - - foreach (var liquidType in setters.Keys) + 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 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 -- cgit v1.3.1