176 lines
4.6 KiB
C#
176 lines
4.6 KiB
C#
///
|
|
/// Copyright (c) 2013-2015 Sensus Metering Systems
|
|
///
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Xml.Serialization;
|
|
using Config.Entities;
|
|
using TBF.BenchControl.Generic;
|
|
|
|
namespace TBF.BenchControl
|
|
{
|
|
public class ComponentCfgBase
|
|
{
|
|
[XmlIgnore]
|
|
public string Name
|
|
{
|
|
get { return name; }
|
|
set { name = value; }
|
|
}
|
|
string name;
|
|
|
|
[XmlIgnore]
|
|
public Generic.IComponentFactory Factory
|
|
{
|
|
get { return factory; }
|
|
set { factory = value; }
|
|
}
|
|
Generic.IComponentFactory factory;
|
|
|
|
[XmlIgnore]
|
|
public string ParentName
|
|
{
|
|
get { return parentName; }
|
|
set { parentName = value; }
|
|
}
|
|
string parentName;
|
|
|
|
[XmlIgnore]
|
|
public int ItemNr
|
|
{
|
|
get { return itemNr; }
|
|
set { itemNr = value; }
|
|
}
|
|
int itemNr;
|
|
|
|
[XmlIgnore]
|
|
public DebugMode DebugLevel
|
|
{
|
|
get { return debugLevel; }
|
|
set { debugLevel = value; }
|
|
}
|
|
DebugMode debugLevel;
|
|
|
|
[XmlIgnore]
|
|
public LogLevel LogLevel
|
|
{
|
|
get { return logLevel; }
|
|
set { logLevel = value; }
|
|
}
|
|
LogLevel logLevel;
|
|
|
|
[XmlIgnore]
|
|
public IList<MeasurementCorrection> Corrections
|
|
{
|
|
get { return corrections; }
|
|
set { corrections = value; }
|
|
}
|
|
IList<MeasurementCorrection> corrections;
|
|
|
|
protected ComponentCfgBase()
|
|
{
|
|
itemNr = 0;
|
|
debugLevel = DebugMode.Normal;
|
|
logLevel = LogLevel.Off;
|
|
}
|
|
|
|
protected ComponentCfgBase(Generic.IComponentFactory factory)
|
|
: this()
|
|
{
|
|
this.factory = factory;
|
|
}
|
|
|
|
protected ComponentCfgBase(Generic.IComponentFactory factory, string name)
|
|
: this(factory)
|
|
{
|
|
this.name = name;
|
|
}
|
|
|
|
protected ComponentCfgBase(Generic.IComponentFactory factory, string name, string parentName)
|
|
: this(factory, name)
|
|
{
|
|
this.parentName = parentName;
|
|
}
|
|
|
|
|
|
public Component CreateDbEntity()
|
|
{
|
|
using (var writer = new StringWriter())
|
|
{
|
|
(new XmlSerializer(GetType())).Serialize(writer, this);
|
|
return Component.CreateFromCfg(Name, factory.ClassName, ParentName, ItemNr, DebugLevel, LogLevel, writer.ToString());
|
|
}
|
|
}
|
|
|
|
|
|
public static IComponentCfg CreateFromDbEntity(Type type, Component cmpntEntity, IComponentFactory factory)
|
|
{
|
|
using (var reader = new StringReader(cmpntEntity.Parameters))
|
|
{
|
|
IComponentCfg config = (IComponentCfg)(new XmlSerializer(type)).Deserialize(reader);
|
|
config.Name = cmpntEntity.Name;
|
|
config.ParentName = cmpntEntity.ParentName;
|
|
config.ItemNr = cmpntEntity.ItemNr;
|
|
config.DebugLevel = cmpntEntity.Mode;
|
|
config.LogLevel = cmpntEntity.Logging;
|
|
config.Corrections = cmpntEntity.Corrections;
|
|
config.Factory = factory;
|
|
return config;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Default implementation returning null - no test aprameters.
|
|
/// In case there are any test parameters, this function override should return
|
|
/// a reference to a class that implements IParamsProvider and ITestParams.
|
|
/// </summary>
|
|
/// <returns>Test parameters obtained by the last UpdateTestParams(test)</returns>
|
|
public virtual IParamsProvider GetTestParams()
|
|
{
|
|
return null;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Default implementation returning null - no procedure parameters.
|
|
/// In case there are any procedure parameters, this function override should return
|
|
/// a reference to a class that implements IParamsProvider and IProcedureParams.
|
|
/// </summary>
|
|
/// <returns>Procedure parameters obtained by the last UpdateProcedureParams(procedure)</returns>
|
|
public virtual IParamsProvider GetProcedureParams()
|
|
{
|
|
return null;
|
|
}
|
|
|
|
|
|
public void UpdateTestParams(Test test)
|
|
{
|
|
ITestParams tstPrms = (GetTestParams() as ITestParams);
|
|
if (tstPrms != null)
|
|
{
|
|
tstPrms.UpdateTestParams(Name, test);
|
|
}
|
|
}
|
|
|
|
public void UpdateProcedureParams(Procedure procedure)
|
|
{
|
|
IProcedureParams procPrms = (GetProcedureParams() as IProcedureParams);
|
|
if (procPrms != null)
|
|
{
|
|
procPrms.UpdateProcedureParams(Name, procedure);
|
|
}
|
|
}
|
|
|
|
|
|
public virtual IParamsProvider CreateTestParams(Test test)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
public virtual IParamsProvider CreateProcedureParams(Procedure procedure)
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
}
|