tbf/TestBenchFramework/BenchControl/Elde/RegisterReader/RegisterReaderCfg.cs
2014-07-28 09:56:40 +02:00

61 lines
1.8 KiB
C#

using System;
using System.IO;
using System.Xml.Serialization;
using TBF.BenchControl.Generic;
namespace TBF.BenchControl.Elde.RegisterReader
{
public class RegisterReaderCfg : ComponentCfgBase, Generic.IChildComponentCfg
{
public int Position; /// 1..nrWaterMeters
/// Parameterless constructor
public RegisterReaderCfg()
{
}
/// <summary>
/// Regulation valve configuration parameters
/// </summary>
/// <param name="name">Regulation valve name</param>
/// <param name="position">Position on the control board 1 .. nrWaterMeters</param>
public RegisterReaderCfg(IComponentFactory factory, string name, string parentName, int position)
: base(factory, name, parentName)
{
if (position < 1 || position >= 2 * Program.WMsCount)
{
throw new ArgumentOutOfRangeException("position");
}
this.Position = position;
}
public IComponentCfg Clone()
{
return new RegisterReaderCfg(Factory, Name, ParentName, Position);
}
public string ToString(int i)
{
return string.Format("position={0}", Position);
}
public TBF.Entities.Component CreateDbEntity()
{
using (var writer = new StringWriter())
{
(new XmlSerializer(GetType())).Serialize(writer, this);
return Entities.Component.CreateFromCfg(Name, Factory.ClassName, ParentName, ItemNr, DebugLevel, LogLevel, writer.ToString());
}
}
public static IComponentCfg CreateFromDbEntity(Entities.Component component, IComponentFactory factory)
{
using (var reader = new StringReader(component.Parameters))
{
RegisterReaderCfg config = (RegisterReaderCfg)(new XmlSerializer(typeof(RegisterReaderCfg))).Deserialize(reader);
config.InitCfgBaseFromEntity(component, factory);
return config;
}
}
}
}