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-07-28 07:54:35 +00:00
|
|
|
|
using System.Collections.Generic;
|
2017-12-20 08:14:43 +00:00
|
|
|
|
using System.IO;
|
2021-09-23 09:46:40 +00:00
|
|
|
|
using Common;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
2015-12-04 16:17:20 +00:00
|
|
|
|
namespace Config.Entities
|
2014-07-28 07:54:35 +00:00
|
|
|
|
{
|
2017-06-29 14:58:59 +00:00
|
|
|
|
public class Component : IHasName, IHasItemNr
|
2014-07-28 07:54:35 +00:00
|
|
|
|
{
|
|
|
|
|
|
public virtual int Id { get; protected set; }
|
|
|
|
|
|
public virtual int ItemNr { get; set; }
|
|
|
|
|
|
public virtual string Name { get; set; }
|
|
|
|
|
|
public virtual string ClassName { get; set; }
|
|
|
|
|
|
public virtual string ParentName { get; set; }
|
|
|
|
|
|
public virtual DebugMode Mode { get; set; }
|
|
|
|
|
|
public virtual LogLevel Logging { get; set; }
|
|
|
|
|
|
public virtual string Parameters { get; set; }
|
|
|
|
|
|
public virtual IList<MeasurementCorrection> Corrections { get; set; }
|
2019-09-17 08:27:23 +00:00
|
|
|
|
public virtual IList<Uncertainty> Uncertainties { get; set; }
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
|
|
|
|
|
/// ------------- Additional stuff not mapped into the database -------------
|
|
|
|
|
|
|
|
|
|
|
|
public Component()
|
|
|
|
|
|
{
|
2018-03-12 05:37:08 +00:00
|
|
|
|
Name = string.Empty;
|
|
|
|
|
|
ClassName = string.Empty;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
Corrections = new List<MeasurementCorrection>();
|
2019-09-17 08:27:23 +00:00
|
|
|
|
Uncertainties = new List<Uncertainty>();
|
2014-07-28 07:54:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static Component CreateFromCfg(string name, string className, string parentName, int itemNr,
|
|
|
|
|
|
DebugMode debugLevel, LogLevel logLevel, string parameters)
|
|
|
|
|
|
{
|
|
|
|
|
|
Component result = new Component();
|
|
|
|
|
|
result.ItemNr = itemNr;
|
|
|
|
|
|
result.Name = name;
|
|
|
|
|
|
result.ClassName = className;
|
|
|
|
|
|
result.ParentName = parentName;
|
|
|
|
|
|
result.Mode = debugLevel;
|
|
|
|
|
|
result.Logging = logLevel;
|
|
|
|
|
|
result.Parameters = parameters;
|
|
|
|
|
|
return result;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Makes a new copy of this object (not just a reference)
|
|
|
|
|
|
public virtual Component Clone()
|
|
|
|
|
|
{
|
|
|
|
|
|
Component result = new Component();
|
|
|
|
|
|
result.ItemNr = ItemNr;
|
|
|
|
|
|
result.Name = Name;
|
|
|
|
|
|
result.ClassName = ClassName;
|
|
|
|
|
|
result.ParentName = ParentName;
|
|
|
|
|
|
result.Mode = Mode;
|
|
|
|
|
|
result.Logging = Logging;
|
|
|
|
|
|
result.Parameters = Parameters;
|
|
|
|
|
|
return result;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-20 08:14:43 +00:00
|
|
|
|
public virtual void Export(StreamWriter output)
|
|
|
|
|
|
{
|
|
|
|
|
|
output.WriteLine(Name);
|
|
|
|
|
|
output.WriteLine(ClassName);
|
|
|
|
|
|
output.WriteLine(ParentName);
|
|
|
|
|
|
output.WriteLine(Mode.ToString());
|
|
|
|
|
|
output.WriteLine(Logging.ToString());
|
|
|
|
|
|
output.Write(Parameters);
|
|
|
|
|
|
|
|
|
|
|
|
output.Close();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static Component Import(StreamReader input)
|
|
|
|
|
|
{
|
|
|
|
|
|
Component result = new Component();
|
|
|
|
|
|
|
|
|
|
|
|
result.Name = input.ReadLine();
|
|
|
|
|
|
result.ClassName = input.ReadLine();
|
|
|
|
|
|
result.ParentName = input.ReadLine();
|
|
|
|
|
|
|
|
|
|
|
|
string line = input.ReadLine();
|
|
|
|
|
|
if (line.Equals(DebugMode.DetectedOff.ToString())) result.Mode = DebugMode.DetectedOff;
|
|
|
|
|
|
else if (line.Equals(DebugMode.DetectedOn.ToString())) result.Mode = DebugMode.DetectedOn;
|
|
|
|
|
|
else if (line.Equals(DebugMode.Normal.ToString())) result.Mode = DebugMode.Normal;
|
|
|
|
|
|
else if (line.Equals(DebugMode.AutoDetect.ToString())) result.Mode = DebugMode.AutoDetect;
|
|
|
|
|
|
else if (line.Equals(DebugMode.FailureDuringOperation.ToString())) result.Mode = DebugMode.FailureDuringOperation;
|
|
|
|
|
|
else if (line.Equals(DebugMode.Off.ToString())) result.Mode = DebugMode.Off;
|
|
|
|
|
|
else if (line.Equals(DebugMode.Record.ToString())) result.Mode = DebugMode.Record;
|
2021-09-23 09:46:40 +00:00
|
|
|
|
else if (line.Equals(DebugMode.Replay.ToString())) result.Mode = DebugMode.Replay;
|
2017-12-20 08:14:43 +00:00
|
|
|
|
else if (line.Equals(DebugMode.Simulate.ToString())) result.Mode = DebugMode.Simulate;
|
|
|
|
|
|
else if (line.Equals(DebugMode.Inherit.ToString())) result.Mode = DebugMode.Inherit;
|
|
|
|
|
|
|
|
|
|
|
|
line = input.ReadLine();
|
|
|
|
|
|
if (line.Equals(LogLevel.Off.ToString())) result.Logging = LogLevel.Off;
|
|
|
|
|
|
else if (line.Equals(LogLevel.Fatal.ToString())) result.Logging = LogLevel.Fatal;
|
|
|
|
|
|
else if (line.Equals(LogLevel.Error.ToString())) result.Logging = LogLevel.Error;
|
|
|
|
|
|
else if (line.Equals(LogLevel.Warn.ToString())) result.Logging = LogLevel.Warn;
|
|
|
|
|
|
else if (line.Equals(LogLevel.Info.ToString())) result.Logging = LogLevel.Info;
|
|
|
|
|
|
else if (line.Equals(LogLevel.Debug.ToString())) result.Logging = LogLevel.Debug;
|
|
|
|
|
|
else if (line.Equals(LogLevel.All.ToString())) result.Logging = LogLevel.All;
|
|
|
|
|
|
|
|
|
|
|
|
result.Parameters = string.Empty;
|
|
|
|
|
|
line = input.ReadLine();
|
|
|
|
|
|
while (line != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
result.Parameters += line;
|
|
|
|
|
|
result.Parameters += Environment.NewLine;
|
|
|
|
|
|
line = input.ReadLine();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-07-28 07:54:35 +00:00
|
|
|
|
public virtual string ToString(string indent)
|
|
|
|
|
|
{
|
|
|
|
|
|
string result = string.Empty;
|
|
|
|
|
|
|
|
|
|
|
|
result += indent + "ItemNr = " + (ItemNr + 1).ToString() + Environment.NewLine;
|
|
|
|
|
|
result += indent + "Name = " + Name + Environment.NewLine;
|
|
|
|
|
|
result += indent + "ClassName = " + ClassName + Environment.NewLine;
|
|
|
|
|
|
if (ParentName != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
result += indent + "ParentName = " + ParentName + Environment.NewLine;
|
|
|
|
|
|
}
|
|
|
|
|
|
result += indent + "DebugLevel = " + Mode.ToString() + Environment.NewLine;
|
|
|
|
|
|
result += indent + "LogLevel = " + Logging.ToString() + Environment.NewLine;
|
|
|
|
|
|
result += indent + "Parameters = " + Parameters + Environment.NewLine;
|
|
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
}
|
2018-03-12 05:37:08 +00:00
|
|
|
|
|
|
|
|
|
|
public override string ToString()
|
|
|
|
|
|
{
|
|
|
|
|
|
return string.Format("{0} ({1})", Name, ClassName);
|
|
|
|
|
|
}
|
2014-07-28 07:54:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|