2015-04-15 18:32:56 +00:00
|
|
|
|
///
|
2017-06-08 13:42:47 +00:00
|
|
|
|
/// Copyright (c) 2013-2017 Sensus Metering Systems
|
2015-04-15 18:32:56 +00:00
|
|
|
|
///
|
|
|
|
|
|
using System;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
using System.Collections.Generic;
|
2017-04-11 10:49:07 +00:00
|
|
|
|
using System.Globalization;
|
2017-03-31 16:14:21 +00:00
|
|
|
|
using System.IO;
|
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
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Stores one test procedure, supports revisions and history log
|
|
|
|
|
|
/// </summary>
|
2017-06-29 14:58:59 +00:00
|
|
|
|
public class Procedure : 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; }
|
2015-11-26 22:51:49 +00:00
|
|
|
|
|
2014-12-11 21:35:16 +00:00
|
|
|
|
public virtual string Description { get; set; } /// Short description
|
2014-07-28 07:54:35 +00:00
|
|
|
|
public virtual string CreationUser { get; set; } /// Name of the user who has created or changed this procedure
|
|
|
|
|
|
public virtual DateTime CreationTime { get; set; } /// Date and time of the creation or change
|
|
|
|
|
|
public virtual string LastChgUser { get; set; } /// Name of the user who has created or changed this procedure
|
|
|
|
|
|
public virtual DateTime LastChgTime { get; set; } /// Date and time of the creation or change
|
|
|
|
|
|
public virtual string LongDescription { get; set; } /// Long description (notes)
|
2015-11-26 22:51:49 +00:00
|
|
|
|
|
|
|
|
|
|
public virtual ProcedureState ProcedureState { get; set; }
|
|
|
|
|
|
public virtual int Revision { get; set; }
|
|
|
|
|
|
public virtual int PredecessorId { get; set; }
|
2017-06-08 13:42:47 +00:00
|
|
|
|
public virtual bool ObtainedByCopy { get; set; } /// Initial version of this procedure was a copy of another procedure
|
2017-06-26 14:11:47 +00:00
|
|
|
|
///
|
2017-06-08 13:42:47 +00:00
|
|
|
|
public virtual MetersKind MetersKind { get; set; } /// single / compound / heat meters
|
2014-07-28 07:54:35 +00:00
|
|
|
|
public virtual string Watermeters { get; set; } /// Water meter name or Id
|
2017-05-03 20:19:26 +00:00
|
|
|
|
public virtual bool Protected { get; set; } /// true = procedure cannot be changed by a testing specialist
|
|
|
|
|
|
public virtual bool MustBeComplete { get; set; } /// true = procedure can be finished just when all tests were finished
|
|
|
|
|
|
public virtual bool ManualCtrlDisabled { get; set; } /// true = manual control of valves, etc. is disabled
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
|
|
|
|
|
public virtual string DataEntry { get; set; } /// Component to use for data entry
|
|
|
|
|
|
public virtual string ResultsPrinter { get; set; } /// Component to use for printing the results
|
|
|
|
|
|
public virtual string ResultsWriter { get; set; } /// Component to use for saving the results into the file
|
|
|
|
|
|
public virtual string TransitionStart { get; set; }
|
|
|
|
|
|
public virtual string TransitionEnd { get; set; }
|
|
|
|
|
|
|
2017-07-24 06:32:56 +00:00
|
|
|
|
public virtual string AltProcName { get; set; } /// Alternative procedure name (null or string.Empty = no alt. procedure)
|
|
|
|
|
|
public virtual int AltProcPeriod { get; set; } /// Period of alternative procedures (0 = no alt. procedure)
|
2017-06-26 14:11:47 +00:00
|
|
|
|
|
2014-07-28 07:54:35 +00:00
|
|
|
|
public virtual IList<ComponentProcedure> MoreParams { get; set; }
|
|
|
|
|
|
public virtual IList<Test> Tests { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
/// ------------- Additional stuff not mapped into the database -------------
|
|
|
|
|
|
|
|
|
|
|
|
public Procedure()
|
|
|
|
|
|
{
|
2015-02-02 13:45:06 +00:00
|
|
|
|
MoreParams = new List<ComponentProcedure>();
|
|
|
|
|
|
Tests = new List<Test>();
|
|
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
/// Default values
|
|
|
|
|
|
///
|
2017-03-16 20:53:12 +00:00
|
|
|
|
CreationUser = (Users.GlobalData.CurrentUser != null) ? Users.GlobalData.CurrentUser.UserName : null;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
CreationTime = DateTime.Now;
|
|
|
|
|
|
LastChgUser = CreationUser;
|
|
|
|
|
|
LastChgTime = CreationTime;
|
2015-03-25 04:35:05 +00:00
|
|
|
|
MetersKind = Entities.MetersKind.Single;
|
2017-07-24 06:32:56 +00:00
|
|
|
|
Watermeters = string.Empty;
|
|
|
|
|
|
Description = string.Empty;
|
|
|
|
|
|
LongDescription = string.Empty;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Procedure(string name, int itemNr)
|
|
|
|
|
|
: this()
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = name;
|
|
|
|
|
|
ItemNr = itemNr;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public virtual Procedure Clone()
|
|
|
|
|
|
{
|
|
|
|
|
|
Procedure result = new Procedure();
|
|
|
|
|
|
|
2016-02-23 14:16:43 +00:00
|
|
|
|
result.ItemNr = ItemNr;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
result.Name = Name;
|
|
|
|
|
|
result.Description = Description;
|
|
|
|
|
|
result.CreationUser = CreationUser;
|
|
|
|
|
|
result.CreationTime = CreationTime;
|
|
|
|
|
|
result.LastChgUser = LastChgUser;
|
|
|
|
|
|
result.LastChgTime = LastChgTime;
|
|
|
|
|
|
result.LongDescription = LongDescription;
|
2015-11-26 22:51:49 +00:00
|
|
|
|
|
2016-02-23 14:16:43 +00:00
|
|
|
|
result.ProcedureState = ProcedureState;
|
|
|
|
|
|
result.Revision = Revision;
|
2015-11-26 22:51:49 +00:00
|
|
|
|
result.PredecessorId = Id;
|
2016-02-23 14:16:43 +00:00
|
|
|
|
result.ObtainedByCopy = ObtainedByCopy;
|
2015-11-26 22:51:49 +00:00
|
|
|
|
|
2016-02-23 14:16:43 +00:00
|
|
|
|
result.MetersKind = MetersKind;
|
2015-01-09 08:01:08 +00:00
|
|
|
|
result.Watermeters = Watermeters;
|
2017-05-03 20:19:26 +00:00
|
|
|
|
result.Protected = Protected;
|
|
|
|
|
|
result.MustBeComplete = MustBeComplete;
|
|
|
|
|
|
result.ManualCtrlDisabled = ManualCtrlDisabled;
|
2015-01-09 08:01:08 +00:00
|
|
|
|
result.DataEntry = DataEntry;
|
|
|
|
|
|
result.ResultsPrinter = ResultsPrinter;
|
|
|
|
|
|
result.ResultsWriter = ResultsWriter;
|
|
|
|
|
|
result.TransitionStart = TransitionStart;
|
|
|
|
|
|
result.TransitionEnd = TransitionEnd;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
2017-03-31 16:14:21 +00:00
|
|
|
|
foreach (var prms in MoreParams) { result.MoreParams.Add(prms.Clone(result)); }
|
2014-07-28 07:54:35 +00:00
|
|
|
|
foreach (var test in Tests) { result.Tests.Add(test.Clone()); }
|
|
|
|
|
|
|
2017-03-31 16:14:21 +00:00
|
|
|
|
return result;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public virtual void Export(StreamWriter output)
|
|
|
|
|
|
{
|
2017-04-11 10:49:07 +00:00
|
|
|
|
output.WriteLine(ItemNr.ToString(CultureInfo.InvariantCulture));
|
2017-03-31 16:14:21 +00:00
|
|
|
|
output.WriteLine(Name);
|
|
|
|
|
|
output.WriteLine(Description);
|
|
|
|
|
|
output.WriteLine(CreationUser);
|
2017-04-11 10:49:07 +00:00
|
|
|
|
output.WriteLine(CreationTime.ToString(CultureInfo.InvariantCulture));
|
2017-03-31 16:14:21 +00:00
|
|
|
|
output.WriteLine(LastChgUser);
|
2017-04-11 10:49:07 +00:00
|
|
|
|
output.WriteLine(LastChgTime.ToString(CultureInfo.InvariantCulture));
|
|
|
|
|
|
output.WriteLine(MetersKind.ToString());
|
2017-03-31 16:14:21 +00:00
|
|
|
|
output.WriteLine(Watermeters);
|
2017-05-03 20:19:26 +00:00
|
|
|
|
output.WriteLine(Protected.ToString());
|
|
|
|
|
|
output.WriteLine(MustBeComplete.ToString());
|
|
|
|
|
|
output.WriteLine(ManualCtrlDisabled.ToString());
|
2017-03-31 16:14:21 +00:00
|
|
|
|
output.WriteLine(DataEntry);
|
|
|
|
|
|
output.WriteLine(ResultsPrinter);
|
|
|
|
|
|
output.WriteLine(ResultsWriter);
|
|
|
|
|
|
output.WriteLine(TransitionStart);
|
|
|
|
|
|
output.WriteLine(TransitionEnd);
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var prms in MoreParams) { prms.Export(output); }
|
|
|
|
|
|
output.WriteLine();
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var test in Tests) { test.Export(output); }
|
|
|
|
|
|
output.WriteLine();
|
|
|
|
|
|
|
|
|
|
|
|
output.Close();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static Procedure Import(StreamReader input)
|
|
|
|
|
|
{
|
|
|
|
|
|
Procedure result = new Procedure();
|
|
|
|
|
|
|
2017-04-11 10:49:07 +00:00
|
|
|
|
result.ItemNr = int.Parse(input.ReadLine(), CultureInfo.InvariantCulture);
|
2017-03-31 16:14:21 +00:00
|
|
|
|
result.Name = input.ReadLine();
|
|
|
|
|
|
result.Description = input.ReadLine();
|
|
|
|
|
|
result.CreationUser = input.ReadLine();
|
2017-04-11 10:49:07 +00:00
|
|
|
|
result.CreationTime = DateTime.Parse(input.ReadLine(), CultureInfo.InvariantCulture);
|
2017-03-31 16:14:21 +00:00
|
|
|
|
result.LastChgUser = input.ReadLine();
|
2017-04-11 10:49:07 +00:00
|
|
|
|
result.LastChgTime = DateTime.Parse(input.ReadLine(), CultureInfo.InvariantCulture);
|
2017-03-31 16:14:21 +00:00
|
|
|
|
string line = input.ReadLine();
|
|
|
|
|
|
result.MetersKind = line.Equals(MetersKind.Single.ToString()) ? MetersKind.Single : (line.Equals(MetersKind.Combined.ToString()) ? MetersKind.Combined : MetersKind.HeatMeter);
|
|
|
|
|
|
result.Watermeters = input.ReadLine();
|
2017-05-03 20:19:26 +00:00
|
|
|
|
result.Protected = bool.Parse(input.ReadLine());
|
|
|
|
|
|
result.MustBeComplete = bool.Parse(input.ReadLine());
|
|
|
|
|
|
result.ManualCtrlDisabled = bool.Parse(input.ReadLine());
|
2017-03-31 16:14:21 +00:00
|
|
|
|
result.DataEntry = input.ReadLine();
|
|
|
|
|
|
result.ResultsPrinter = input.ReadLine();
|
|
|
|
|
|
result.ResultsWriter = input.ReadLine();
|
|
|
|
|
|
result.TransitionStart = input.ReadLine();
|
|
|
|
|
|
result.TransitionEnd = input.ReadLine();
|
|
|
|
|
|
|
|
|
|
|
|
while(true)
|
|
|
|
|
|
{
|
|
|
|
|
|
ComponentProcedure prms = ComponentProcedure.Import(input, result);
|
|
|
|
|
|
if (prms == null)
|
|
|
|
|
|
break;
|
|
|
|
|
|
else
|
|
|
|
|
|
result.MoreParams.Add(prms);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
while (true)
|
|
|
|
|
|
{
|
|
|
|
|
|
Test tst = Test.Import(input, result);
|
|
|
|
|
|
if (tst == null)
|
|
|
|
|
|
break;
|
|
|
|
|
|
else
|
|
|
|
|
|
result.Tests.Add(tst);
|
|
|
|
|
|
}
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
}
|
2016-01-10 11:39:20 +00:00
|
|
|
|
|
2017-07-14 14:28:18 +00:00
|
|
|
|
public virtual string Compare(StreamReader inp)
|
|
|
|
|
|
{
|
|
|
|
|
|
System.Text.StringBuilder diff = new System.Text.StringBuilder();
|
|
|
|
|
|
const string fmt = "{0} = {1}\r\n (in the file {2})\r\n";
|
|
|
|
|
|
string ln;
|
|
|
|
|
|
|
|
|
|
|
|
ln = inp.ReadLine(); /// skip ItemNr
|
|
|
|
|
|
ln = inp.ReadLine(); if (ln != Name) { diff.AppendFormat(fmt, "Name", Name, ln); };
|
|
|
|
|
|
ln = inp.ReadLine(); if (ln != Description) { diff.AppendFormat(fmt, "Description", Description, ln); };
|
|
|
|
|
|
ln = inp.ReadLine(); /// skip CreationUser
|
|
|
|
|
|
ln = inp.ReadLine(); /// skip CreationTime
|
|
|
|
|
|
ln = inp.ReadLine(); /// skip LastChgUser
|
|
|
|
|
|
ln = inp.ReadLine(); /// skip LastChgTime
|
|
|
|
|
|
ln = inp.ReadLine(); if (ln != MetersKind.ToString()) { diff.AppendFormat(fmt, "MetersKind", MetersKind, ln); };
|
|
|
|
|
|
ln = inp.ReadLine(); if (ln != Watermeters) { diff.AppendFormat(fmt, "Watermeters", Watermeters, ln); };
|
|
|
|
|
|
|
|
|
|
|
|
ln = inp.ReadLine(); if (ln != Protected.ToString()) { diff.AppendFormat(fmt, "Protected", Protected, ln); };
|
|
|
|
|
|
ln = inp.ReadLine(); if (ln != MustBeComplete.ToString()) { diff.AppendFormat(fmt, "MustBeComplete", MustBeComplete, ln); };
|
|
|
|
|
|
ln = inp.ReadLine(); if (ln != ManualCtrlDisabled.ToString()) { diff.AppendFormat(fmt, "ManualCtrlDisabled", ManualCtrlDisabled, ln); };
|
|
|
|
|
|
ln = inp.ReadLine(); if (ln != DataEntry) { diff.AppendFormat(fmt, "DataEntry", DataEntry, ln); };
|
|
|
|
|
|
ln = inp.ReadLine(); if (ln != ResultsPrinter) { diff.AppendFormat(fmt, "ResultsPrinter", ResultsPrinter, ln); };
|
|
|
|
|
|
ln = inp.ReadLine(); if (ln != ResultsWriter) { diff.AppendFormat(fmt, "ResultsWriter", ResultsWriter, ln); };
|
|
|
|
|
|
ln = inp.ReadLine(); if (ln != TransitionStart) { diff.AppendFormat(fmt, "TransitionStart", TransitionStart, ln); };
|
|
|
|
|
|
ln = inp.ReadLine(); if (ln != TransitionEnd) { diff.AppendFormat(fmt, "TransitionEnd", TransitionEnd, ln); };
|
|
|
|
|
|
|
|
|
|
|
|
/// TODO Compare componentprocedure-s
|
|
|
|
|
|
while (ComponentProcedure.Import(inp, null) != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//foreach (var test in Tests)
|
|
|
|
|
|
//{
|
|
|
|
|
|
// string testDiff = test.Compare(inp);
|
|
|
|
|
|
// if (testDiff.Contains(
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
//bool extraTestsInFile = true;
|
|
|
|
|
|
//while (Test.Import(inp, null) != null) { extraTestsInFile = true; }
|
|
|
|
|
|
|
|
|
|
|
|
return diff.ToString();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-05-10 11:25:46 +00:00
|
|
|
|
public virtual ComponentProcedure GetProcedureParamsEntity(string cmpntName)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var procPrms in MoreParams)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (procPrms.CmpntName == cmpntName) return procPrms;
|
|
|
|
|
|
}
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-10-15 08:03:28 +00:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Processes the selection done by the bench control panel in the main sequence.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="selection">Selection.Q1, .Q2, .Q3 or .Test</param>
|
|
|
|
|
|
/// <returns>The selected test or null</returns>
|
|
|
|
|
|
public virtual Test GetTest(string expandedTestName, out int testIx, out int repetNr)
|
|
|
|
|
|
{
|
|
|
|
|
|
for (int ix = 0; ix < Tests.Count; ix++)
|
|
|
|
|
|
{
|
|
|
|
|
|
Test test = Tests[ix];
|
|
|
|
|
|
if (test.Name.Equals(expandedTestName))
|
|
|
|
|
|
{
|
|
|
|
|
|
/// Name is not expanded => Repeats==1
|
|
|
|
|
|
testIx = ix;
|
|
|
|
|
|
repetNr = 1;
|
|
|
|
|
|
return test;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (int r = 1; r <= test.Repeats; r++)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (test.GetExpandedTestName(r).Equals(expandedTestName))
|
|
|
|
|
|
{
|
|
|
|
|
|
testIx = ix;
|
|
|
|
|
|
repetNr = r;
|
|
|
|
|
|
return test;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
testIx = 0;
|
|
|
|
|
|
repetNr = 1;
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-01-10 11:39:20 +00:00
|
|
|
|
public override string ToString()
|
|
|
|
|
|
{
|
|
|
|
|
|
return string.Format("{0}, rev.{1}", Name, Revision);
|
|
|
|
|
|
}
|
2014-07-28 07:54:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|