183 lines
6.8 KiB
C#
183 lines
6.8 KiB
C#
using System.Text;
|
|
|
|
namespace DatabaseExport.ISO
|
|
{
|
|
public class IsoCode
|
|
{
|
|
private char[] _isoCodeFull = { '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0' };
|
|
private char _TestObject
|
|
{
|
|
get => _isoCodeFull[0];
|
|
set => _isoCodeFull[0] = value;
|
|
}
|
|
public string TestObject
|
|
{
|
|
get => new string(new[] { _TestObject });
|
|
set
|
|
{
|
|
if (string.IsNullOrEmpty(value)) { _TestObject = '?'; }
|
|
else { _TestObject = value[0]; }
|
|
}
|
|
}
|
|
|
|
private char _Position
|
|
{
|
|
get => _isoCodeFull[1];
|
|
set => _isoCodeFull[1] = value;
|
|
}
|
|
public string Position
|
|
{
|
|
get => new string(new[] { _Position });
|
|
set => _Position = string.IsNullOrEmpty(value) ? '?' : value[0];
|
|
}
|
|
|
|
private char[] _MainLocation
|
|
{
|
|
get => new[] { _isoCodeFull[2], _isoCodeFull[3], _isoCodeFull[4], _isoCodeFull[5] };
|
|
set
|
|
{
|
|
for (var i = 0; i < 4; i++)
|
|
{
|
|
if (value.Length <= i) { _isoCodeFull[i + 2] = '0'; }
|
|
else { _isoCodeFull[i + 2] = value[i]; }
|
|
}
|
|
}
|
|
}
|
|
private char[] _FineLocation1
|
|
{
|
|
get => new[] { _isoCodeFull[6], _isoCodeFull[7] };
|
|
set
|
|
{
|
|
for (var i = 0; i < 2; i++)
|
|
{
|
|
if (value.Length < i) { _isoCodeFull[i + 6] = '0'; }
|
|
else { _isoCodeFull[i + 6] = value[i]; }
|
|
}
|
|
}
|
|
}
|
|
private char[] _FineLocation2
|
|
{
|
|
get => new[] { _isoCodeFull[8], _isoCodeFull[9] };
|
|
set
|
|
{
|
|
for (var i = 0; i < 2; i++)
|
|
{
|
|
if (value.Length < i) { _isoCodeFull[i + 8] = '0'; }
|
|
else { _isoCodeFull[i + 8] = value[i]; }
|
|
}
|
|
}
|
|
}
|
|
private char[] _FineLocation3
|
|
{
|
|
get => new[] { _isoCodeFull[10], _isoCodeFull[11] };
|
|
set
|
|
{
|
|
for (var i = 0; i < 2; i++)
|
|
{
|
|
if (value.Length < i) { _isoCodeFull[i + 10] = '0'; }
|
|
else { _isoCodeFull[i + 10] = value[i]; }
|
|
}
|
|
}
|
|
}
|
|
private char[] _PhysicalDimension
|
|
{
|
|
get => new[] { _isoCodeFull[12], _isoCodeFull[13] };
|
|
set
|
|
{
|
|
for (var i = 0; i < 2; i++)
|
|
{
|
|
if (value.Length < i) { _isoCodeFull[i + 12] = '0'; }
|
|
else { _isoCodeFull[i + 12] = value[i]; }
|
|
}
|
|
}
|
|
}
|
|
private char _Direction
|
|
{
|
|
get => _isoCodeFull[14];
|
|
set => _isoCodeFull[14] = value;
|
|
}
|
|
private char _FilterClass
|
|
{
|
|
get => _isoCodeFull[15];
|
|
set => _isoCodeFull[15] = value;
|
|
}
|
|
public string FilterClass
|
|
{
|
|
get => new string(new[] { _FilterClass });
|
|
set => _FilterClass = string.IsNullOrEmpty(value) ? '?' : value[0];
|
|
}
|
|
|
|
public IsoCode(string isoCode)
|
|
{
|
|
if (null == isoCode) { isoCode = ""; }
|
|
if (isoCode.Length > 16) { isoCode = isoCode.Substring(0, 16); }
|
|
if (isoCode.Length < 16)
|
|
{
|
|
isoCode = isoCode.PadRight(16, '?');
|
|
}
|
|
for (var i = 0; i < 16; i++) { _isoCodeFull[i] = isoCode[i]; }
|
|
}
|
|
public string StringRepresentation
|
|
{
|
|
get
|
|
{
|
|
var sb = new StringBuilder();
|
|
foreach (var c in _isoCodeFull) { sb.Append(c); }
|
|
return sb.ToString();
|
|
}
|
|
set
|
|
{
|
|
for (var i = 0; i < 16; i++)
|
|
{
|
|
if (i >= value.Length) { _isoCodeFull[i] = '0'; }
|
|
else { _isoCodeFull[i] = value[i]; }
|
|
}
|
|
}
|
|
}
|
|
public static string GetString(MMEPossibleChannels channel, MMETestObjects container, MMEPositions position, MMEFilterClasses fc)
|
|
{
|
|
var iso = new IsoCode("");
|
|
iso._Direction = channel.Direction[0];
|
|
iso._FilterClass = channel.Default_Filter_Class[0];
|
|
iso._FineLocation1 = channel.Fine_Loc_1.ToCharArray();
|
|
iso._FineLocation2 = channel.Fine_Loc_2.ToCharArray();
|
|
iso._FineLocation3 = channel.Fine_Loc_3.ToCharArray();
|
|
iso._MainLocation = channel.Trans_Main_Loc.ToCharArray();
|
|
iso._PhysicalDimension = channel.Physical_Dimension.ToCharArray();
|
|
iso._Position = null == position ? '?' : position.Position[0];
|
|
iso._TestObject = null == container ? '?' : container.Test_Object[0];
|
|
iso._FilterClass = null == fc ? '?' : fc.Filter_Class[0];
|
|
return iso.StringRepresentation;
|
|
}
|
|
/// <summary>
|
|
/// returns the isocode for a channel
|
|
/// considers whether it should mask the test time fields in the isocode
|
|
/// test time fields are test object, and filterclass
|
|
/// returns isocode
|
|
/// </summary>
|
|
/// <param name="channel"></param>
|
|
/// <param name="careAboutTestTimeFields"></param>
|
|
/// <returns></returns>
|
|
public static string GetString(MMEPossibleChannels channel, bool careAboutTestTimeFields)
|
|
{
|
|
var iso = new IsoCode("")
|
|
{
|
|
_Direction = channel.Direction[0],
|
|
_FineLocation1 = channel.Fine_Loc_1.ToCharArray(),
|
|
_FineLocation2 = channel.Fine_Loc_2.ToCharArray(),
|
|
_FineLocation3 = channel.Fine_Loc_3.ToCharArray(),
|
|
_MainLocation = channel.Trans_Main_Loc.ToCharArray(),
|
|
_PhysicalDimension = channel.Physical_Dimension.ToCharArray(),
|
|
_Position = channel.Position[0],
|
|
_TestObject = careAboutTestTimeFields ? channel.Test_Object[0] : '?',
|
|
_FilterClass = careAboutTestTimeFields ? channel.Default_Filter_Class[0] : '?'
|
|
};
|
|
return iso.StringRepresentation;
|
|
}
|
|
public static string GetString(string testObject, string position, string main, string floc1, string floc2, string floc3, string physdim, string dir, string fc)
|
|
{
|
|
return string.Format("{0}{1}{2}{3}{4}{5}{6}{7}{8}", testObject, position, main, floc1, floc2, floc3, physdim, dir, fc);
|
|
}
|
|
}
|
|
}
|