2015-04-15 18:32:56 +00:00
|
|
|
|
///
|
|
|
|
|
|
/// Copyright (c) 2013-2015 Sensus Metering Systems
|
|
|
|
|
|
///
|
|
|
|
|
|
using System.Collections.Generic;
|
2015-12-04 16:17:20 +00:00
|
|
|
|
using Config.Entities;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
using TBF.BenchControl.Generic;
|
|
|
|
|
|
|
|
|
|
|
|
namespace TBF.BenchControl
|
|
|
|
|
|
{
|
|
|
|
|
|
public static class TbfComponents
|
|
|
|
|
|
{
|
2014-12-29 15:00:27 +00:00
|
|
|
|
public readonly static IList<IComponentFactory> Factories;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
|
|
|
|
|
static TbfComponents()
|
|
|
|
|
|
{
|
|
|
|
|
|
Factories = new List<IComponentFactory>();
|
|
|
|
|
|
|
2015-02-01 15:20:27 +00:00
|
|
|
|
Factories.Add(new TestMethods.Adjustment.TestMethodFactory());
|
|
|
|
|
|
Factories.Add(new ResultsPrinters.Basic.PrinterFactory());
|
2015-08-01 20:21:43 +00:00
|
|
|
|
Factories.Add(new BenchInfo.Munich.ComponentFactory());
|
|
|
|
|
|
Factories.Add(new BenchInfo.Polska.ComponentFactory());
|
2014-07-28 07:54:35 +00:00
|
|
|
|
Factories.Add(new Cameras.CameraRoi.CameraRoiFactory());
|
2015-02-01 15:20:27 +00:00
|
|
|
|
Factories.Add(new TestMethods.CombinedMeters.TestMethodFactory());
|
|
|
|
|
|
Factories.Add(new TestMethods.CombinedWithDetection.TestMethodFactory());
|
|
|
|
|
|
Factories.Add(new Elde.ControlBoardFactory());
|
2015-03-25 01:12:06 +00:00
|
|
|
|
Factories.Add(new DataEntry.Combined.EntryFormFactory());
|
2015-02-01 15:20:27 +00:00
|
|
|
|
Factories.Add(new DataEntry.Munich3.EntryFormFactory());
|
2014-07-28 07:54:35 +00:00
|
|
|
|
Factories.Add(new DataEntry.Munich.EntryFormFactory());
|
2015-08-24 07:33:13 +00:00
|
|
|
|
Factories.Add(new DataEntry.iPerl.EntryFormFactory());
|
2016-06-10 10:08:08 +00:00
|
|
|
|
Factories.Add(new DataEntry.Standard6.EntryFormFactory());
|
2015-09-22 12:01:43 +00:00
|
|
|
|
Factories.Add(new DataEntry.Standard12.EntryFormFactory());
|
2015-05-19 16:46:36 +00:00
|
|
|
|
Factories.Add(new DataEntry.Standard24.EntryFormFactory());
|
2015-09-22 12:01:43 +00:00
|
|
|
|
Factories.Add(new DataEntry.Standard48.EntryFormFactory());
|
2015-05-19 16:46:36 +00:00
|
|
|
|
Factories.Add(new Elde.Diverter.DiverterFactory());
|
2015-10-05 08:11:59 +00:00
|
|
|
|
Factories.Add(new TestMethods.FixedStartAdvanced.TestMethodFactory()); /// FixedStartAdvanced
|
2015-06-02 15:59:54 +00:00
|
|
|
|
Factories.Add(new TestMethods.FixedStartCombinedMeters.TestMethodFactory());
|
2015-10-05 08:11:59 +00:00
|
|
|
|
Factories.Add(new TestMethods.FixedStartMassCollection.TestMethodFactory()); /// FixedStartMassCollection
|
2015-02-01 15:20:27 +00:00
|
|
|
|
Factories.Add(new Elde.FixedStartRegisterReader.RegisterReaderFactory());
|
|
|
|
|
|
Factories.Add(new Elde.FlowMeter.FlowMeterFactory());
|
|
|
|
|
|
Factories.Add(new Elde.FlowMeterTwins.FlowMeterFactory());
|
|
|
|
|
|
Factories.Add(new TestMethods.FlyingStart.TestMethodFactory());
|
2016-01-03 01:05:35 +00:00
|
|
|
|
Factories.Add(new TestMethods.FlyingStartMassCollection.TestMethodFactory());
|
2015-02-01 15:20:27 +00:00
|
|
|
|
Factories.Add(new DataEntry.WMStates.EntryFormFactory());
|
2015-04-16 20:06:42 +00:00
|
|
|
|
Factories.Add(new Ambient.Comet.Factory());
|
|
|
|
|
|
Factories.Add(new Ambient.Greco.Factory());
|
2016-08-04 13:46:17 +00:00
|
|
|
|
Factories.Add(new TestMethods.HeatMeters.TestMethodFactory()); /// HeatMeters
|
2015-02-01 15:20:27 +00:00
|
|
|
|
Factories.Add(new Cameras.IdcCamera.IdcCameraFactory());
|
2015-07-31 08:45:50 +00:00
|
|
|
|
Factories.Add(new WaterMeters.iPerl.WaterMeterFactory()); /// iPerl
|
2015-08-22 04:27:57 +00:00
|
|
|
|
Factories.Add(new TestMethods.iPerlCommunication.TestMethodFactory()); /// iPerlCommunication
|
2016-06-23 14:39:56 +00:00
|
|
|
|
Factories.Add(new Keithley.RS232.Factory()); /// Keithley.RS232.Multimeter
|
|
|
|
|
|
Factories.Add(new Keithley.TempMeter.Factory()); /// Keithley.TempMeter
|
|
|
|
|
|
Factories.Add(new ResultsPrinters.LabelPrinter.PrinterFactory()); /// LabelPrinter
|
2015-08-11 06:50:32 +00:00
|
|
|
|
Factories.Add(new TestMethods.LeakTest.TestMethodFactory());
|
2015-07-31 08:45:50 +00:00
|
|
|
|
Factories.Add(new MettlerToledo.Standard.BalanceFactory()); /// MettlerToledo Balance
|
2016-04-20 13:58:48 +00:00
|
|
|
|
Factories.Add(new MettlerToledo.Standard.BalanceOldFactory()); /// MettlerToledoBalanceOld
|
|
|
|
|
|
Factories.Add(new MettlerToledo.Standard.BalanceNewFactory()); /// MettlerToledoBalanceSN
|
2015-07-31 08:45:50 +00:00
|
|
|
|
Factories.Add(new MettlerToledo.Multi.BalanceFactory()); /// MettlerToledo-Multi
|
|
|
|
|
|
Factories.Add(new Modbus.Common.Factory()); /// Modbus
|
2016-04-24 06:55:39 +00:00
|
|
|
|
Factories.Add(new Output.FileWriters.Basic.FactorySingle()); /// Output.FileWriters.Basic.Single
|
|
|
|
|
|
Factories.Add(new Output.FileWriters.Basic.FactoryCompound()); /// Output.FileWriters.Basic.Compound
|
2016-04-29 15:21:23 +00:00
|
|
|
|
Factories.Add(new Output.FileWriters.Enhanced.FactorySingle()); /// Output.FileWriters.Basic.Single
|
2016-06-23 14:39:56 +00:00
|
|
|
|
Factories.Add(new Output.FileWriters.Enhanced.FactoryCompound()); /// Output.FileWriters.Basic.Compound
|
2016-04-29 15:21:23 +00:00
|
|
|
|
Factories.Add(new TestMethods.PMaxTest.TestMethodFactory());
|
2015-02-01 15:20:27 +00:00
|
|
|
|
Factories.Add(new Elde.PressureMeter.PressureMeterFactory());
|
2015-05-21 15:48:27 +00:00
|
|
|
|
Factories.Add(new Elde.PressureMeterInternal.PressureMeterFactory());
|
2014-07-28 07:54:35 +00:00
|
|
|
|
Factories.Add(new Elde.Pump.PumpFactory());
|
2015-02-16 12:36:22 +00:00
|
|
|
|
Factories.Add(new Danfoss.VLT2800.PumpFactory());
|
2014-07-28 07:54:35 +00:00
|
|
|
|
Factories.Add(new Elde.PumpWithFM.PumpFactory());
|
2015-01-11 04:06:18 +00:00
|
|
|
|
Factories.Add(new Elde.PumpTandem.PumpFactory());
|
2015-07-31 08:45:50 +00:00
|
|
|
|
Factories.Add(new Modbus.QuidoRS.Factory()); /// QuidoRS
|
2015-02-01 15:20:27 +00:00
|
|
|
|
Factories.Add(new TestMethods.ReferenceFlowmeterCalibration.TestMethodFactory());
|
|
|
|
|
|
Factories.Add(new Elde.RegisterReader.RegisterReaderFactory());
|
2014-07-28 07:54:35 +00:00
|
|
|
|
Factories.Add(new Elde.RegulValve.RegulValveFactory());
|
2015-02-03 06:48:48 +00:00
|
|
|
|
Factories.Add(new Elde.RegulValveTandem.RegulValveTandemFactory());
|
2016-02-18 20:30:13 +00:00
|
|
|
|
Factories.Add(new ResultsPrinters.Cevak.PrinterFactory());
|
2014-07-28 07:54:35 +00:00
|
|
|
|
Factories.Add(new ResultsPrinters.Munich.PrinterFactory());
|
|
|
|
|
|
Factories.Add(new TestMethods.CameraRoiDetection.RoiDetectionFactory());
|
2015-08-19 12:17:02 +00:00
|
|
|
|
Factories.Add(new DB.SensusOracle.DatabaseFactory());
|
2015-02-01 15:20:27 +00:00
|
|
|
|
Factories.Add(new Elde.TempMeter.TempMeterFactory());
|
2015-05-21 15:48:27 +00:00
|
|
|
|
Factories.Add(new Elde.TempMeterInternal.TempMeterFactory());
|
2015-02-01 15:20:27 +00:00
|
|
|
|
Factories.Add(new Elde.Valve.ValveFactory());
|
2015-07-01 13:28:28 +00:00
|
|
|
|
Factories.Add(new Elde.ValveEx.ValveFactory());
|
2016-05-19 22:10:16 +00:00
|
|
|
|
Factories.Add(new WaterMeters.Munich.WaterMeterFactory()); /// WaterMeter
|
|
|
|
|
|
Factories.Add(new WaterMeters.WaterMeter.WaterMeterFactory()); /// WaterMeter
|
|
|
|
|
|
Factories.Add(new ResultsPrinters.Zapiska.PrinterFactory()); /// Zapiska
|
2014-07-28 07:54:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Get a component factory given the component name
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="className">Component class name</param>
|
|
|
|
|
|
/// <returns>Component factory instance</returns>
|
|
|
|
|
|
public static IComponentFactory CmpntFactoryFromClassName(string className)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var factory in Factories)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (factory.ClassName.Equals(className)) return factory;
|
|
|
|
|
|
}
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-09-16 10:04:08 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Get a component configuration given a component DB entity
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="entity">DB entity</param>
|
|
|
|
|
|
/// <returns>An appropriate component configuration or null if factory was not found</returns>
|
2015-12-04 16:17:20 +00:00
|
|
|
|
public static IComponentCfg CmpntCfgFromCmpntEntity(Component entity)
|
2014-07-28 07:54:35 +00:00
|
|
|
|
{
|
2014-09-16 10:04:08 +00:00
|
|
|
|
IComponentFactory cmpntFactory = CmpntFactoryFromClassName(entity.ClassName);
|
|
|
|
|
|
return (cmpntFactory != null) ? cmpntFactory.CmpntCfgFromCmpntEntity(entity) : null;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Load component entities from the database and convert them to TBF components
|
|
|
|
|
|
/// derived from IComponent with mutual references.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="session">NHibernate DB session</param>
|
|
|
|
|
|
/// <returns>A list of TBF Components</returns>
|
|
|
|
|
|
public static IList<IComponent> LoadComponentsFromDB(NHibernate.ISession session)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var factory in Factories) factory.ResetStaticProperties();
|
|
|
|
|
|
|
|
|
|
|
|
/// Load the list of components from the database
|
2015-12-04 16:17:20 +00:00
|
|
|
|
IList<Component> cmptnEntities = session
|
2014-07-28 07:54:35 +00:00
|
|
|
|
.CreateQuery("FROM Component ORDER BY ItemNr")
|
2015-12-04 16:17:20 +00:00
|
|
|
|
.List<Component>();
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
|
|
|
|
|
/// Convert database entities to TBF components
|
|
|
|
|
|
IList<IComponent> components = new List<BenchControl.Generic.IComponent>();
|
|
|
|
|
|
foreach (var entity in cmptnEntities)
|
|
|
|
|
|
{
|
2014-09-16 10:04:08 +00:00
|
|
|
|
IComponentFactory cmpntFactory = BenchControl.TbfComponents.CmpntFactoryFromClassName(entity.ClassName);
|
|
|
|
|
|
if (cmpntFactory == null) continue;
|
|
|
|
|
|
|
2015-01-02 18:14:19 +00:00
|
|
|
|
IComponent cmpnt = cmpntFactory.CmpntCfgFromCmpntEntity(entity).GetComponent(components);
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
2014-12-31 12:46:33 +00:00
|
|
|
|
///
|
2014-07-28 07:54:35 +00:00
|
|
|
|
/// Inherit DebugMode from the parent (if any)
|
2014-12-31 12:46:33 +00:00
|
|
|
|
///
|
2015-12-04 16:17:20 +00:00
|
|
|
|
if ((cmpnt.Cfg.DebugLevel == DebugMode.Inherit) &&
|
2014-08-15 18:50:42 +00:00
|
|
|
|
(cmpnt.Cfg is IChildComponentCfg) &&
|
2014-07-28 07:54:35 +00:00
|
|
|
|
!string.IsNullOrEmpty(cmpnt.Cfg.ParentName))
|
|
|
|
|
|
{
|
2014-08-15 18:50:42 +00:00
|
|
|
|
bool inherited = false;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
foreach (var par in components)
|
|
|
|
|
|
{
|
2014-08-15 18:50:42 +00:00
|
|
|
|
if (par.Cfg.Name.Equals(cmpnt.Cfg.ParentName))
|
|
|
|
|
|
{
|
|
|
|
|
|
/// Parent found, inherit the debug mode
|
|
|
|
|
|
cmpnt.Cfg.DebugLevel = par.Cfg.DebugLevel;
|
|
|
|
|
|
inherited = true;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
2014-07-28 07:54:35 +00:00
|
|
|
|
}
|
2014-08-15 18:50:42 +00:00
|
|
|
|
if (!inherited)
|
|
|
|
|
|
{
|
|
|
|
|
|
/// Applied when the parent is (most likely) in DebugMode.Off
|
2015-12-04 16:17:20 +00:00
|
|
|
|
cmpnt.Cfg.DebugLevel = DebugMode.Off;
|
2014-08-15 18:50:42 +00:00
|
|
|
|
}
|
2014-07-28 07:54:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2015-12-04 16:17:20 +00:00
|
|
|
|
if (cmpnt.Cfg.DebugLevel != DebugMode.Off) components.Add(cmpnt);
|
2014-07-28 07:54:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return components;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Get a reference to a component with a given name from a list of components.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="name">Component name</param>
|
|
|
|
|
|
/// <param name="components">A list of components</param>
|
|
|
|
|
|
/// <returns>Matching component or null</returns>
|
|
|
|
|
|
public static IComponent FindComponent(string name, IList<IComponent> components)
|
|
|
|
|
|
{
|
2015-01-02 18:14:19 +00:00
|
|
|
|
if (string.IsNullOrEmpty(name)) return null;
|
|
|
|
|
|
foreach (var cmpnt in components)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (cmpnt.Cfg.Name.Equals(name)) return cmpnt;
|
|
|
|
|
|
}
|
2014-07-28 07:54:35 +00:00
|
|
|
|
return null;
|
|
|
|
|
|
}
|
2015-01-02 18:14:19 +00:00
|
|
|
|
|
2014-07-28 07:54:35 +00:00
|
|
|
|
public static IComponent FindComponent(string name)
|
|
|
|
|
|
{
|
|
|
|
|
|
return FindComponent(name, StateMachine.Components);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|