2015-04-15 18:32:56 +00:00
|
|
|
|
///
|
2019-09-17 08:27:23 +00:00
|
|
|
|
/// Copyright (c) 2013-2019 Sensus Slovensko a.s.
|
2015-04-15 18:32:56 +00:00
|
|
|
|
///
|
|
|
|
|
|
using System;
|
2014-12-29 15:00:27 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.IO;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
using System.Xml.Serialization;
|
2021-09-23 09:46:40 +00:00
|
|
|
|
using Common;
|
2015-12-04 16:17:20 +00:00
|
|
|
|
using Config.Entities;
|
2021-10-26 09:23:57 +00:00
|
|
|
|
using TBF.Rig.Generic;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
2021-10-26 09:23:57 +00:00
|
|
|
|
namespace TBF.Rig
|
2014-07-28 07:54:35 +00:00
|
|
|
|
{
|
|
|
|
|
|
public class ComponentCfgBase
|
|
|
|
|
|
{
|
2021-07-28 11:48:47 +00:00
|
|
|
|
[XmlIgnore] public int Id { get; set; }
|
|
|
|
|
|
[XmlIgnore] public Generic.IComponentFactory Factory { get; set; }
|
|
|
|
|
|
[XmlIgnore] public string ClassName { get { return Factory.ToString(); } }
|
|
|
|
|
|
[XmlIgnore] public string Name { get; set; }
|
|
|
|
|
|
[XmlIgnore] public string ParentName { get; set; }
|
|
|
|
|
|
[XmlIgnore] public int ItemNr { get; set; }
|
|
|
|
|
|
[XmlIgnore] public DebugMode DebugLevel { get; set; }
|
|
|
|
|
|
[XmlIgnore] public LogLevel LogLevel { get; set; }
|
|
|
|
|
|
[XmlIgnore] public IList<MeasurementCorrection> Corrections { get; set; }
|
|
|
|
|
|
[XmlIgnore] public IList<Uncertainty> Uncertainties { get; set; }
|
2019-09-17 08:27:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
2014-07-28 07:54:35 +00:00
|
|
|
|
protected ComponentCfgBase()
|
|
|
|
|
|
{
|
2021-07-28 11:48:47 +00:00
|
|
|
|
ItemNr = 0;
|
|
|
|
|
|
DebugLevel = DebugMode.Normal;
|
|
|
|
|
|
LogLevel = LogLevel.Off;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2014-12-29 15:00:27 +00:00
|
|
|
|
protected ComponentCfgBase(Generic.IComponentFactory factory)
|
2014-07-28 07:54:35 +00:00
|
|
|
|
: this()
|
|
|
|
|
|
{
|
2021-07-28 11:48:47 +00:00
|
|
|
|
Factory = factory;
|
2014-12-29 15:00:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected ComponentCfgBase(Generic.IComponentFactory factory, string name)
|
|
|
|
|
|
: this(factory)
|
|
|
|
|
|
{
|
2021-07-28 11:48:47 +00:00
|
|
|
|
Name = name;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected ComponentCfgBase(Generic.IComponentFactory factory, string name, string parentName)
|
|
|
|
|
|
: this(factory, name)
|
|
|
|
|
|
{
|
2021-07-28 11:48:47 +00:00
|
|
|
|
ParentName = parentName;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2014-12-29 15:00:27 +00:00
|
|
|
|
|
2018-06-18 10:44:37 +00:00
|
|
|
|
public virtual XmlSerializer GetSerializer() { return new XmlSerializer(GetType()); }
|
2017-06-21 21:39:34 +00:00
|
|
|
|
|
2015-12-04 16:17:20 +00:00
|
|
|
|
public Component CreateDbEntity()
|
2014-12-29 15:00:27 +00:00
|
|
|
|
{
|
|
|
|
|
|
using (var writer = new StringWriter())
|
|
|
|
|
|
{
|
2017-06-21 21:39:34 +00:00
|
|
|
|
GetSerializer().Serialize(writer, this);
|
2021-07-28 11:48:47 +00:00
|
|
|
|
return Component.CreateFromCfg(Name, Factory.ClassName, ParentName, ItemNr, DebugLevel, LogLevel, writer.ToString());
|
2014-12-29 15:00:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-06-21 21:39:34 +00:00
|
|
|
|
public static IComponentCfg CreateFromDbEntity(XmlSerializer s, Component cmpntEntity, IComponentFactory factory)
|
2014-07-28 07:54:35 +00:00
|
|
|
|
{
|
2014-12-29 15:00:27 +00:00
|
|
|
|
using (var reader = new StringReader(cmpntEntity.Parameters))
|
|
|
|
|
|
{
|
2017-06-21 21:39:34 +00:00
|
|
|
|
IComponentCfg config = s.Deserialize(reader) as IComponentCfg;
|
|
|
|
|
|
if (config != null)
|
|
|
|
|
|
{
|
2021-07-28 11:48:47 +00:00
|
|
|
|
config.Id = cmpntEntity.Id;
|
|
|
|
|
|
config.Name = cmpntEntity.Name;
|
2017-06-21 21:39:34 +00:00
|
|
|
|
config.ParentName = cmpntEntity.ParentName;
|
|
|
|
|
|
config.ItemNr = cmpntEntity.ItemNr;
|
|
|
|
|
|
config.DebugLevel = cmpntEntity.Mode;
|
|
|
|
|
|
config.LogLevel = cmpntEntity.Logging;
|
|
|
|
|
|
config.Corrections = cmpntEntity.Corrections;
|
2019-09-17 08:27:23 +00:00
|
|
|
|
config.Uncertainties = cmpntEntity.Uncertainties;
|
|
|
|
|
|
config.Factory = factory;
|
2017-06-21 21:39:34 +00:00
|
|
|
|
}
|
2014-12-29 15:00:27 +00:00
|
|
|
|
return config;
|
|
|
|
|
|
}
|
2014-07-28 07:54:35 +00:00
|
|
|
|
}
|
2014-12-31 12:46:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
2018-05-10 11:25:46 +00:00
|
|
|
|
public void LoadTestParamsFromDB(Test test)
|
2014-12-31 12:46:33 +00:00
|
|
|
|
{
|
2018-05-10 11:25:46 +00:00
|
|
|
|
ITestParams tstPrms = (GetRuntimeTestParamsProvider() as ITestParams);
|
2014-12-31 12:46:33 +00:00
|
|
|
|
if (tstPrms != null)
|
|
|
|
|
|
{
|
2018-05-10 11:25:46 +00:00
|
|
|
|
tstPrms.FromDbEntity(Name, test);
|
2014-12-31 12:46:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-05-10 11:25:46 +00:00
|
|
|
|
|
|
|
|
|
|
public void LoadProcedureParamsFromDB(Procedure procedure)
|
2014-12-31 12:46:33 +00:00
|
|
|
|
{
|
2018-05-10 11:25:46 +00:00
|
|
|
|
IProcedureParams procPrms = (GetRuntimeProcParamsProvider() as IProcedureParams);
|
2015-01-07 08:01:05 +00:00
|
|
|
|
if (procPrms != null)
|
2014-12-31 12:46:33 +00:00
|
|
|
|
{
|
2018-05-10 11:25:46 +00:00
|
|
|
|
procPrms.FromDbEntity(Name, procedure);
|
2014-12-31 12:46:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-05-10 11:25:46 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// If there are any procedure parameters, this function should be overriden
|
|
|
|
|
|
/// by one returning a reference to a newly created object
|
|
|
|
|
|
/// implementing IParamsProvider and IProcedureParams.
|
|
|
|
|
|
///
|
|
|
|
|
|
/// This default implementation returns null = no procedure parameters.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns>Procedure parameters provider for this component or null</returns>
|
|
|
|
|
|
public virtual IParamsProvider CreateProcParamsProvider()
|
|
|
|
|
|
{
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
2014-12-31 12:46:33 +00:00
|
|
|
|
|
2018-05-10 11:25:46 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// If there are any procedure parameters, this function should be overriden
|
|
|
|
|
|
/// by one returning a reference to an object
|
|
|
|
|
|
/// implementing IParamsProvider and IProcedureParams used in runtime.
|
|
|
|
|
|
///
|
|
|
|
|
|
/// This default implementation returns null = no procedure parameters.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns>Procedure parameters provider for this component or null</returns>
|
|
|
|
|
|
public virtual IParamsProvider GetRuntimeProcParamsProvider()
|
|
|
|
|
|
{
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public virtual IParamsProvider GetUIProcParamsProvider(Procedure procedure)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (GetRuntimeProcParamsProvider() == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
/// Component has no test parametes
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ComponentProcedure procParamsEntity = procedure.GetProcedureParamsEntity(Name);
|
|
|
|
|
|
|
|
|
|
|
|
if (procParamsEntity != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (procParamsEntity.GetParamsProvider() != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
/// Parameters provider for this entity already fetched - return it
|
|
|
|
|
|
return procParamsEntity.GetParamsProvider();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
/// Parameters provider for this entity will be created and updated from the entity later on
|
|
|
|
|
|
IParamsProvider paramsProvider = CreateProcParamsProvider();
|
|
|
|
|
|
(paramsProvider as IProcedureParams).UpdateFromDbEntity(procParamsEntity);
|
|
|
|
|
|
procParamsEntity.SetParamsProvider(paramsProvider);
|
|
|
|
|
|
return paramsProvider;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
IParamsProvider paramsProvider = CreateProcParamsProvider();
|
|
|
|
|
|
(paramsProvider as IProcedureParams).FromDbEntity(Name, procedure);
|
|
|
|
|
|
return paramsProvider;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// If there are any procedure parameters, this function should be overriden
|
|
|
|
|
|
/// by one returning a reference to a newly created object
|
|
|
|
|
|
/// implementing IParamsProvider and ITestParams.
|
|
|
|
|
|
///
|
|
|
|
|
|
/// This default implementation returns null = no test parameters.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns>Procedure parameters provider for this component or null</returns>
|
|
|
|
|
|
public virtual IParamsProvider CreateTestParamsProvider()
|
|
|
|
|
|
{
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// If there are any test parameters, this function should be overriden
|
|
|
|
|
|
/// by one returning a reference to an object
|
|
|
|
|
|
/// implementing IParamsProvider and ITestParams used in runtime.
|
|
|
|
|
|
///
|
|
|
|
|
|
/// This default implementation returns null = no test parameters.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns>Test parameters provider for this component or null</returns>
|
|
|
|
|
|
public virtual IParamsProvider GetRuntimeTestParamsProvider()
|
|
|
|
|
|
{
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public virtual IParamsProvider GetUITestParamsProvider(Test test)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (GetRuntimeTestParamsProvider() == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
/// Component has no test parametes
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ComponentTest testParamsEntity = test.GetTestParamsEntity(Name);
|
|
|
|
|
|
|
|
|
|
|
|
if (testParamsEntity != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (testParamsEntity.GetParamsProvider() != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
/// Parameters provider for this entity already fetched - return it
|
|
|
|
|
|
return testParamsEntity.GetParamsProvider();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
/// Parameters provider for this entity will be created and updated from the entity later on
|
|
|
|
|
|
IParamsProvider paramsProvider = CreateTestParamsProvider();
|
|
|
|
|
|
(paramsProvider as ITestParams).UpdateFromDbEntity(testParamsEntity);
|
|
|
|
|
|
testParamsEntity.SetParamsProvider(paramsProvider);
|
|
|
|
|
|
return paramsProvider;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
IParamsProvider paramsProvider = CreateTestParamsProvider();
|
|
|
|
|
|
(paramsProvider as ITestParams).FromDbEntity(Name, test);
|
|
|
|
|
|
return paramsProvider;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2014-12-31 12:46:33 +00:00
|
|
|
|
}
|
2014-07-28 07:54:35 +00:00
|
|
|
|
}
|