From d4ac2453b8649d95bf7eb09ab48745c51d26d439 Mon Sep 17 00:00:00 2001 From: Milan Hanajik Date: Wed, 2 Dec 2020 13:36:21 +0100 Subject: [PATCH] Refactorization. --- TBF/BenchControl/OutputPath.cs | 28 +++++++++++----------- TBF/BenchControl/Sequences/SequenceBase.cs | 4 ++-- TBF/Utils.cs | 16 ++++++------- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/TBF/BenchControl/OutputPath.cs b/TBF/BenchControl/OutputPath.cs index 68d17b4ce..a2bf7fd5d 100644 --- a/TBF/BenchControl/OutputPath.cs +++ b/TBF/BenchControl/OutputPath.cs @@ -1,5 +1,5 @@ /// -/// Copyright (c) 2013-2017 Sensus Metering Systems +/// Copyright (c) 2013-2020 Sensus Slovensko a.s. /// using System.Collections.Generic; using TBF.BenchControl.GenericDevices; @@ -39,19 +39,19 @@ namespace TBF.BenchControl } /// Constructor from data entity - public OutputPath(Config.Entities.OutputPath outputPathEntity, IList components) - : this(outputPathEntity.Name, outputPathEntity.ItemNr) + public OutputPath(Config.Entities.OutputPath entity, IList components) + : this(entity.Name, entity.ItemNr) { - Qfrom = outputPathEntity.Qfrom; - Qto = outputPathEntity.Qto; - FlowMeter = (IFlowMeter)TbfComponents.FindComponent(outputPathEntity.FlowMeter, components); - RegulValve = (IRegulValve)TbfComponents.FindComponent(outputPathEntity.RegulValve, components); - PidCoef = outputPathEntity.PidCoef; - Diverter = (IDiverter)TbfComponents.FindComponent(outputPathEntity.Diverter, components); - TempDiv = (ITempMeter)TbfComponents.FindComponent(outputPathEntity.TempDiv, components); - Scale = (IScaleOrTank)TbfComponents.FindComponent(outputPathEntity.Scale, components); + Qfrom = entity.Qfrom; + Qto = entity.Qto; + FlowMeter = (IFlowMeter)TbfComponents.FindComponent(entity.FlowMeter, components); + RegulValve = (IRegulValve)TbfComponents.FindComponent(entity.RegulValve, components); + PidCoef = entity.PidCoef; + Diverter = (IDiverter)TbfComponents.FindComponent(entity.Diverter, components); + TempDiv = (ITempMeter)TbfComponents.FindComponent(entity.TempDiv, components); + Scale = (IScaleOrTank)TbfComponents.FindComponent(entity.Scale, components); - string[] svs = outputPathEntity.StartValve != null ? outputPathEntity.StartValve.Split(new char[] { '~' }) : new string[0]; + string[] svs = entity.StartValve != null ? entity.StartValve.Split(new char[] { '~' }) : new string[0]; int iTmp; /// StartValve1 = (IValve)TbfComponents.FindComponent(((svs.Length > 0) ? svs[0] : string.Empty), components); @@ -63,11 +63,11 @@ namespace TBF.BenchControl InvertSV3 = (svs.Length > 6) ? svs[6].Equals("i") : false; LagSV3 = (svs.Length > 7 && int.TryParse(svs[7], out iTmp)) ? iTmp : 0; - string[] vOpen = outputPathEntity.ValvesOpen.Split(new char[] { ';' }); + string[] vOpen = entity.ValvesOpen.Split(new char[] { ';' }); ValvesOpen = new List(); foreach (var vName in vOpen) ValvesOpen.Add((IValve)TbfComponents.FindComponent(vName, components)); - string[] vClose = outputPathEntity.ValvesClose.Split(new char[] { ';' }); + string[] vClose = entity.ValvesClose.Split(new char[] { ';' }); ValvesClose = new List(); foreach (var vName in vClose) ValvesClose.Add((IValve)TbfComponents.FindComponent(vName, components)); } diff --git a/TBF/BenchControl/Sequences/SequenceBase.cs b/TBF/BenchControl/Sequences/SequenceBase.cs index a47e2f78e..bc9da5be8 100644 --- a/TBF/BenchControl/Sequences/SequenceBase.cs +++ b/TBF/BenchControl/Sequences/SequenceBase.cs @@ -598,7 +598,7 @@ namespace TBF.BenchControl.Sequences /// FM controlled pumps are canged imediately without using any state operations log.DebugFormat("step.PumpWithFMPcts = {0}", step.PumpWithFMPcts); - float[] allFMPumpPcts = Utils.GetPumpWithFMPcts(step); + float[] allFMPumpPcts = Utils.GetPumpWithFMPcts(step.PumpWithFMPcts); for (int i = 0; i < allFMPumpPcts.Length; i++) { float pwr = allFMPumpPcts[i]; @@ -613,7 +613,7 @@ namespace TBF.BenchControl.Sequences } /// Get new regulation valve positions, - float[] allRegvPositions = Utils.GetRegulValvesPositions(step); + float[] allRegvPositions = Utils.GetRegulValvesPositions(step.RegulValvesPct); /// Prepare necessary SetRegValvePositionOp operations for RV-s with changed positions IList rvPosOps = new List(); diff --git a/TBF/Utils.cs b/TBF/Utils.cs index 7ae2524de..e9809acb0 100644 --- a/TBF/Utils.cs +++ b/TBF/Utils.cs @@ -189,16 +189,16 @@ namespace TBF /// - /// Get an array of RegulValve positions from a TransitionStep entity + /// Get an array of RegulValve positions from a string /// - /// TransitionStep entity + /// String from TransitionStep entity defining all RegulValve positions /// float[] of regulation valve positions from 0 to 100.0f - public static float[] GetRegulValvesPositions(TransitionStep step) + public static float[] GetRegulValvesPositions(string regulValvesPct) { int regvCount = BenchControl.Sequences.SequenceBase.RegulValves.Count; float[] result = new float[regvCount]; - string[] rvPosStr = (step.RegulValvesPct != null) ? step.RegulValvesPct.Split(new char[] { ';' }) : new string[0]; + string[] rvPosStr = string.IsNullOrEmpty(regulValvesPct) ? new string[0] : regulValvesPct.Split(new char[] { ';' }); for (int i = 0; i < regvCount; i++) { float fdummy; @@ -218,16 +218,16 @@ namespace TBF /// - /// Get an array of Pump-With-FM power percentages from a TransitionStep entity + /// Get an array of Pump-With-FM power percentages from a string /// - /// TransitionStep entity + /// String from TransitionStep entity defining all FM pump powers /// float[] of FM-pump power percentages from 0 to 100.0f - public static float[] GetPumpWithFMPcts(TransitionStep step) + public static float[] GetPumpWithFMPcts(string pumpWithFMPcts) { int fmPumpCount = BenchControl.Sequences.SequenceBase.PumpsWithFM.Count; float[] result = new float[fmPumpCount]; - string[] fmPctsStr = (step.PumpWithFMPcts != null) ? step.PumpWithFMPcts.Split(new char[] { ';' }) : new string[0]; + string[] fmPctsStr = string.IsNullOrEmpty(pumpWithFMPcts) ? new string[0] : pumpWithFMPcts.Split(new char[] { ';' }); for (int i = 0; i < fmPumpCount; i++) { float fdummy;