2014-07-28 07:54:35 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using TBF.BenchControl.Generic;
|
|
|
|
|
|
|
|
|
|
|
|
namespace TBF.BenchControl
|
|
|
|
|
|
{
|
|
|
|
|
|
public static class TbfComponents
|
|
|
|
|
|
{
|
|
|
|
|
|
public static IList<IComponentFactory> Factories;
|
|
|
|
|
|
|
|
|
|
|
|
static TbfComponents()
|
|
|
|
|
|
{
|
|
|
|
|
|
Factories = new List<IComponentFactory>();
|
|
|
|
|
|
|
|
|
|
|
|
Factories.Add(new BenchId.ComponentFactory());
|
|
|
|
|
|
Factories.Add(new Cameras.IdcCamera.IdcCameraFactory());
|
|
|
|
|
|
Factories.Add(new Cameras.CameraRoi.CameraRoiFactory());
|
|
|
|
|
|
Factories.Add(new DataEntry.Munich.EntryFormFactory());
|
2014-07-28 20:13:30 +00:00
|
|
|
|
Factories.Add(new DataEntry.Munich3.EntryFormFactory());
|
|
|
|
|
|
Factories.Add(new Elde.ControlBoardFactory());
|
2014-07-28 07:54:35 +00:00
|
|
|
|
Factories.Add(new Elde.Diverter.DiverterFactory());
|
|
|
|
|
|
Factories.Add(new Elde.FlowMeter.FlowMeterFactory());
|
2014-09-15 20:00:30 +00:00
|
|
|
|
Factories.Add(new Elde.FlowMeterTwins.FlowMeterFactory());
|
2014-09-10 11:43:33 +00:00
|
|
|
|
Factories.Add(new Elde.PressureMeter.PressureMeterFactory());
|
2014-07-28 07:54:35 +00:00
|
|
|
|
Factories.Add(new Elde.Pump.PumpFactory());
|
|
|
|
|
|
Factories.Add(new Elde.PumpWithFM.PumpFactory());
|
|
|
|
|
|
Factories.Add(new Elde.RegisterReader.RegisterReaderFactory());
|
|
|
|
|
|
Factories.Add(new Elde.RegulValve.RegulValveFactory());
|
|
|
|
|
|
Factories.Add(new Elde.TempMeter.TempMeterFactory());
|
|
|
|
|
|
Factories.Add(new Elde.Valve.ValveFactory());
|
|
|
|
|
|
Factories.Add(new Greco.AmbientFactory());
|
|
|
|
|
|
Factories.Add(new MettlerToledo.BalanceFactory());
|
|
|
|
|
|
Factories.Add(new MettlerToledo.BalanceNewFactory());
|
|
|
|
|
|
Factories.Add(new ResultsPrinters.Basic.PrinterFactory());
|
|
|
|
|
|
Factories.Add(new ResultsPrinters.Munich.PrinterFactory());
|
|
|
|
|
|
Factories.Add(new ResultsWriters.Basic.WriterFactory());
|
|
|
|
|
|
Factories.Add(new TestMethods.CameraRoiDetection.RoiDetectionFactory());
|
|
|
|
|
|
Factories.Add(new TestMethods.CombinedMeters.TestMethodFactory());
|
|
|
|
|
|
Factories.Add(new TestMethods.CombinedWithDetection.TestMethodFactory());
|
2014-09-05 07:06:23 +00:00
|
|
|
|
Factories.Add(new TestMethods.FixedStartMassCollection.TestMethodFactory());
|
2014-09-06 15:34:26 +00:00
|
|
|
|
Factories.Add(new TestMethods.FlyingStart.TestMethodFactory());
|
2014-09-05 07:06:23 +00:00
|
|
|
|
Factories.Add(new TestMethods.FlyingStartCollectionMethod.TestMethodFactory());
|
2014-09-06 15:34:26 +00:00
|
|
|
|
Factories.Add(new TestMethods.ReferenceFlowmeterCalibration.TestMethodFactory());
|
2014-09-05 07:06:23 +00:00
|
|
|
|
Factories.Add(new WaterMeter.WaterMeterFactory());
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static IComponentCfg CmpntCfgFromCmpntEntity(Entities.Component entity)
|
|
|
|
|
|
{
|
|
|
|
|
|
return CmpntFactoryFromClassName(entity.ClassName).CmpntCfgFromCmpntEntity(entity);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <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
|
|
|
|
|
|
IList<Entities.Component> cmptnEntities = session
|
|
|
|
|
|
.CreateQuery("FROM Component ORDER BY ItemNr")
|
|
|
|
|
|
.List<Entities.Component>();
|
|
|
|
|
|
|
|
|
|
|
|
/// Convert database entities to TBF components
|
|
|
|
|
|
IList<IComponent> components = new List<BenchControl.Generic.IComponent>();
|
|
|
|
|
|
foreach (var entity in cmptnEntities)
|
|
|
|
|
|
{
|
|
|
|
|
|
IComponent cmpnt = BenchControl.TbfComponents
|
|
|
|
|
|
.CmpntFactoryFromClassName(entity.ClassName)
|
|
|
|
|
|
.ComponentFromCmpntCfg(BenchControl.TbfComponents.CmpntCfgFromCmpntEntity(entity), components);
|
|
|
|
|
|
|
|
|
|
|
|
/// Inherit DebugMode from the parent (if any)
|
2014-08-15 18:50:42 +00:00
|
|
|
|
if ((cmpnt.Cfg.DebugLevel == Entities.DebugMode.Inherit) &&
|
|
|
|
|
|
(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
|
|
|
|
|
|
cmpnt.Cfg.DebugLevel = Entities.DebugMode.Off;
|
|
|
|
|
|
}
|
2014-07-28 07:54:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (cmpnt.Cfg.DebugLevel != Entities.DebugMode.Off) components.Add(cmpnt);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (name == null) return null;
|
|
|
|
|
|
foreach (var cmpnt in components) if (cmpnt.Cfg.Name.Equals(name)) return cmpnt;
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
public static IComponent FindComponent(string name)
|
|
|
|
|
|
{
|
|
|
|
|
|
return FindComponent(name, StateMachine.Components);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static IParamsProvider GetTestParams(IComponent cmpnt, Entities.Test test)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (cmpnt == null || cmpnt.Cfg == null || !cmpnt.Cfg.Factory.HasTestParams) return null;
|
|
|
|
|
|
|
|
|
|
|
|
/// Search for an existing matching entity
|
|
|
|
|
|
foreach (var tstPrms in test.MoreParams)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (tstPrms.CmpntName.Equals(cmpnt.Cfg.Name)) return cmpnt.Cfg.Factory.GetTestParams(tstPrms);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Create a new entity and add it to the list test.MoreParams
|
|
|
|
|
|
Entities.ComponentTest testParams = new Entities.ComponentTest { CmpntName = cmpnt.Cfg.Name, Test = test };
|
|
|
|
|
|
test.MoreParams.Add(testParams);
|
|
|
|
|
|
return cmpnt.Cfg.Factory.GetTestParams(testParams);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static IParamsProvider GetProcedureParams(IComponent cmpnt, Entities.Procedure procedure)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (cmpnt == null || cmpnt.Cfg == null || !cmpnt.Cfg.Factory.HasProcedureParams) return null;
|
|
|
|
|
|
|
|
|
|
|
|
/// Search for an existing matching entity
|
|
|
|
|
|
foreach (var procPrms in procedure.MoreParams)
|
|
|
|
|
|
{
|
2014-07-29 17:25:13 +00:00
|
|
|
|
if (procPrms.CmpntName.Equals(cmpnt.Cfg.Name))
|
|
|
|
|
|
{
|
|
|
|
|
|
return cmpnt.Cfg.Factory.GetProcedureParams(procPrms);
|
|
|
|
|
|
}
|
2014-07-28 07:54:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Create a new entity and add it to the list procedure.MoreParams
|
|
|
|
|
|
Entities.ComponentProcedure procParams = new Entities.ComponentProcedure { CmpntName = cmpnt.Cfg.Name, Procedure = procedure };
|
|
|
|
|
|
procedure.MoreParams.Add(procParams);
|
|
|
|
|
|
return cmpnt.Cfg.Factory.GetProcedureParams(procParams);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|