Files
DP44/DataPRO/Modules/DatabaseImporter/DatabaseImport/ISO/IsoCode.cs

146 lines
5.1 KiB
C#
Raw Normal View History

2026-04-17 14:55:32 -04:00
using System.Text;
namespace DatabaseImport.ISO
{
public class IsoCode
{
private readonly 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;
}
private char _position
{
get => _isoCodeFull[1];
set => _isoCodeFull[1] = value;
}
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++)
{
_isoCodeFull[i + 6] = value.Length < i ? '0' : 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 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]; }
}
}
}
/// <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 $"{testObject}{position}{main}{floc1}{floc2}{floc3}{physdim}{dir}{fc}";
}
}
}