145 lines
4.8 KiB
C#
145 lines
4.8 KiB
C#
///
|
|
/// Copyright (c) 2019 Sensus Slovensko a.s.
|
|
///
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Globalization;
|
|
using System.IO;
|
|
using Common;
|
|
|
|
namespace Config.Entities
|
|
{
|
|
/// <summary>
|
|
/// Stores one test procedure, supports revisions and history log
|
|
/// </summary>
|
|
public class Profile : IHasName, IHasItemNr
|
|
{
|
|
public virtual int Id { get; protected set; }
|
|
public virtual int ItemNr { get; set; }
|
|
public virtual string Name { get; set; }
|
|
public virtual string Description { get; set; } /// Short description
|
|
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 ProfileType ProfileType { get; set; }
|
|
public virtual ErrorLimitType ErrorLimitType { get; set; }
|
|
|
|
public virtual IList<PTest> Tests { get; set; }
|
|
|
|
/// ------------- Additional stuff not mapped into the database -------------
|
|
|
|
public Profile()
|
|
{
|
|
Tests = new List<PTest>();
|
|
|
|
///
|
|
/// Default values
|
|
///
|
|
CreationUser = Users.CurrentUser.UserName();
|
|
CreationTime = DateTime.Now;
|
|
LastChgUser = CreationUser;
|
|
LastChgTime = CreationTime;
|
|
Description = string.Empty;
|
|
}
|
|
|
|
public Profile(string name, int itemNr)
|
|
: this()
|
|
{
|
|
Name = name;
|
|
ItemNr = itemNr;
|
|
}
|
|
|
|
public virtual Profile Clone()
|
|
{
|
|
Profile result = new Profile();
|
|
|
|
result.ItemNr = ItemNr;
|
|
result.Name = Name;
|
|
result.Description = Description;
|
|
result.CreationUser = CreationUser;
|
|
result.CreationTime = CreationTime;
|
|
result.LastChgUser = LastChgUser;
|
|
result.LastChgTime = LastChgTime;
|
|
result.ProfileType = ProfileType;
|
|
result.ErrorLimitType = ErrorLimitType;
|
|
|
|
foreach (var test in Tests) { result.Tests.Add(test.Clone()); }
|
|
|
|
return result;
|
|
}
|
|
|
|
public virtual void Export(StreamWriter output)
|
|
{
|
|
output.WriteLine(ItemNr.ToString(CultureInfo.InvariantCulture));
|
|
output.WriteLine(Name);
|
|
output.WriteLine(Description);
|
|
output.WriteLine(CreationUser);
|
|
output.WriteLine(CreationTime.ToString(CultureInfo.InvariantCulture));
|
|
output.WriteLine(LastChgUser);
|
|
output.WriteLine(LastChgTime.ToString(CultureInfo.InvariantCulture));
|
|
|
|
foreach (var test in Tests) { test.Export(output); }
|
|
output.WriteLine();
|
|
|
|
output.Close();
|
|
}
|
|
|
|
public static Profile Import(StreamReader input)
|
|
{
|
|
Profile result = new Profile();
|
|
|
|
result.ItemNr = int.Parse(input.ReadLine(), CultureInfo.InvariantCulture);
|
|
result.Name = input.ReadLine();
|
|
result.Description = input.ReadLine();
|
|
result.CreationUser = input.ReadLine();
|
|
result.CreationTime = DateTime.Parse(input.ReadLine(), CultureInfo.InvariantCulture);
|
|
result.LastChgUser = input.ReadLine();
|
|
result.LastChgTime = DateTime.Parse(input.ReadLine(), CultureInfo.InvariantCulture);
|
|
string line = input.ReadLine();
|
|
|
|
while (true)
|
|
{
|
|
PTest tst = PTest.Import(input, result);
|
|
if (tst == null)
|
|
break;
|
|
else
|
|
result.Tests.Add(tst);
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
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
|
|
|
|
//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();
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
return string.Format("{0}", Name);
|
|
}
|
|
}
|
|
}
|