Files
2026-04-17 14:55:32 -04:00

192 lines
9.1 KiB
C#

using System;
using System.Collections.Generic;
using System.Globalization;
namespace DatabaseExport
{
/// <summary>
/// a custom channel is a wrapper for MMEPossibleChannels that are defined by the user rather than ISO13499
/// they have mirror tables to the actual db and let us define new channels without disrupting the existing 1so13499 db
/// </summary>
public class CustomChannel : /*BindableBase,*/ IComparable<CustomChannel>
{
public MMEPossibleChannels Channel { get; private set; }
private MMETestObjects _testObject;
public MMETestObjects TestObject
{
get => _testObject;
set { _testObject = value; if (null != Channel && null != value) { Channel.Set_Test_Object(value.Test_Object); } }
}
private MMEPositions _position;
public MMEPositions Position
{
get => _position;
set { _position = value; if (null != Channel && null != value) { Channel.Set_Position(value.Position); } }
}
private MMETransducerMainLocation _mainLocation;
public MMETransducerMainLocation MainLocation
{
get => _mainLocation;
set { _mainLocation = value; if (null != Channel && null != value) { Channel.Set_Main_Loc(value.Trans_Main_Loc); } }
}
private MMEFineLocations1 _finLoc1;
public MMEFineLocations1 FinLoc1
{
get => _finLoc1;
set { _finLoc1 = value; if (null != Channel && null != value) { Channel.Set_Fine_Loc_1(value.Fine_Loc_1); } }
}
private MMEFineLocations2 _finLoc2;
public MMEFineLocations2 FinLoc2
{
get => _finLoc2;
set { _finLoc2 = value; if (null != Channel && null != value) { Channel.Set_Fine_Loc_2(value.FINE_LOC_2); } }
}
private MMEFineLocations3 _finLoc3;
public MMEFineLocations3 FinLoc3
{
get => _finLoc3;
set { _finLoc3 = value; if (null != Channel && null != value) { Channel.Set_Fine_Loc_3(value.FINE_LOC_3); } }
}
private MMEPhysicalDimensions _physicalDimension;
public MMEPhysicalDimensions PhysicalDimension
{
get => _physicalDimension;
set { _physicalDimension = value; if (null != Channel && null != value) { Channel.Set_Physical_Dimension(value.Physical_Dimension); } }
}
private MMEDirections _direction;
public MMEDirections Direction
{
get => _direction;
set { _direction = value; if (null != Channel && null != value) { Channel.Set_Direction(value.Direction); } }
}
private MMEFilterClasses _filterClass;
public MMEFilterClasses FilterClass
{
get => _filterClass;
set { _filterClass = value; if (null != Channel && null != value) { Channel.Set_Default_Filter_Class(value.Filter_Class); } }
}
public string Text1
{
get => Channel.Text_L1;
set => Channel.SetText1(value);
}
public string Remarks
{
get => Channel.Remarks;
set => Channel.SetRemarks(value);
}
private readonly List<ISO13499FileDb.ExpiredISOFieldException> _expiredErrors = new List<ISO13499FileDb.ExpiredISOFieldException>();
public CustomChannel(MMEPossibleChannels channel, bool newChannel = true)
{
Channel = newChannel ? new MMEPossibleChannels(channel) : channel;
_direction = ISO13499FileDb.IsoDb.GetDirectionByIso(channel.Direction);
_filterClass = ISO13499FileDb.IsoDb.GetFilterClassByIso(channel.Default_Filter_Class);
_finLoc1 = ISO13499FileDb.IsoDb.GetFineLocation1ByIso(channel.Fine_Loc_1);
_finLoc2 = ISO13499FileDb.IsoDb.GetFineLocation2ByIso(channel.Fine_Loc_2);
_finLoc3 = ISO13499FileDb.IsoDb.GetFineLocation3ByIso(channel.Fine_Loc_3);
try { _mainLocation = ISO13499FileDb.IsoDb.GetMainLocationByIso(channel.Trans_Main_Loc); }
catch (ISO13499FileDb.ExpiredISOFieldException ex) { _expiredErrors.Add(ex); }
_physicalDimension = ISO13499FileDb.IsoDb.GetPhysicalDimensionByIso(channel.Physical_Dimension);
_position = ISO13499FileDb.IsoDb.GetPositionByISO(channel.Position);
_testObject = ISO13499FileDb.IsoDb.GetTestObjectByIso(channel.Test_Object);
}
public int CompareTo(CustomChannel other)
{
return Equals(this, other) ? 0 : string.Compare(Text1, other.Text1, StringComparison.Ordinal);
}
public Dictionary<string, string> GetValues()
{
var elementNameValuePairs = new Dictionary<string, string>
{
[DbOperations.MMETables.MMEPossibleChannelsFields.ID.ToString()] = Channel.Id.ToString(CultureInfo.InvariantCulture),
[DbOperations.MMETables.MMEPossibleChannelsFields.TYPE.ToString()] = Channel.Type,
[DbOperations.MMETables.MMEPossibleChannelsFields.TEST_OBJECT.ToString()] = TestObject.Test_Object,
[DbOperations.MMETables.MMEPossibleChannelsFields.POSITION.ToString()] = Position.Position,
[DbOperations.MMETables.MMEPossibleChannelsFields.TRANS_MAIN_LOC.ToString()] = MainLocation.Trans_Main_Loc,
[DbOperations.MMETables.MMEPossibleChannelsFields.FINE_LOC_1.ToString()] = FinLoc1.Fine_Loc_1,
[DbOperations.MMETables.MMEPossibleChannelsFields.FINE_LOC_2.ToString()] = FinLoc2.FINE_LOC_2,
[DbOperations.MMETables.MMEPossibleChannelsFields.FINE_LOC_3.ToString()] = FinLoc3.FINE_LOC_3,
[DbOperations.MMETables.MMEPossibleChannelsFields.PHYSICAL_DIMENSION.ToString()] = PhysicalDimension.Physical_Dimension,
[DbOperations.MMETables.MMEPossibleChannelsFields.DIRECTION.ToString()] = Direction.Direction,
[DbOperations.MMETables.MMEPossibleChannelsFields.DEFAULT_FILTER_CLASS.ToString()] = FilterClass.Filter_Class,
[DbOperations.MMETables.MMEPossibleChannelsFields.TEXT_L1.ToString()] = Text1,
[DbOperations.MMETables.MMEPossibleChannelsFields.TEXT_L2.ToString()] = Channel.Text_L2,
[DbOperations.MMETables.MMEPossibleChannelsFields.VERSION.ToString()] = Channel.Version.ToString(CultureInfo.InvariantCulture),
[DbOperations.MMETables.MMEPossibleChannelsFields.DATE.ToString()] = Channel.Date.ToString(CultureInfo.InvariantCulture),
[DbOperations.MMETables.MMEPossibleChannelsFields.REMARKS.ToString()] = Remarks,
[DbOperations.MMETables.MMEPossibleChannelsFields.EXPIRED.ToString()] = Channel.Expired.ToString(),
[DbOperations.MMETables.MMEPossibleChannelsFields.SORTKEY.ToString()] = Channel.SortKey,
[DbOperations.MMETables.MMEPossibleChannelsFields.PICTURE_SHORTNAME.ToString()] = Channel.Picture_ShortName,
[DbOperations.MMETables.MMEPossibleChannelsFields.LAST_CHANGE.ToString()] = Channel.Last_Change.ToString(CultureInfo.InvariantCulture),
[DbOperations.MMETables.MMEPossibleChannelsFields.LAST_CHANGE_TEXT.ToString()] = Channel.Last_Change_Text,
[DbOperations.MMETables.MMEPossibleChannelsFields.HISTORY.ToString()] = Channel.History
};
return elementNameValuePairs;
}
}
public class CustomChannelList
{
private static readonly object MyLock = new object();
private static CustomChannelList _list;
public static CustomChannelList List
{
get
{
lock (MyLock)
{
if (null == _list)
{
_list = new CustomChannelList();
}
}
return _list;
}
}
private List<CustomChannel> _listChannels;
public CustomChannel[] AllChannels
{
get
{
PopulateChannelsIfNecessary();
return _listChannels.ToArray();
}
}
/// <summary>
/// loads all calculated channels, if necessary
/// </summary>
private void PopulateChannelsIfNecessary()
{
lock (MyLock)
{
if (null != _listChannels) return;
_listChannels = new List<CustomChannel>();
//_dictChannels = new Dictionary<string, CustomChannel>();
foreach (var channel in ISO13499FileDb.IsoDb.GetSQLPossibleChannels())
{
var ch = new CustomChannel(channel);
//var iso = ISO.IsoCode.GetString(ch.Channel, false);
//if (_dictChannels.ContainsKey(iso)) continue;
_listChannels.Add(ch);
//_dictChannels[iso] = ch;
}
_listChannels.Sort();
}
}
}
}