2015-04-15 18:32:56 +00:00
|
|
|
|
///
|
2017-05-01 13:57:37 +00:00
|
|
|
|
/// Copyright (c) 2013-2017 Sensus Metering Systems
|
2015-04-15 18:32:56 +00:00
|
|
|
|
///
|
|
|
|
|
|
using System;
|
2014-12-31 12:46:33 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Xml.Serialization;
|
2015-12-04 16:17:20 +00:00
|
|
|
|
using Config.Entities;
|
2014-12-31 12:46:33 +00:00
|
|
|
|
|
|
|
|
|
|
namespace TBF.BenchControl
|
|
|
|
|
|
{
|
|
|
|
|
|
public class ProcedureParamsBase : Generic.IProcedureParams
|
|
|
|
|
|
{
|
2015-12-04 16:17:20 +00:00
|
|
|
|
protected ComponentProcedure procedureParamsEntity;
|
2014-12-31 12:46:33 +00:00
|
|
|
|
|
2017-06-21 21:39:34 +00:00
|
|
|
|
protected virtual XmlSerializer GetSerializer() { return new XmlSerializer(GetType()); }
|
|
|
|
|
|
|
2014-12-31 12:46:33 +00:00
|
|
|
|
public string ComponentName { get { return componentName; } }
|
|
|
|
|
|
protected string componentName;
|
|
|
|
|
|
|
2015-12-04 16:17:20 +00:00
|
|
|
|
public Procedure Procedure { get { return procedure; } }
|
|
|
|
|
|
protected Procedure procedure;
|
2014-12-31 12:46:33 +00:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Parameterless constructor required for serialization
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public ProcedureParamsBase()
|
|
|
|
|
|
{
|
|
|
|
|
|
InitializeAll();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary> To be overridden </summary>
|
|
|
|
|
|
public virtual void InitializeAll()
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary> To be overridden </summary>
|
2015-12-04 16:17:20 +00:00
|
|
|
|
public virtual void UpdateProcedureParams(ComponentProcedure dbEntity)
|
2014-12-31 12:46:33 +00:00
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-12-04 16:17:20 +00:00
|
|
|
|
public void UpdateProcedureParams(string cmpntName, Procedure procedure)
|
2014-12-31 12:46:33 +00:00
|
|
|
|
{
|
|
|
|
|
|
/// Search for an existing matching entity
|
|
|
|
|
|
foreach (var procPrms in procedure.MoreParams)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (procPrms.CmpntName.Equals(cmpntName))
|
|
|
|
|
|
{
|
|
|
|
|
|
UpdateProcedureParams(procPrms);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Create a new entity and add it to the list test.MoreParams
|
2015-01-04 15:26:54 +00:00
|
|
|
|
this.procedureParamsEntity = this.ToDbEntity(cmpntName, procedure);
|
|
|
|
|
|
this.procedure = procedure;
|
|
|
|
|
|
this.componentName = cmpntName;
|
|
|
|
|
|
procedure.MoreParams.Add(procedureParamsEntity);
|
2014-12-31 12:46:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2015-12-04 16:17:20 +00:00
|
|
|
|
public ComponentProcedure ToDbEntity(string componentName, Procedure procedure)
|
2014-12-31 12:46:33 +00:00
|
|
|
|
{
|
|
|
|
|
|
using (var writer = new StringWriter())
|
|
|
|
|
|
{
|
|
|
|
|
|
/// Serialize this class with parameters
|
2017-06-21 21:39:34 +00:00
|
|
|
|
GetSerializer().Serialize(writer, this);
|
2014-12-31 12:46:33 +00:00
|
|
|
|
|
|
|
|
|
|
/// Create and return the ComponentProcedure entity
|
2015-12-04 16:17:20 +00:00
|
|
|
|
ComponentProcedure entity = new ComponentProcedure();
|
2014-12-31 12:46:33 +00:00
|
|
|
|
entity.CmpntName = componentName;
|
|
|
|
|
|
entity.Parameters = writer.ToString();
|
|
|
|
|
|
entity.Procedure = procedure;
|
|
|
|
|
|
return entity;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void UpdateDbEntity()
|
|
|
|
|
|
{
|
|
|
|
|
|
using (var writer = new StringWriter())
|
|
|
|
|
|
{
|
|
|
|
|
|
/// Serialize this class and update the entity
|
2017-06-21 21:39:34 +00:00
|
|
|
|
GetSerializer().Serialize(writer, this);
|
2014-12-31 12:46:33 +00:00
|
|
|
|
procedureParamsEntity.Parameters = writer.ToString();
|
|
|
|
|
|
procedureParamsEntity.CmpntName = componentName;
|
|
|
|
|
|
procedureParamsEntity.Procedure = procedure;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public virtual string ParamName(int i) { return string.Empty; }
|
|
|
|
|
|
|
|
|
|
|
|
public virtual int ParamsCount() { return 0; }
|
|
|
|
|
|
|
|
|
|
|
|
public virtual string ToString(int i) { return string.Empty; }
|
|
|
|
|
|
|
|
|
|
|
|
public override string ToString()
|
|
|
|
|
|
{
|
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
|
for (int i = 0; i < ParamsCount(); i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (i != 0) sb.Append("; ");
|
|
|
|
|
|
sb.Append(ParamName(i));
|
|
|
|
|
|
sb.Append("=");
|
|
|
|
|
|
sb.Append(ToString(i));
|
|
|
|
|
|
}
|
|
|
|
|
|
return sb.ToString();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|