/// /// Copyright (c) 2013-2023 Sensus Slovensko a.s. /// using System.Collections.Generic; using System.Linq; using Common; using Config.Entities; using TBF.Rig.Generic; namespace TBF.Rig { public static class TbfComponents { public readonly static IList Factories; static TbfComponents() { Factories = new List() { new Ambient.Comet.Factory(), new Ambient.Greco.Factory(), new ControlBoard.Papouch.Factory(), new ControlBoard.Uni.Factory(), new DataContainer.BackupAndSecurityOptions.Factory(), new DataContainer.BenchInfo.Factory(), new DataContainer.Buoyancy.Factory(), new DataContainer.Density.Factory(), new DataContainer.Evaporation.Factory(), new DataContainer.iPerlBenchInfo.Factory(), new DataEntry.Combined.EntryFormFactory(), new DataEntry.HeatMeters6.Factory(), new DataEntry.HeatMeters12.Factory(), new DataEntry.iPerl.Factory(), new DataEntry.S620.Factory(), new DataEntry.Single.Factory(), new DataEntry.Single.FactoryNoStartEnd(), new DataEntry.Standard6.Factory(), new DataEntry.Standard6.FactoryNoStartEnd(), new DataEntry.Standard12.Factory(), new DataEntry.Standard12.FactoryNoStartEnd(), new DataEntry.Standard24.Factory(), new DataEntry.Standard24.FactoryNoStartEnd(), new DataEntry.Standard48.Factory(), new DataEntry.Standard48.FactoryNoStartEnd(), new DataEntry.StandardCamera.Factory(), new DataEntry.Uni.Factory(), new DataEntry.Uni.FactoryNoStartEnd(), new RegisterReaders.KPackE.DataEntryForRadio.Factory(), /// DataEntry for KPackE radio new Uni.Diverter.Factory(), new Dummy.Balance.Factory(), new Dummy.Diverter.Factory(), new Dummy.FlowMeter.Factory(), new Dummy.RegValve.Factory(), new Dummy.TempControl.Factory(), new Dummy.Valve.Factory(), new Uni.FlowMeter.Factory(), new Uni.FlowMetersInParallel.Factory(), new Hart.Common.Factory(), new Hart.Nivotrack.Factory(), new Keithley.Multimeter_2010_RS232.Factory(), /// Keithley.Multimeter_2010_RS232 new Keithley.TempMeter.Factory(), /// Keithley.TempMeter new Modbus.Common.Factory(), /// Modbus new Modbus.Ambient.Comet.Factory(), /// Comet Ambient temp./pressure/humidity measurement via a modbus on a PC new Modbus.PressureMeter.Meret.Factory(), /// Meret pressure meter connected via a modbus on a PC new Modbus.Meret.AdjustableScale.Factory(), /// Adjustable meter connected via a modbus on a PC new Modbus.PumpFM.DanfossVLT.Factory(), /// Pump controlled by Danfoss VLT connected via Modbus new Modbus.QuidoRS.Factory(), /// Modbus.QuidoRS new Modbus.TankSelector.Factory(), /// Modbus.TankSelector new Modbus.TempControl.Easytherm.Factory(), new Modbus.TempControl.Novus.Factory(), new Modbus.TempMeter.Groch.Factory(), /// Groch temperature meter connected via a modbus on a PC new Modbus.TempMeter.Meret.Factory(), /// Meret temperature meter connected via a modbus on a PC new Modbus.UltrasoundLevelMeter.Factory(), new Modbus.WaterAnalyzer.Factory(), new Network.Adapter.Factory(), new Network.Camera.CLP1611.Factory(), new Network.Camera.Display.Factory(), new Network.Camera.Roi.Factory(), new Network.Camera.RoiForFixedStart.Factory(), new Network.Comet.Ambient.Factory(), new Output.DB.ProductionTracing.Factory(), new Output.DB.SaveDiverterCorrections.Factory(), new Output.DB.SaveFlowmeterCorrections.Factory(), new Output.DB.SensusOracle.Factory(), new Output.EventTriggers.Iperl.Factory(), new Output.EventTriggers.Standard.Factory(), new Output.FileWriters.Basic.FactorySingle(), new Output.FileWriters.Basic.FactoryCompound(), new Output.FileWriters.Basic.FactoryHeatMeters(), new Output.FileWriters.Elde.FactorySingle(), new Output.FileWriters.Enhanced.FactorySingle(), new Output.FileWriters.Enhanced.FactoryCompound(), new Output.FileWriters.Enhanced.FactoryHeatMeters(), new Output.FileWriters.ImageArchiver.Factory(), new Output.FileWriters.IperlLogger.Factory(), new Output.FileWriters.OneFilePerMeter.FactorySingle(), new Output.FileWriters.OneFilePerMeter.FactoryCompound(), new Output.FileWriters.OneFilePerMeter.FactoryHeatMeters(), new Output.FileWriters.Xml.FactorySingle(), new Output.FileWriters.Xml.FactoryCompound(), new Output.FileWriters.Xml.FactoryHeatMeters(), new Output.FileWriters.XmlBatch.FactorySingle(), new Output.Printers.Enhanced.FactorySingle(), new Output.Printers.Enhanced.FactoryCompound(), new Output.Printers.Enhanced.FactoryHeatMeters(), new Output.Printers.Label.Factory(), new Output.Printers.MultiLabel.Factory(), new Output.Printers.OnePerBatch.Factory(), new Output.Printers.OnePerMeter.FactorySingle(), new Output.Printers.OnePerMeter.FactoryCompound(), new Output.Printers.OnePerMeter.FactoryHeatMeters(), new Output.Printers.Zapiska.FactorySingle(), new Output.Printers.Zapiska.FactoryCompound(), new Output.Printers.Zapiska.FactoryHeatMeters(), new BuiltIn.Pump.PumpFactory(), new Danfoss.VLT2800.PumpFactory(), new BuiltIn.PumpTandem.PumpFactory(), new RegisterReaders.DataStream.MefImport.Factory(), /// 'Interface for data stream stream via MEF' new RegisterReaders.DataStream.Reader.Factory(), /// 'RegisterReader for data stream stream via MEF' new RegisterReaders.PulsesFromUniCB.Factory(), /// 'RegisterReader' new RegisterReaders.StandingStartStop.Factory(), /// 'RegisterReader for standing start/stop' new TestMethods.iPerlCommunication.iPerlHead.Factory(), /// 'RegisterReader for iPerl' new RegisterReaders.S640Stream.Factory(), /// 'RegisterReader for S640' new RegisterReaders.SerialStream.Factory(), /// 'RegisterReader for generic serial stream' new RegisterReaders.KPackE.RegisterReader.Factory(), /// KPackE register reader new RegisterReaders.KPackE.Radio.Factory(), /// Radio for KPackE register readers new Uni.RegValve.Factory(), new Uni.RegValveAnalog.Factory(), new Scales.MettlerToledo.Factory(), new TestMethods.Adjustment.Factory(), new TestMethods.ChangeFlowDirection.Factory(), new TestMethods.CombinedWithDetection.TestMethodFactory(), new TestMethods.Counter.Factory(), new TestMethods.DiverterTest.Factory(), new TestMethods.Dummy.Factory(), new TestMethods.Endurance.Factory(), new TestMethods.Evacuation.Factory(), new TestMethods.FixedStart.Single.Factory(), new TestMethods.FixedStart.Compound.Factory(), new TestMethods.FixedStart.HeatMeters.Factory(), new TestMethods.FixedStartAdvanced.Single.Factory(), new TestMethods.FixedStartDeferredEval.Single.Factory(), new TestMethods.FixedStartDeferredEval.Compound.Factory(), new TestMethods.FixedStartDeferredEval.HeatMeters.Factory(), new TestMethods.FixedStartMassCollAdvanced.Single.Factory(), new TestMethods.FixedStartMassCollAdvanced.Compound.Factory(), new TestMethods.FixedStartMassCollAdvanced.HeatMeters.Factory(), new TestMethods.FixedStartMassCollDeferredEval.Single.Factory(), new TestMethods.FixedStartMassCollDeferredEval.Compound.Factory(), new TestMethods.FixedStartMassCollDeferredEval.HeatMeters.Factory(), new TestMethods.FixedStartTankCollection.Single.Factory(), new TestMethods.FixedStartTankCollection.Compound.Factory(), new TestMethods.FlowAdjustment.Factory(), new TestMethods.FlyingStart.Single.Factory(), new TestMethods.FlyingStart.Compound.Factory(), new TestMethods.FlyingStart.HeatMeters.Factory(), new TestMethods.FlyingStartMassCollection.Single.Factory(), new TestMethods.FlyingStartMassCollection.Compound.Factory(), new TestMethods.FlyingStartMassCollection.HeatMeters.Factory(), new TestMethods.FlyingStartMassCollComparative.Single.Factory(), new TestMethods.FlyingStartMassCollComparative.Compound.Factory(), new TestMethods.FlyingStartMassCollComparative.HeatMeters.Factory(), new TestMethods.FlyingStartMassCollProlonged.Single.Factory(), new TestMethods.FlyingStartMassCollProlonged.Compound.Factory(), new TestMethods.FlyingStartMassCollProlonged.HeatMeters.Factory(), new TestMethods.FlyingStartFirstRepetWithMassColl.Single.Factory(), new TestMethods.FlyingStartFirstRepetWithMassColl.Compound.Factory(), new TestMethods.FlyingStartFirstRepetWithMassColl.HeatMeters.Factory(), new TestMethods.FlyingStartTankCollection.Single.Factory(), new TestMethods.FlyingStartTankCollection.Compound.Factory(), new TestMethods.GrabImage.Factory(), new TestMethods.iPerlCommunication.TestMethodFactory(), /// iPerlCommunication new TestMethods.LeakTest.Factory(), new TestMethods.LiveStream.Factory(), new TestMethods.ManualEntry.Factory(), new TestMethods.OuterLoop.Start.Factory(), new TestMethods.OuterLoop.End.Factory(), new TestMethods.PMaxTest.Factory(), new TestMethods.PulsesTest.Factory(), new TestMethods.PulsesTestManual.Factory(), new TestMethods.Q2CorrectionFromHistory.Factory(), new TestMethods.RoiDetection.RoiDetectionFactory(), new TestMethods.S640Communication.S640StartFactory(), new TestMethods.S640Communication.S640EndFactory(), new TestMethods.SensitivityTest.Factory(), new TestMethods.StandingStart.Single.Factory(), new TestMethods.StandingStart.Compound.Factory(), new TestMethods.StandingStart.HeatMeters.Factory(), new TestMethods.StandingStartMassCollection.Single.Factory(), new TestMethods.StandingStartMassCollection.Compound.Factory(), new TestMethods.StandingStartMassCollection.HeatMeters.Factory(), new TestMethods.StandingStartMassCollWODiv.Factory(), new BuiltIn.Valve.ValveFactory(), new BuiltIn.ValveEx.ValveFactory(), new Various.Clamping.Factory(), new Various.CoverTest.Factory(), new Various.Drawing.Junction.Factory(), new Various.Drawing.Knee.Factory(), new Various.Drawing.Pipes.Factory(), new Various.Drawing.Tank.Factory(), new Various.Drawing.Vacuum.Factory(), new Various.EmergencyStop.Factory(), new Various.ErrorFlags.Factory(), new Various.StatisticsMonitoring.Factory(), new Various.TankWithLevelMsrmnt.Factory(), new WaterMeters.WaterMeter.WaterMeterFactory(), /// 'WaterMeter' #if OBSOLETE /// Obsolete components new MettlerToledo.Standard.BalanceFactory(), /// MettlerToledo Balance new MettlerToledo.Standard.BalanceOldFactory(), /// MettlerToledoBalanceOld new MettlerToledo.Standard.BalanceNewFactory(), /// MettlerToledoBalanceSN #endif }; } /// /// Get a component factory given the component name /// /// Component class name /// Component factory instance public static IComponentFactory CmpntFactoryFromClassName(string className) { foreach (var factory in Factories) { if (factory.ClassName.Equals(className)) return factory; } return null; } /// /// Get a component configuration given a component DB entity /// /// DB entity /// An appropriate component configuration or null if factory was not found public static IComponentCfg CmpntCfgFromCmpntEntity(Component entity) { IComponentFactory cmpntFactory = CmpntFactoryFromClassName(entity.ClassName); if (cmpntFactory == null) return null; try { return cmpntFactory.CmpntCfgFromCmpntEntity(entity); } catch { return null; } } public static string CurrentlyLoadedComponentName; /// /// Load component entities from the database and convert them to TBF components /// derived from IComponent with mutual references. /// /// NHibernate DB session /// A list of TBF Components public static IList LoadComponentsFromDB(NHibernate.ISession session) { /// Load the list of components from the database var cmptnEntities = session.QueryOver() .OrderBy(x => x.ItemNr).Asc .List(); return LoadComponentsFromDB(cmptnEntities); } /// /// Load component entities from the database and convert them to TBF components /// derived from IComponent with mutual references. /// /// NHibernate DB session /// A list of TBF Components public static IList LoadComponentsFromDB(IList cmptnEntities) { CurrentlyLoadedComponentName = string.Empty; /// Convert database entities to TBF components IList components = new List(); foreach (var entity in cmptnEntities) { CurrentlyLoadedComponentName = entity.Name; IComponentFactory cmpntFactory = Rig.TbfComponents.CmpntFactoryFromClassName(entity.ClassName); if (cmpntFactory == null) continue; IComponent cmpnt = cmpntFactory.GetComponent(cmpntFactory.CmpntCfgFromCmpntEntity(entity), components); /// /// Inherit DebugMode from the parent (if any) /// if ((cmpnt.Cfg.DebugLevel == DebugMode.Inherit) && (cmpnt.Cfg is IChildComponentCfg) && !string.IsNullOrEmpty(cmpnt.Cfg.ParentName)) { bool inherited = false; foreach (var par in components) { if (par.Cfg.Name.Equals(cmpnt.Cfg.ParentName)) { /// Parent found, inherit the debug mode cmpnt.Cfg.DebugLevel = par.Cfg.DebugLevel; inherited = true; break; } } if (!inherited) { /// Applied when the parent is (most likely) in DebugMode.Off cmpnt.Cfg.DebugLevel = DebugMode.Off; } } if (cmpnt.Cfg.DebugLevel != DebugMode.Off) components.Add(cmpnt); } CurrentlyLoadedComponentName = string.Empty; return components; } /// /// Get a reference to a component with a given name from a list of components. /// /// Component name /// A list of components /// Matching component or null public static IComponent FindComponent(string name, IList components) { if (string.IsNullOrEmpty(name) || components == null) return null; return components.FirstOrDefault(x => x.Name == name); } public static IComponent FindComponent(string name) { return FindComponent(name, StateMachine.Components); } } }