Files
DP44/DataPRO/Modules/DatabaseImporter/DatabaseImport/CustomChannel.cs
2026-04-17 14:55:32 -04:00

131 lines
5.2 KiB
C#

using System;
using System.Collections.Generic;
using System.Windows;
namespace DatabaseImport
{
/// <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 : /*BasePropertyChanged,*/ IComparable<CustomChannel>
{
// #region Properties
public MMEPossibleChannels Channel { get; private set; }
private MMETestObjects _testObject;
private MMEPositions _position;
private MMETransducerMainLocation _mainLocation;
private MMEFineLocations1 _finLoc1;
private MMEFineLocations2 _finLoc2;
private MMEFineLocations3 _finLoc3;
private MMEPhysicalDimensions _physicalDimension;
private MMEDirections _direction;
private MMEFilterClasses _filterClass;
public string Text1
{
get => Channel.Text_L1;
set => Channel.SetText1(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 = ((App)Application.Current).IsoDb.GetDirectionByIso(channel.Direction);
_filterClass = ((App)Application.Current).IsoDb.GetFilterClassByIso(channel.Default_Filter_Class);
_finLoc1 = ((App)Application.Current).IsoDb.GetFineLocation1ByIso(channel.Fine_Loc_1);
_finLoc2 = ((App)Application.Current).IsoDb.GetFineLocation2ByIso(channel.Fine_Loc_2);
_finLoc3 = ((App)Application.Current).IsoDb.GetFineLocation3ByIso(channel.Fine_Loc_3);
try { _mainLocation = ((App)Application.Current).IsoDb.GetMainLocationByIso(channel.Trans_Main_Loc); }
catch (ISO13499FileDb.ExpiredISOFieldException ex) { _expiredErrors.Add(ex); }
_physicalDimension = ((App)Application.Current).IsoDb.GetPhysicalDimensionByIso(channel.Physical_Dimension);
_position = ((App)Application.Current).IsoDb.GetPositionByISO(channel.Position);
_testObject = ((App)Application.Current).IsoDb.GetTestObjectByIso(channel.Test_Object);
}
public int CompareTo(CustomChannel other)
{
return Equals(this, other) ? 0 : string.Compare(Text1, other.Text1, StringComparison.Ordinal);
}
}
public class CustomChannelList //: BasePropertyChanged
{
private static readonly object LockObject = new object();
private static CustomChannelList _list;
public static CustomChannelList List
{
get
{
lock (LockObject)
{
if (null == _list)
{
_list = new CustomChannelList();
}
}
return _list;
}
}
public void ReloadAll()
{
lock (LockObject)
{
List._listChannels = null;
var app = Application.Current as App;
if (app == null) { return; }
app.IsoDb.RefreshAllData();
List.PopulateChannelsIfNecessary();
}
}
private Dictionary<string, CustomChannel> _dictChannels;
private List<CustomChannel> _listChannels;
private void PopulateChannelsIfNecessary()
{
lock (LockObject)
{
if (null != _listChannels) return;
_listChannels = new List<CustomChannel>();
_dictChannels = new Dictionary<string, CustomChannel>();
foreach (var channel in ((App)Application.Current).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();
}
}
private static ISO13499FileDb _isoDb;
public ISO13499FileDb IsoDb
{
get
{
if (null != _isoDb) return _isoDb;
_isoDb = new ISO13499FileDb();
_isoDb.RefreshAllData();
return _isoDb;
}
}
/// <summary>
/// deletes all customchannels
/// originally created so TDM imports could clear all tables except DAS tables
/// </summary>
public void DeleteAll()
{
lock (LockObject)
{
_listChannels = null;
_dictChannels = null;
//((App)Application.Current).IsoDb.DeleteSQL();
IsoDb.DeleteSQL();
//OnPropertyChanged("AllChannels");
}
}
}
}