This commit is contained in:
2026-04-17 14:55:32 -04:00
commit bc3ac1d4c9
18017 changed files with 4371742 additions and 0 deletions

View File

@@ -0,0 +1,165 @@
using System;
namespace DatabaseExport
{
/// <summary>
/// list of all non columned test settings
/// </summary>
public enum TestSettingsEnum
{
ArmCheckListStep,
CheckListInputVoltageCheck,
CheckListBatteryVoltageCheck,
CheckListSquibResistanceCheck,
CheckListSensorIDCheck,
CheckListTriggerStartCheck,
EW,//ExcitationWarmup
CheckListMustPass
}
public enum RecordingModes
{
CircularBuffer,
Recorder,
HybridRecorder
}
public enum IsoChannelSensorCompatibilityLevels
{
DontWarn,
Warn,
DontAllow
}
[Flags]
public enum SupportedExportFormatBitFlags
{
none = 0x0,
csvunfiltered = 0x1,
diademadc = 0x2,
isounfiltered = 0x4,
somatunfiltered = 0x8,
tdmsadc = 0x10,
toyotaunfiltered = 0x20,
tsvunfiltered = 0x40,
csvfiltered = 0x80,
//diademfiltered = 0x100, //unused & available
isofiltered = 0x200,
somatfiltered = 0x400,
tdasadc = 0x800,
toyotafiltered = 0x1000,
tsvfiltered = 0x2000,
rdfadc = 0x4000,
ChryslerDDAS = 0x8000,
HDFUnfiltered = 0x10000,
HDFFiltered = 0x20000,
HDFMV = 0x40000,
HDFADC = 0x80000,
xlsxfiltered = 0x100000,
xlsxunfiltered = 0x200000
}
public enum TestTemplateTags
{
UploadData,
UploadFolder,
CommonLine,
AllCustomers,
AllTestEngineers,
AllLabs,
Test,
AllowMissingSensors,
AllowSensorIdToBlankChannel,
AutomaticProgression,
AutomaticProgressionDelayMS,
InvertTriggerCompletion,
TriggerCheckStep,
PostTestDiagnostics,
TriggerCheckRealtime,
InvertStartRecordCompletion,
ViewDiagnostics,
VerifyChannels,
AutoVerifyProgress,
AutoVerifyDelaySeconds,
TestGraphs,
GraphCount,
Name,
TestId,
SetupFile,
Description,
AvailableTestObjects,
SamplesPerSecond,
SampleRateText,
PreTriggerSeconds,
PostTriggerSeconds,
RecordingMode,
RecordingModeText,
StrictDiagnostics,
TestObjects,
AllTestObjects,
SysBuiltTestObjects,
RequireUserConfirmationOnErrors,
DoROIDownload,
ROIButtonVisibility,
ViewROIDownload,
ViewROIDownloadButtonVisibility,
DownloadAll,
DownloadAllButtonVisibility,
ViewRealtime,
ViewRealtimeButtonVisibility,
ROIStart,
ROIEnd,
ViewDownloadAll,
ViewDownloadAllButtonVisibility,
ViewExport,
ViewExportButtonVisibility,
ExportFormats,
DownloadFolder,
ExportFolder,
SameAsDownloadFolder,
TestTime,
LabDetails,
CustomerDetails,
TestEngineerDetails,
DefaultNumberRealtimeGraphs,
GraphDetailsVisibility,
CurrentGraph,
UseCustomerDetails,
UseTestEngineerDetails,
TurnOffExcitation,
UseLabratoryDetails,
TestDirectory,
OriginalTestDirectory,
LocalOnly,
LastModified,
LastMmodifiedBy,
ExpressTestSetup,
EW,
ExcitationWarmupTimeMS,
ArmCheckListStep,
CheckListBatteryVoltageCheck,
CheckListInputVoltageCheck,
CheckListSquibResistanceCheck,
CheckListSensorIDCheck,
CheckListTriggerStartCheck,
CheckListMustPass,
WarnOnFailedBattery,
HardwareOverrides,
DoAutoArm,
DoStreaming,
SysBuiltTestObjectTypes,
AddedGroupRemoved,
CheckoutMode,
QuitTestWithoutWarning,
SuppressMissingSensorsWarning,
ISFFile,
TestObjectsAndAddedGroups,
NotAllChannelsRealTime,
NotAllChannelsViewer,
GroupsStepValid
}
public enum StrictLevel
{
Strict,
UpdateTable
}
}

View File

@@ -0,0 +1,288 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace DatabaseExport
{
public class DASHardware : DbTimeStampBase, IComparable<DASHardware>
{
public override ConstraintHelper[] GetConstraints()
{
return new ConstraintHelper[]
{
new ConstraintHelper()
{
ColumnName = DbOperations.DAS.Fields.SerialNumber.ToString(),
DbType = System.Data.SqlDbType.NVarChar,
DbValue = SerialNumber
}
};
}
public override string LookupTable => "tblDAS";
public enum Tags
{
MeasuredBatteryVoltage,
MeasuredInputVoltage,
Channels,
ChannelCount,
Selected,
BackgroundColor,
SerialNumber,
DASTypeEnum,
Connection,
FirmwareVersion,
MaxModules,
ChannelTypes,
Reprogramable,
Reconfigurable,
LocalOnly
}
public int CompareTo(DASHardware right)
{
if (null == right) { return 1; }
if (this == right) { return 0; }
return SerialNumber == right.SerialNumber ? Connection.CompareTo(right.Connection) : SerialNumber.CompareTo(right.SerialNumber);
}
private List<HardwareChannel> _channels = new List<HardwareChannel>();
public HardwareChannel[] Channels
{
get => _channels.ToArray();
set
{
var channels = new List<HardwareChannel>(value);
channels.Sort();
SetProperty(ref _channels, channels, Tags.Channels.ToString());
OnPropertyChanged(Tags.ChannelCount.ToString());
}
}
public string SerialNumber
{
get => _hardware.SerialNumber;
set
{
_hardware.SerialNumber = value;
OnPropertyChanged(Tags.SerialNumber.ToString());
}
}
public int GetHardwareTypeInt() { return _hardware.DASType; }
public Hardware.HardwareTypes GetHardwareTypeEnum() { return (Hardware.HardwareTypes)GetHardwareTypeInt(); }
public string Connection
{
get => _hardware.IPAddress;
set
{
_hardware.IPAddress = value;
OnPropertyChanged(Tags.Connection.ToString());
}
}
public DateTime CalDate => _hardware.CalDate;
public long GetMaxMemoryLong() { return _hardware.MaxMemory; }
public bool LocalOnly
{
get => _hardware.LocalOnly;
set
{
_hardware.LocalOnly = value;
OnPropertyChanged(Tags.LocalOnly.ToString());
}
}
public DASHardware()
{
}
public Dictionary<string, string> GetValues()
{
var elementNameValuePairs = new Dictionary<string, string>();
var isoH = GetHardware();
elementNameValuePairs[DbOperations.DAS.Fields.SerialNumber.ToString()] = isoH.SerialNumber;
elementNameValuePairs[DbOperations.DAS.Fields.Type.ToString()] = isoH.DASType.ToString(System.Globalization.CultureInfo.InvariantCulture);
elementNameValuePairs[DbOperations.DAS.Fields.MaxModules.ToString()] = isoH.MaxModules.ToString(System.Globalization.CultureInfo.InvariantCulture);
elementNameValuePairs[DbOperations.DAS.Fields.MaxMemory.ToString()] = isoH.MaxMemory.ToString(System.Globalization.CultureInfo.InvariantCulture);
elementNameValuePairs[DbOperations.DAS.Fields.MaxSampleRate.ToString()] = isoH.MaxSampleRate.ToString(System.Globalization.CultureInfo.InvariantCulture);
elementNameValuePairs[DbOperations.DAS.Fields.MinSampleRate.ToString()] = isoH.MinSampleRate.ToString(System.Globalization.CultureInfo.InvariantCulture);
elementNameValuePairs[DbOperations.DAS.Fields.FirmwareVersion.ToString()] = isoH.FirmwareVersion;
elementNameValuePairs[DbOperations.DAS.Fields.CalDate.ToString()] = CalDate.ToString(System.Globalization.CultureInfo.InvariantCulture);
elementNameValuePairs[DbOperations.DAS.Fields.ProtocolVersion.ToString()] = isoH.ProtocolVersion.ToString(System.Globalization.CultureInfo.InvariantCulture);
elementNameValuePairs[DbOperations.DAS.Fields.LastModified.ToString()] = isoH.LastModified.ToString(System.Globalization.CultureInfo.InvariantCulture);
elementNameValuePairs[DbOperations.DAS.Fields.LastModifiedBy.ToString()] = isoH.LastModifiedBy;
elementNameValuePairs[DbOperations.DAS.Fields.Version.ToString()] = isoH.Version.ToString(System.Globalization.CultureInfo.InvariantCulture);
elementNameValuePairs[DbOperations.DAS.Fields.LocalOnly.ToString()] = isoH.LocalOnly.ToString();
elementNameValuePairs[DbOperations.DAS.Fields.LastUsed.ToString()] = isoH.LastUsed.ToString(System.Globalization.CultureInfo.InvariantCulture);
elementNameValuePairs[DbOperations.DAS.Fields.LastUsedBy.ToString()] = isoH.LastUsedBy;
elementNameValuePairs[DbOperations.DAS.Fields.Connection.ToString()] = isoH.IPAddress;
elementNameValuePairs[DbOperations.DAS.Fields.Channels.ToString()] = isoH.Channels.ToString(System.Globalization.CultureInfo.InvariantCulture);
elementNameValuePairs[DbOperations.DAS.Fields.Position.ToString()] = isoH.Position;
var channeltypes = new List<string>();
foreach (var ct in isoH.ChannelTypes) { channeltypes.Add(ct.ToString(System.Globalization.CultureInfo.InvariantCulture)); }
elementNameValuePairs[DbOperations.DAS.Fields.ChannelTypes.ToString()] = string.Join(System.Globalization.CultureInfo.InvariantCulture.TextInfo.ListSeparator, channeltypes.ToArray());
elementNameValuePairs[DbOperations.DAS.Fields.Reprogramable.ToString()] = isoH.IsProgrammable.ToString();
elementNameValuePairs[DbOperations.DAS.Fields.Reconfigurable.ToString()] = isoH.IsReconfigurable.ToString();
elementNameValuePairs[DbOperations.DAS.Fields.IsModule.ToString()] = isoH.IsModule.ToString();
return elementNameValuePairs;
}
public Dictionary<string, string> GetChannelValues(HardwareChannel channel)
{
var elementNameValuePairs = new Dictionary<string, string>();
var isoH = GetHardware();
var isoChannel = channel.GetISOChannel();
elementNameValuePairs[DbOperations.DAS.DASChannelFields.HardwareId.ToString()] = isoH.GetId();
elementNameValuePairs[DbOperations.DAS.DASChannelFields.ChannelIdx.ToString()] = isoChannel.ChannelIdx.ToString(System.Globalization.CultureInfo.InvariantCulture);
elementNameValuePairs[DbOperations.DAS.DASChannelFields.SupportedBridges.ToString()] = isoChannel.SupportedBridges.ToString(System.Globalization.CultureInfo.InvariantCulture);
elementNameValuePairs[DbOperations.DAS.DASChannelFields.SupportedExcitations.ToString()] = isoChannel.SupportedExcitations.ToString(System.Globalization.CultureInfo.InvariantCulture);
elementNameValuePairs[DbOperations.DAS.DASChannelFields.DASDisplayOrder.ToString()] = isoChannel.DASDisplayOrder.ToString(System.Globalization.CultureInfo.InvariantCulture);
elementNameValuePairs[DbOperations.DAS.DASChannelFields.LocalOnly.ToString()] = isoChannel.LocalOnly.ToString();
elementNameValuePairs[DbOperations.DAS.DASChannelFields.SupportedDigitalInputModes.ToString()] = isoChannel.SupportedDigitalInputModes.ToString(System.Globalization.CultureInfo.InvariantCulture);
elementNameValuePairs[DbOperations.DAS.DASChannelFields.SupportedSquibFireModes.ToString()] = isoChannel.SupportedSquibFireModes.ToString(System.Globalization.CultureInfo.InvariantCulture);
elementNameValuePairs[DbOperations.DAS.DASChannelFields.SupportedDigitalOutputModes.ToString()] = isoChannel.SupportedDigitalOutputModes.ToString(System.Globalization.CultureInfo.InvariantCulture);
elementNameValuePairs[DbOperations.DAS.DASChannelFields.ModuleSerialNumber.ToString()] = isoChannel.ModuleSerialNumber;
elementNameValuePairs[DbOperations.DAS.DASChannelFields.ModuleArrayIndex.ToString()] = isoChannel.ModuleArrayIndex.ToString(System.Globalization.CultureInfo.InvariantCulture);
return elementNameValuePairs;
}
public DASHardware(DASHardware copy, DASHardware parentDAS)
{
if (null != copy.Channels)
{
var channels = new List<HardwareChannel>();
foreach (var ch in copy.Channels) { channels.Add(new HardwareChannel(ch)); }
Channels = channels.ToArray();
}
_hardware = new Hardware(copy.GetHardware());
DbTimeStamp = copy.DbTimeStamp;
}
private Hardware _hardware = new Hardware();
public Hardware GetHardware() { return _hardware; }
/// <summary>
/// note that if you use this constructor, you should set
/// TimeStampDb explicitly
/// </summary>
/// <param name="hardware"></param>
public DASHardware(Hardware hardware)
{
_hardware = new Hardware(hardware);
_hardware.IPAddress = Connection;
var channels = new List<HardwareChannel>();
foreach (var channel in hardware.ISOChannels)
{
channels.Add(new HardwareChannel(channel, this));
}
Channels = channels.ToArray();
}
public bool IsDummy()
{
return SerialNumber.Contains("Dummy");
}
}
public class DASHardwareList //: Common.BindableBase
{
private static DASHardwareList _list;
public static DASHardwareList GetList()
{
if (null == _list)
{
_list = new DASHardwareList();
_list.PopulateHardware();
}
return _list;
}
public DASHardware GetHardware(string id)
{
bool bNotUsed;
return GetHardware(id, true, out bNotUsed);
}
public DASHardware GetHardware(string id, bool bThrowExceptionIfChanged, out bool changed)
{
changed = false;
if (_hardware.ContainsKey(id)) { return _hardware[id]; }
else
{
var matchingSerial = from h in _hardware where h.Value.SerialNumber == id select h.Value;
if (matchingSerial.Count() > 0) { return matchingSerial.First(); }
else
{
//check to see if the type changed?
var index = id.IndexOf('_');
if (index >= 0)
{
id = id.Substring(0, index);
}
var match2 = from h in _hardware where h.Value.SerialNumber == id select h.Value;
if (match2.Count() > 0)
{
if (bThrowExceptionIfChanged)
{
throw new HardwareTypeChangedException();
}
else
{
changed = true;
}
}
return null;
}
}
}
public class HardwareTypeChangedException : Exception
{
public HardwareTypeChangedException() { }
}
private DASHardware[] GetAllHardware()
{
var hardware = new List<DASHardware>();
var temp = new DASHardware();
var allTimeStamps = temp.GetAllTimeStampDb();
foreach (var hw in DatabaseExport.Hardware.GetAllDAS())
{
if (hw.Position == "Prototype" /*DbOperations.DAS.PROTOTYPE_POSITION*/) { continue; } //fix this
else
{
var newH = new DASHardware(hw);
newH.SetTimeStampMemory(newH.GetTimeStampDb(allTimeStamps));
hardware.Add(newH);
}
}
return hardware.ToArray();
}
private Dictionary<string, DASHardware> _hardware = null;
public DASHardware[] Hardware
{
get
{
if (null == _hardware)
{
PopulateHardware();
}
return _hardware.Values.ToArray();
}
}
private void PopulateHardware()
{
_hardware = new Dictionary<string, DASHardware>();
foreach (var h in GetAllHardware())
{
if (!_hardware.ContainsKey(h.GetHardware().GetId())) { _hardware.Add(h.GetHardware().GetId(), h); }
else { _hardware[h.GetHardware().GetId()] = h; }
}
}
}
}

View File

@@ -0,0 +1,33 @@
namespace DatabaseExport
{
/// <summary>
/// this is a class for holding das specific settings in a test, for example sample rate or aaf
/// it is serialized into tblTestSetupDASSettings
/// </summary>
public class DASSettings //: Common.BindableBase
{
public string DASSerialNumber { get; set; }
public double SampleRate { get; set; }
public int ExcitationWarmupTimeMS { get; set; }
public double HardwareAAF { get; set; }
public double PreTriggerSeconds { get; set; }
public double PostTriggerSeconds { get; set; }
public bool StatusLineCheck { get; set; }
public bool BatteryCheck { get; set; }
public double InputVoltageMin { get; set; }
public double InputVoltageMax { get; set; }
public double BatteryVoltageMin { get; set; }
public double BatteryVoltageMax { get; set; }
}
}

View File

@@ -0,0 +1,47 @@
namespace DatabaseExport
{
public class HardwareChannel : System.IComparable<HardwareChannel> //: Common.BindableBase, System.IComparable<HardwareChannel>
{
private readonly ISOHardwareChannel _isoChannel;
public ISOHardwareChannel GetISOChannel() { return _isoChannel; }
public int CompareTo(HardwareChannel right)
{
if (this == right) { return 0; }
if (null == right) { return 0; }
var order = GetISOChannel().DASDisplayOrder.CompareTo(right.GetISOChannel().DASDisplayOrder);
if (0 != order) { return order; }
return GetISOChannel().ChannelIdx.CompareTo(right.GetISOChannel().ChannelIdx);
}
public string GetId()
{
return string.Format("{0}x{1}", Hardware.GetHardware().GetId(), 1 + ChannelNumber);
}
public TestObjectChannel TestObjectChannel { get; set; }
public HardwareChannel(HardwareChannel copy)
{
ChannelNumber = copy.ChannelNumber;
if (null != copy.Sensor) { Sensor = new SensorData(copy.Sensor); }
TestObjectChannel = copy.TestObjectChannel;
Hardware = copy.Hardware;
_isoChannel = copy._isoChannel;
}
public HardwareChannel(ISOHardwareChannel channel, DASHardware hardware)
{
ChannelNumber = channel.ChannelIdx;
Hardware = hardware;
_isoChannel = channel;
}
public DASHardware Hardware { get; }
public int ChannelNumber { get; } = 0;
public SensorData Sensor { get; set; } = null;
public bool IsSupportedBridgeType(Test.Module.Channel.Sensor.BridgeType bridgeType)
{
return (GetISOChannel().SupportedBridges & (int)bridgeType) == (int)bridgeType;
}
}
}

View File

@@ -0,0 +1,581 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
namespace DatabaseExport
{
public class Region
{
private TestObjectTemplate _template;
public TestObjectTemplate Template
{
get => _template;
set
{
_template = value;
DetermineAvailableISOSettings();
}
}
private void InvalidateVisual()
{
_adorner?.InvalidateVisual();
}
private string _name;
public string RegionName
{
get => _name;
set { _name = value; InvalidateVisual(); }
}
private string _regionDescription;
public string RegionDescription
{
get => _regionDescription;
set { _regionDescription = value; InvalidateVisual(); }
}
public Point RegionUpperLeft { get; set; }
public Point RegionBottomRight { get; set; }
private MMEDirections _direction;
public MMEDirections RegionDirection
{
get => _direction;
set
{
_direction = value;
SetISOCode();
}
}
private MMEFilterClasses _filterClass;
public MMEFilterClasses RegionFilterClass
{
get => _filterClass;
set
{
_filterClass = value;
if (null != value)
{
_filterClassIndex = _filterClasses.IndexOf(value);
}
else
{
_filterClassIndex = -1;
}
SetISOCode();
}
}
private MMEFineLocations1 _fineLocation1;
public MMEFineLocations1 RegionFineLocation1
{
get => _fineLocation1;
set
{
_fineLocation1 = value;
SetISOCode();
}
}
private MMEFineLocations2 _fineLocation2;
public MMEFineLocations2 RegionFineLocation2
{
get => _fineLocation2;
set
{
_fineLocation2 = value;
SetISOCode();
}
}
private MMEFineLocations3 _fineLocation3;
public MMEFineLocations3 RegionFineLocation3
{
get => _fineLocation3;
set
{
_fineLocation3 = value;
SetISOCode();
}
}
private MMETransducerMainLocation _mainLocation;
public MMETransducerMainLocation RegionMainLocation
{
get => _mainLocation;
set
{
if (_mainLocation != value)
{
_mainLocation = value;
SetISOCode();
}
}
}
private void FilterRegionChannels()
{
_regionChannels = new List<TestObjectTemplateChannel>(Template.TemplateAllChannels);
_regionUIChannels = new List<TemplateChannelUI>(Template.TemplateAllUIChannels);
for (var i = _regionChannels.Count - 1; i >= 0; i--)
{
var channel = _regionChannels[i];
var mmeChannel = channel.Channel;
if (RegionMainLocation != null && RegionMainLocation.Trans_Main_Loc != mmeChannel.Trans_Main_Loc)
{
_regionChannels.RemoveAt(i);
_regionUIChannels.RemoveAt(i);
continue;
}
if (RegionDirection != null && RegionDirection.Direction != mmeChannel.Direction && RegionDirection.Direction != "?")
{
_regionChannels.RemoveAt(i);
_regionUIChannels.RemoveAt(i);
continue;
}
if (RegionFilterClass != null && RegionFilterClass.Filter_Class != mmeChannel.Default_Filter_Class && RegionFilterClass.Filter_Class != "?")
{
_regionChannels.RemoveAt(i);
_regionUIChannels.RemoveAt(i);
continue;
}
if (RegionFineLocation1 != null && RegionFineLocation1.Fine_Loc_1 != mmeChannel.Fine_Loc_1 && RegionFineLocation1.Fine_Loc_1 != "??")
{
_regionChannels.RemoveAt(i);
_regionUIChannels.RemoveAt(i);
continue;
}
if (RegionFineLocation2 != null && RegionFineLocation2.FINE_LOC_2 != mmeChannel.Fine_Loc_2 && RegionFineLocation2.FINE_LOC_2 != "??")
{
_regionChannels.RemoveAt(i);
_regionUIChannels.RemoveAt(i);
continue;
}
if (RegionFineLocation3 != null && RegionFineLocation3.FINE_LOC_3 != mmeChannel.Fine_Loc_3 && RegionFineLocation3.FINE_LOC_3 != "??")
{
_regionChannels.RemoveAt(i);
_regionUIChannels.RemoveAt(i);
continue;
}
if (RegionPhysicalDimension != null && RegionPhysicalDimension.Physical_Dimension != mmeChannel.Physical_Dimension && RegionPhysicalDimension.Physical_Dimension != "??")
{
_regionChannels.RemoveAt(i);
_regionUIChannels.RemoveAt(i);
continue;
}
if (RegionPosition != null && RegionPosition.Position != mmeChannel.Position && RegionPosition.Position != "?")
{
_regionChannels.RemoveAt(i);
_regionUIChannels.RemoveAt(i);
continue;
}
}
RegionChannels = _regionChannels.ToArray();
RegionUIChannels = _regionUIChannels.ToArray();
SetISOCode();
}
private MMEPhysicalDimensions _physicalDimension;
public MMEPhysicalDimensions RegionPhysicalDimension
{
get => _physicalDimension;
set
{
_physicalDimension = value;
SetISOCode();
}
}
private MMEPositions _position;
public MMEPositions RegionPosition
{
get => _position;
set
{
_position = value;
SetISOCode();
}
}
public MMETestObjects RegionTestObject { get; set; }
private readonly RegionAdorner _adorner;
public Region(RegionAdorner adorner, TestObjectTemplate template)
{
_adorner = adorner;
RegionName = "New region";
RegionDescription = "Describe region";
Template = template;
RegionTestObject = template.TestObject;
RegionChannels = template.TemplateAllChannels;
RegionUIChannels = template.TemplateAllUIChannels;
DetermineAvailableISOSettings();
}
public Region(TestObjectTemplate template, TemplateRegion r)
{
RegionName = r.RegionName;
RegionDescription = r.RegionDescription;
Template = template;
RegionChannels = template.TemplateAllChannels;
RegionUIChannels = template.TemplateAllUIChannels;
RegionTestObject = ISO13499FileDb.IsoDb.GetTestObjectByIso(r.TestObject);
RegionBottomRight = new Point(r.LowerRight.X, r.LowerRight.Y);
RegionUpperLeft = new Point(r.UpperLeft.X, r.UpperLeft.Y);
RegionDirection = ISO13499FileDb.IsoDb.GetDirectionByIso(r.Direction);
RegionFilterClass = ISO13499FileDb.IsoDb.GetFilterClassByIso(r.FilterClass);
RegionFineLocation1 = ISO13499FileDb.IsoDb.GetFineLocation1ByIso(r.FineLocation1);
RegionFineLocation2 = ISO13499FileDb.IsoDb.GetFineLocation2ByIso(r.FineLocation2);
RegionFineLocation3 = ISO13499FileDb.IsoDb.GetFineLocation3ByIso(r.FineLocation3);
RegionMainLocation = ISO13499FileDb.IsoDb.GetMainLocationByIso(r.MainLocation);
RegionPhysicalDimension = ISO13499FileDb.IsoDb.GetPhysicalDimensionByIso(r.PhysicalDimension);
RegionPosition = ISO13499FileDb.IsoDb.GetPosition(r.Position);
FilterRegionChannels();
SetISOCode();
}
public Visibility RegionAddVisibility { get; set; } = Visibility.Visible;
public Visibility RegionDeleteVisibility { get; set; } = Visibility.Hidden;
private List<MMEDirections> _allDirections = new List<MMEDirections>();
public MMEDirections[] AllDirections
{
get => _allDirections.ToArray();
set
{
_allDirections = new List<MMEDirections>(value);
var directions = new List<string>();
foreach (var dir in _allDirections)
{
if (null == dir) { directions.Add("?"); }
else { directions.Add(dir.Text_L1); }
}
AllDirectionsStrings = directions.ToArray();
}
}
private List<string> _allDirectionsStrings = new List<string>();
public string[] AllDirectionsStrings
{
get => _allDirectionsStrings.ToArray();
set => _allDirectionsStrings = new List<String>(value);
}
private List<MMEFilterClasses> _filterClasses = new List<MMEFilterClasses>();
public MMEFilterClasses[] AllFilterClasses
{
get => _filterClasses.ToArray();
set
{
_filterClasses = new List<MMEFilterClasses>(value);
var filterclasses = new List<string>();
foreach (var fc in _filterClasses) { filterclasses.Add(fc.Text_L1); }
AllFilterClassStrings = filterclasses.ToArray();
}
}
private List<string> _allFilterClassStrings = new List<string>();
public string[] AllFilterClassStrings
{
get => _allFilterClassStrings.ToArray();
set => _allFilterClassStrings = new List<string>(value);
}
public int _filterClassIndex = -1;
private List<MMEFineLocations1> _fineLocations1 = new List<MMEFineLocations1>();
public MMEFineLocations1[] AllFineLocations1
{
get => _fineLocations1.ToArray();
set
{
_fineLocations1 = new List<MMEFineLocations1>(value);
var fineLocations1 = new List<string>();
foreach (var loc in _fineLocations1)
{
fineLocations1.Add(null == loc ? "??" : loc.Text_L1);
}
AllFineLocations1Strings = fineLocations1.ToArray();
}
}
private List<string> _allFineLocations1Strings = new List<string>();
public string[] AllFineLocations1Strings
{
get => _allFineLocations1Strings.ToArray();
set => _allFineLocations1Strings = new List<string>(value);
}
private List<MMEFineLocations2> _fineLocations2 = new List<MMEFineLocations2>();
public MMEFineLocations2[] AllFineLocations2
{
get => _fineLocations2.ToArray();
set
{
_fineLocations2 = new List<MMEFineLocations2>(value);
var locations = new List<string>();
foreach (var loc in _fineLocations2) { locations.Add(loc.Text_L1); }
AllFineLocations2Strings = locations.ToArray();
}
}
private List<string> _allFineLocations2Strings = new List<string>();
public string[] AllFineLocations2Strings
{
get => _allFineLocations2Strings.ToArray();
set => _allFineLocations2Strings = new List<string>(value);
}
private List<MMEFineLocations3> _fineLocations3 = new List<MMEFineLocations3>();
public MMEFineLocations3[] AllFineLocations3
{
get => _fineLocations3.ToArray();
set
{
_fineLocations3 = new List<MMEFineLocations3>(value);
var locations = new List<string>();
foreach (var l in _fineLocations3) { locations.Add(l.Text_L1); }
AllFineLocations3Strings = locations.ToArray();
}
}
private List<string> _allFineLocations3Strings = new List<string>();
public string[] AllFineLocations3Strings
{
get => _allFineLocations3Strings.ToArray();
set => _allFineLocations3Strings = new List<String>(value);
}
private List<MMETransducerMainLocation> _mainLocations = new List<MMETransducerMainLocation>();
public MMETransducerMainLocation[] AllMainLocations
{
get => _mainLocations.ToArray();
set
{
_mainLocations = new List<MMETransducerMainLocation>(value);
var locations = new List<string>();
foreach (var loc in _mainLocations)
{
if (null == loc)
{
locations.Add("????");
}
else { locations.Add(loc.Text_L1); }
}
AllMainLocationsStrings = locations.ToArray();
}
}
private List<String> _allMainLocationsStrings = new List<string>();
public string[] AllMainLocationsStrings
{
get => _allMainLocationsStrings.ToArray();
set => _allMainLocationsStrings = new List<string>(value);
}
private List<MMEPhysicalDimensions> _physicalDimensions = new List<MMEPhysicalDimensions>();
public MMEPhysicalDimensions[] AllPhysicalDimensions
{
get => _physicalDimensions.ToArray();
set
{
_physicalDimensions = new List<MMEPhysicalDimensions>(value);
var dimensions = new List<string>();
foreach (var dim in _physicalDimensions)
{
if (null == dim) { dimensions.Add("??"); }
else { dimensions.Add(dim.Text_L1); }
}
AllPhysicalDimensionStrings = dimensions.ToArray();
}
}
private List<string> _allPhysicalDimensionStrings = new List<string>();
public string[] AllPhysicalDimensionStrings
{
get => _allPhysicalDimensionStrings.ToArray();
set => _allPhysicalDimensionStrings = new List<String>(value);
}
private List<MMEPositions> _positions = new List<MMEPositions>();
public MMEPositions[] AllPositions
{
get => _positions.ToArray();
set
{
_positions = new List<MMEPositions>(value);
var positions = new List<string>();
foreach (var pos in _positions) { positions.Add(pos.Text_L1); }
AllPositionStrings = positions.ToArray();
}
}
private List<string> _allPositionsStrings = new List<string>();
public string[] AllPositionStrings
{
get => _allPositionsStrings.ToArray();
set => _allPositionsStrings = new List<string>(value);
}
public string ISOCode { get; set; } = "????????????????";
private void SetISOCode()
{
var testObject = "?";
if (null != RegionTestObject) { testObject = RegionTestObject.Test_Object; }
var position = "?";
if (null != RegionPosition) { position = RegionPosition.Position; }
var main = "????";
if (null != RegionMainLocation) { main = RegionMainLocation.Trans_Main_Loc; }
var floc1 = "??";
if (null != RegionFineLocation1) { floc1 = RegionFineLocation1.Fine_Loc_1; }
var floc2 = "??";
if (null != RegionFineLocation2) { floc2 = RegionFineLocation2.FINE_LOC_2; }
var floc3 = "??";
if (null != RegionFineLocation3) { floc3 = RegionFineLocation3.FINE_LOC_3; }
var physdim = "??";
if (null != RegionPhysicalDimension) { physdim = RegionPhysicalDimension.Physical_Dimension; }
var dir = "?";
if (null != RegionDirection) { dir = RegionDirection.Direction; }
var fc = "?";
if (null != RegionFilterClass) { fc = RegionFilterClass.Filter_Class; }
ISOCode = ISO.IsoCode.GetString(testObject, position, main, floc1, floc2, floc3, physdim, dir, fc);
}
private List<TestObjectTemplateChannel> _regionChannels = new List<TestObjectTemplateChannel>();
public TestObjectTemplateChannel[] RegionChannels
{
get => _regionChannels.ToArray();
set
{
_regionChannels = new List<TestObjectTemplateChannel>(value);
DetermineAvailableISOSettings();
}
}
private void DetermineAvailableISOSettings()
{
var regionChannels = RegionChannels;
var templateChannels = Template.TemplateAllChannels;
var testObjects = (from pc in regionChannels.AsParallel() select pc.Channel.Test_Object).Distinct().ToArray();
if (testObjects.Length < 1) { return; }
RegionTestObject = ISO13499FileDb.IsoDb.GetTestObjectByIso(testObjects[0]);
var dirs = new List<string>((from pc in templateChannels.AsParallel() select pc.Channel.Direction).Distinct().ToArray());
dirs.Sort();
var directions = new List<MMEDirections>();
foreach (var dir in dirs) { directions.Add(ISO13499FileDb.IsoDb.GetDirectionByIso(dir)); }
var d = ISO13499FileDb.IsoDb.GetDirectionByIso("?");
if (!directions.Contains(d)) { directions.Add(d); }
AllDirections = directions.ToArray();
dirs = new List<string>((from pc in regionChannels.AsParallel() select pc.Channel.Direction).Distinct().ToArray());
if (1 == dirs.Count) { RegionDirection = (ISO13499FileDb.IsoDb.GetDirectionByIso(dirs[0])); }
else if (0 == dirs.Count) { RegionDirection = null; }
var fcs = new List<string>((from pc in templateChannels.AsParallel() select pc.Channel.Default_Filter_Class).Distinct().ToArray());
fcs.Sort();
var filterclasses = new List<MMEFilterClasses>();
foreach (var fc in fcs) { filterclasses.Add(ISO13499FileDb.IsoDb.GetFilterClassByIso(fc)); }
var fc2 = ISO13499FileDb.IsoDb.GetFilterClassByIso("?");
if (!filterclasses.Contains(fc2)) { filterclasses.Add(fc2); }
AllFilterClasses = filterclasses.ToArray();
fcs = new List<string>((from pc in regionChannels.AsParallel() select pc.Channel.Default_Filter_Class).Distinct().ToArray());
if (1 == fcs.Count) { RegionFilterClass = (ISO13499FileDb.IsoDb.GetFilterClassByIso(fcs[0])); }
else if (0 == fcs.Count) { RegionFilterClass = null; }
var locs = new List<string>((from pc in templateChannels.AsParallel() select pc.Channel.Fine_Loc_1).Distinct().ToArray());
locs.Sort();
var finelocations1 = new List<MMEFineLocations1>();
foreach (var loc in locs) { finelocations1.Add(ISO13499FileDb.IsoDb.GetFineLocation1ByIso(loc)); }
var f = ISO13499FileDb.IsoDb.GetFineLocation1ByIso("??");
if (!finelocations1.Contains(f)) { finelocations1.Add(f); }
AllFineLocations1 = finelocations1.ToArray();
locs = new List<string>((from pc in regionChannels.AsParallel() select pc.Channel.Fine_Loc_1).Distinct().ToArray());
if (1 == locs.Count) { RegionFineLocation1 = (ISO13499FileDb.IsoDb.GetFineLocation1ByIso(locs[0])); }
else if (0 == locs.Count) { RegionFineLocation1 = null; }
locs = new List<string>((from pc in templateChannels.AsParallel() select pc.Channel.Fine_Loc_2).Distinct().ToArray());
locs.Sort();
var finelocations2 = new List<MMEFineLocations2>();
foreach (var loc in locs) { finelocations2.Add(ISO13499FileDb.IsoDb.GetFineLocation2ByIso(loc)); }
AllFineLocations2 = finelocations2.ToArray();
var f2 = ISO13499FileDb.IsoDb.GetFineLocation2ByIso("??");
if (!finelocations2.Contains(f2)) { finelocations2.Add(f2); }
locs = new List<string>((from pc in regionChannels.AsParallel() select pc.Channel.Fine_Loc_2).Distinct().ToArray());
if (1 == locs.Count) { RegionFineLocation2 = (ISO13499FileDb.IsoDb.GetFineLocation2ByIso(locs[0])); }
else if (0 == locs.Count) { RegionFineLocation2 = null; }
locs = new List<string>((from pc in templateChannels.AsParallel() select pc.Channel.Fine_Loc_3).Distinct().ToArray());
locs.Sort();
var finelocations3 = new List<MMEFineLocations3>();
foreach (var loc in locs) { finelocations3.Add(ISO13499FileDb.IsoDb.GetFineLocation3ByIso(loc)); }
var f3 = ISO13499FileDb.IsoDb.GetFineLocation3ByIso("??");
if (!finelocations3.Contains(f3)) { finelocations3.Add(f3); }
AllFineLocations3 = finelocations3.ToArray();
locs = new List<string>((from pc in regionChannels.AsParallel() select pc.Channel.Fine_Loc_3).Distinct().ToArray());
if (1 == locs.Count) { RegionFineLocation3 = (ISO13499FileDb.IsoDb.GetFineLocation3ByIso(locs[0])); }
else if (0 == locs.Count) { RegionFineLocation3 = null; }
locs = new List<string>((from pc in templateChannels.AsParallel() select pc.Channel.Trans_Main_Loc).Distinct().ToArray());
locs.Sort();
var mains = new List<MMETransducerMainLocation>();
foreach (var loc in locs) { mains.Add(ISO13499FileDb.IsoDb.GetMainLocationByIso(loc)); }
var m = ISO13499FileDb.IsoDb.GetMainLocationByIso("????");
if (!mains.Contains(m)) { mains.Add(m); }
AllMainLocations = mains.ToArray();
locs = new List<string>((from pc in regionChannels.AsParallel() select pc.Channel.Trans_Main_Loc).Distinct().ToArray());
if (1 == locs.Count) { RegionMainLocation = (ISO13499FileDb.IsoDb.GetMainLocationByIso(locs[0])); }
else if (0 == locs.Count) { RegionMainLocation = null; }
var dims = new List<string>((from pc in templateChannels.AsParallel() select pc.Channel.Physical_Dimension).Distinct().ToArray());
dims.Sort();
var dimensions = new List<MMEPhysicalDimensions>();
foreach (var dim in dims) { dimensions.Add(ISO13499FileDb.IsoDb.GetPhysicalDimensionByIso(dim)); }
var pd = ISO13499FileDb.IsoDb.GetPhysicalDimensionByIso("??");
if (!dimensions.Contains(pd)) { dimensions.Add(pd); }
AllPhysicalDimensions = dimensions.ToArray();
dims = new List<string>((from pc in regionChannels.AsParallel() select pc.Channel.Physical_Dimension).Distinct().ToArray());
if (1 == dims.Count) { RegionPhysicalDimension = (ISO13499FileDb.IsoDb.GetPhysicalDimensionByIso(dims[0])); }
else if (0 == dims.Count) { RegionPhysicalDimension = null; }
var poss = new List<string>((from pc in templateChannels.AsParallel() select pc.Channel.Position).Distinct().ToArray());
poss.Sort();
var positions = new List<MMEPositions>();
foreach (var pos in poss) { positions.Add(ISO13499FileDb.IsoDb.GetPositionByISO(pos)); }
AllPositions = positions.ToArray();
poss = new List<string>((from pc in regionChannels.AsParallel() select pc.Channel.Position).Distinct().ToArray());
if (1 == poss.Count) { RegionPosition = positions[0]; }
else if (0 == poss.Count) { RegionPosition = null; }
}
public TemplateRegion ToISORegion(TestObjectTemplate template, Zone zone, int number)
{
var region = new TemplateRegion(template.TemplateName, zone.Name, template.IsLocalOnly);
region.Direction = null == RegionDirection ? "?" : RegionDirection.Direction;
region.FilterClass = null == RegionFilterClass ? "?" : RegionFilterClass.Filter_Class;
region.FineLocation1 = null == RegionFineLocation1 ? "??" : RegionFineLocation1.Fine_Loc_1;
region.FineLocation2 = null == RegionFineLocation2 ? "??" : RegionFineLocation2.FINE_LOC_2;
region.FineLocation3 = null == RegionFineLocation3 ? "??" : RegionFineLocation3.FINE_LOC_3;
region.LowerRight = new System.Drawing.Point(Convert.ToInt32(RegionBottomRight.X), Convert.ToInt32(RegionBottomRight.Y));
region.MainLocation = null == RegionMainLocation ? "????" : RegionMainLocation.Trans_Main_Loc;
region.PhysicalDimension = null == RegionPhysicalDimension ? "??" : RegionPhysicalDimension.Physical_Dimension;
region.Position = null == RegionPosition ? "?" : RegionPosition.Position;
region.RegionDescription = RegionDescription;
region.RegionName = RegionName;
region.RegionNumber = number;
region.TestObject = null == RegionTestObject ? "?" : RegionTestObject.Test_Object;
region.UpperLeft = new System.Drawing.Point(Convert.ToInt32(RegionUpperLeft.X), Convert.ToInt32(RegionUpperLeft.Y));
return region;
}
private List<TemplateChannelUI> _regionUIChannels = new List<TemplateChannelUI>();
public TemplateChannelUI[] RegionUIChannels
{
get => _regionUIChannels.ToArray();
set => _regionUIChannels = new List<TemplateChannelUI>(value);
}
}
}

View File

@@ -0,0 +1,186 @@
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Shapes;
namespace DatabaseExport
{
public class RegionAdorner : Adorner
{
public Point GetUpperLeft()
{
var p = SelectRect.TopLeft;
var i = AdornedElement as Image;
var s = new Size(i.Source.Width, i.Source.Height);
var difX = (s.Width - _MeasuredSize.Width);
var difY = s.Height - _MeasuredSize.Height;
var scaleX = difX / _MeasuredSize.Width;
var scaleY = difY / _MeasuredSize.Height;
p = new Point(p.X + p.X * scaleX, p.Y + p.Y * scaleY);
return p;
}
public Point GetLowerRight()
{
var p = SelectRect.BottomRight;
var i = AdornedElement as Image;
if (null == i.Source) { return new Point(0, 0); }
var s = new Size(i.Source.Width, i.Source.Height);
var difX = (s.Width - _MeasuredSize.Width);
var difY = s.Height - _MeasuredSize.Height;
var scaleX = difX / _MeasuredSize.Width;
var scaleY = difY / _MeasuredSize.Height;
p = new Point(p.X + p.X * scaleX, p.Y + p.Y * scaleY);
return p;
}
public delegate void RegionSelectedHandler(RegionAdorner r, MouseButtonEventArgs e);
public event RegionSelectedHandler OnRegionSelected;
private bool _bNew = true;
public bool IsNew
{
get => _bNew;
set
{
_bNew = value;
if (_bNew)
{
MyRegion.RegionAddVisibility = Visibility.Visible;
MyRegion.RegionDeleteVisibility = Visibility.Hidden;
}
else
{
MyRegion.RegionDeleteVisibility = Visibility.Visible;
MyRegion.RegionAddVisibility = Visibility.Hidden;
}
}
}
private Point __anchorPoint;
public Point AnchorPoint
{
get => __anchorPoint;
set => __anchorPoint = value;
}
private UIElement _adornedElement;
private Path _path;
private Rect __selectRect;
public Rect SelectRect
{
get => __selectRect;
set
{
__selectRect = value;
MyRegion.RegionUpperLeft = GetUpperLeft();
MyRegion.RegionBottomRight = GetLowerRight();
}
}
private RectangleGeometry _geometry;
private Region _region;
public Region MyRegion
{
get => _region;
set => _region = value;
}
public RegionAdorner(UIElement adornedElement, TestObjectTemplate template, Contexts context)
: base(adornedElement)
{
_region = new Region(this, template);
_adornedElement = adornedElement;
SelectRect = new Rect();
_geometry = new RectangleGeometry();
_path = new Path();
_path.Data = _geometry;
_path.StrokeThickness = 5;
_path.Stroke = Brushes.AliceBlue;
_path.Opacity = .6;
_path.Visibility = Visibility.Hidden;
MouseLeftButtonUp += new MouseButtonEventHandler(Region_MouseLeftButtonUp);
MouseMove += new MouseEventHandler(Region_MouseMove);
MouseLeftButtonDown += new MouseButtonEventHandler(Region_MouseLeftButtonDown);
_MeasuredSize = adornedElement.RenderSize;
//_region.PropertyChanged += new PropertyChangedEventHandler(_region_PropertyChanged);
Context = context;
}
void Region_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
EndSelection(sender, e);
}
public enum Contexts { EditTestObject, EditTestObjectTemplate };
private Contexts _context;
public Contexts Context
{
get => _context;
set => _context = value;
}
void Region_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (null != OnRegionSelected) { OnRegionSelected(this, e); }
}
private Size __MeasuredSize;
private Size _MeasuredSize
{
get => __MeasuredSize;
set => __MeasuredSize = value;
}
private Point p1;
public void Region_MouseMove(object sender, MouseEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed)
{
if (IsNew) { DrawSelection(sender, e, _adornedElement); }
else { MoveSelection(sender, e, _adornedElement); }
var layer = AdornerLayer.GetAdornerLayer(_adornedElement);
InvalidateVisual();
layer.InvalidateVisual();
}
}
public void DrawSelection(object sender, MouseEventArgs e, UIElement adornedElement)
{
if (e.LeftButton == MouseButtonState.Pressed)
{
var mousePosition = e.GetPosition(adornedElement);
var r = SelectRect;
if (mousePosition.X < AnchorPoint.X) { r.X = mousePosition.X; }
else { r.X = AnchorPoint.X; }
if (mousePosition.Y < AnchorPoint.Y) { r.Y = mousePosition.Y; }
else { r.Y = AnchorPoint.Y; }
r.Width = Math.Abs(mousePosition.X - AnchorPoint.X);
r.Height = Math.Abs(mousePosition.Y - AnchorPoint.Y);
SelectRect = r;
_geometry.Rect = SelectRect;
}
}
public void MoveSelection(object sender, MouseEventArgs e, UIElement adornedElement)
{
if (e.LeftButton == MouseButtonState.Pressed)
{
var mousePosition = e.GetPosition(adornedElement);
var r = SelectRect;
r.X -= /*p1.X -*/ (p1.X - mousePosition.X);
r.Y -= /*p1.Y -*/(p1.Y - mousePosition.Y);
SelectRect = r;
p1 = mousePosition;
_geometry.Rect = SelectRect;
}
}
public delegate void EndSelectionHandler(RegionAdorner r);
public event EndSelectionHandler OnEndSelection;
public void EndSelection(object sender, MouseButtonEventArgs e)
{
ReleaseMouseCapture();
if (null != OnEndSelection) { OnEndSelection(this); }
}
}
}

View File

@@ -0,0 +1,152 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace DatabaseExport
{
public class Zone //: Common.BindableBase
{
public string Name { get; set; }
public string Description { get; set; }
public string Image { get; set; }
public TemplateZone ISODllZone { get; }
public Zone(TemplateZone z, TestObjectTemplate template)
{
ISODllZone = z;
if (null == z || null == z.Description)
{
Description = "";
}
else
{
Description = z.Description;
}
Image = z.Picture;
var path = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ZonePictures");
//if (string.IsNullOrEmpty(Image)) { Image = "H3_2_11.png"; }
if (!string.IsNullOrEmpty(Image))
{
path = System.IO.Path.Combine(path, Image);
if (!System.IO.File.Exists(path))
{
PictureIndex = -1;
}
else
{
var src = new System.Windows.Media.Imaging.BitmapImage();
src.BeginInit();
src.UriSource = new Uri(path, UriKind.Absolute);
try
{
src.EndInit();
PictureSource = src;
_pictureIndex = AllPictures.ToList().IndexOf(Image);
}
catch
{
PictureIndex = -1;
}
}
}
Name = z.ZoneName;
_regions = new List<Region>();
foreach (var r in z.TemplateRegions)
{
var region = new Region(template, r);
_regions.Add(region);
}
}
public class FileInfoComparer : IComparer<System.IO.FileInfo>
{
int IComparer<System.IO.FileInfo>.Compare(System.IO.FileInfo left, System.IO.FileInfo right)
{
if (left == right)
{
return 0;
}
if (left == null)
{
return -1;
}
if (right == null)
{
return 1;
}
return left.FullName.CompareTo(right.FullName);
}
}
private List<System.IO.FileInfo> _fileNames = null;
public string[] AllPictures
{
get
{
if (null == _fileNames)
{
var files = new List<string>();
files.AddRange(System.IO.Directory.EnumerateFiles(
System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ZonePictures")));
_fileNames = new List<System.IO.FileInfo>();
foreach (var file in files)
{
_fileNames.Add(new System.IO.FileInfo(file));
}
_fileNames.Sort(new FileInfoComparer());
}
var l = new List<string>();
foreach (var fi in _fileNames)
{
l.Add(fi.Name);
}
return l.ToArray();
}
}
private int _pictureIndex = -1;
public int PictureIndex
{
get => _pictureIndex;
set
{
if (value < 0)
{
PictureSource = null;
}
else
{
var src = new System.Windows.Media.Imaging.BitmapImage();
src.BeginInit();
src.UriSource = new Uri(_fileNames[value].FullName, UriKind.Absolute);
src.EndInit();
PictureSource = src;
}
_pictureIndex = value;
//if (null != _template) { _template.MarkChanged(Tags.PictureIndex.ToString()); }
}
}
public string GetPictureName()
{
return _pictureIndex < 0 ? "" : _fileNames[_pictureIndex].Name;
}
public System.Windows.Media.ImageSource PictureSource { get; set; } = null;
private List<Region> _regions = new List<Region>();
public Region[] Regions
{
get => _regions.ToArray();
set => _regions = new List<Region>(value);
}
}
}

View File

@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Windows.Controls;
namespace DatabaseExport
{
public class TabPageItem : TabPageCommon
{
public UserControl Content { get; set; } = null;
}
public class TabPageItemGroup : TabPageCommon
{
public ObservableCollection<TabPageItem> Items { get; } = new ObservableCollection<TabPageItem>();
}
public class TabPageSource
{
private static TabPageSource _source = new TabPageSource();
public ObservableCollection<TabPageItemGroup> AllGroups { get; } = new ObservableCollection<TabPageItemGroup>();
public static IEnumerable<TabPageItemGroup> GetGroups(string uniqueid)
{
if (!uniqueid.Equals("AllGroups")) throw new ArgumentException("Only 'AllGroups' is supported as a collection of groups");
return _source.AllGroups;
}
}
}

View File

@@ -0,0 +1,8 @@
namespace DatabaseExport
{
public abstract class TabPageCommon : IUIItems
{
public virtual string GetName() { return UniqueId; }
public string UniqueId { get; set; } = string.Empty;
}
}

View File

@@ -0,0 +1,85 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace DatabaseExport
{
public class CustomerDetails
{
private readonly ISO.CustomerDetails _customerDetails;
public string Name
{
get => _customerDetails.Name;
set => _customerDetails.Name = value;
}
public CustomerDetails()
{
_customerDetails = new ISO.CustomerDetails();
_customerDetails.Name = "(none)";
}
public CustomerDetails(ISO.CustomerDetails customerDetails)
{
_customerDetails = new ISO.CustomerDetails(customerDetails);
}
public ISO.CustomerDetails GetISOCustomer()
{
return _customerDetails;
}
public override string ToString()
{
return Name;
}
}
public class CustomerDetailsList
{
private static readonly CustomerDetailsList _customerList = new CustomerDetailsList();
public static CustomerDetailsList CustomerList => _customerList;
private void PopulateCustomers()
{
if (null != _customers) return;
_customers = new Dictionary<string, CustomerDetails>();
foreach (var c in _customerList.GetAllCustomers())
{
if (!_customers.ContainsKey(c.Name))
{
_customers.Add(c.Name, c);
}
}
}
private static readonly object _customerLock = new object();
private Dictionary<string, CustomerDetails> _customers = null;
public CustomerDetails[] Customers
{
get
{
lock (_customerLock)
{
PopulateCustomers();
}
var customers = new List<CustomerDetails>(_customers.Values);
customers.Sort(CompareCustomers);
return customers.ToArray();
}
}
private static int CompareCustomers(CustomerDetails a, CustomerDetails b)
{
if (a == b) { return 0; }
if (null == a) { return -1; }
return null == b ? 1 : String.Compare(a.Name, b.Name, StringComparison.Ordinal);
}
public CustomerDetails[] GetAllCustomers()
{
var list = new List<CustomerDetails>();
list.Add(new CustomerDetails()); //This is the "(none)" entry
list.AddRange(ISO.CustomerDetails.GetAllCustomerDetails().Select(cs => new CustomerDetails(cs)));
return list.ToArray();
}
public CustomerDetails GetCustomerDetail(string name)
{
var customers = from c in Customers.AsParallel() where c.Name == name select c;
return customers.Any() ? customers.First() : null;
}
}
}

View File

@@ -0,0 +1,93 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace DatabaseExport
{
public class LabratoryDetails
{
ISO.LabratoryDetails _lab = null;
public string Name
{
get => _lab.Name;
set => _lab.Name = value;
}
public LabratoryDetails()
{
_lab = new ISO.LabratoryDetails();
_lab.Name = "(none)";
}
public LabratoryDetails(ISO.LabratoryDetails lab) { _lab = new ISO.LabratoryDetails(lab); }
public ISO.LabratoryDetails GetIsoLab() { return _lab; }
public override string ToString()
{
return Name;
}
}
public class LabratoryDetailsList
{
protected LabratoryDetailsList()
{
}
private static LabratoryDetailsList _list = new LabratoryDetailsList();
public static LabratoryDetailsList LabratoryList => _list;
private Dictionary<string, LabratoryDetails> _labs = null;
private void PopulateList()
{
if (null != _labs) return;
_labs = new Dictionary<string, LabratoryDetails>();
foreach (var l in GetAllLabs())
{
if (!_labs.ContainsKey(l.Name))
{
_labs.Add(l.Name, l);
}
else
{
_labs[l.Name] = l;
}
}
}
private static object _LabLock = new object();
public LabratoryDetails[] Labs
{
get
{
lock (_LabLock)
{
PopulateList();
}
var labs = new List<LabratoryDetails>(_labs.Values);
labs.Sort(CompareLabs);
return labs.ToArray();
}
}
private static int CompareLabs(LabratoryDetails a, LabratoryDetails b)
{
if (a == b) { return 0; }
if (null == a) { return -1; }
return null == b ? 1 : string.Compare(a.Name, b.Name, StringComparison.Ordinal);
}
public LabratoryDetails GetLab(string name)
{
try { lock (_LabLock) { return _labs != null ? _labs.ContainsKey(name) ? _labs[name] : null : null; } }
catch (Exception) {/* DTS.Utilities.Logging.APILogger.Log("failed to get labratories", ex); */}
return null;
}
private LabratoryDetails[] GetAllLabs()
{
var list = new List<LabratoryDetails>();
try
{
list.Add(new LabratoryDetails()); //This is the "(none)" entry
list.AddRange(ISO.LabratoryDetails.GetAllLabratoryDetails().Select(lab => new LabratoryDetails(lab)));
}
catch (Exception) {/* DTS.Utilities.Logging.APILogger.Log("failed to get labratories", ex);*/ }
return list.ToArray();
}
}
}

View File

@@ -0,0 +1,88 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace DatabaseExport
{
public class TestEngineerDetails
{
private readonly ISO.TestEngineerDetails _testEngineerDetails;
public string Name
{
get => _testEngineerDetails.Name;
set => _testEngineerDetails.Name = value;
}
public TestEngineerDetails()
{
_testEngineerDetails = new ISO.TestEngineerDetails();
_testEngineerDetails.Name = "(none)"; // Strings.StringResources.TestTemplate_EmptyListName;
}
public TestEngineerDetails(ISO.TestEngineerDetails testEngineerDetails)
{
_testEngineerDetails = new ISO.TestEngineerDetails(testEngineerDetails);
}
public ISO.TestEngineerDetails GetISOTestEngineer()
{
return _testEngineerDetails;
}
public override string ToString()
{
return Name;
}
}
public class TestEngineerDetailsList
{
private static TestEngineerDetailsList _testEngineerList = new TestEngineerDetailsList();
public static TestEngineerDetailsList TestEngineerList => _testEngineerList;
private static object _testEngineerLock = new object();
private Dictionary<string, TestEngineerDetails> _testEngineers = null;
public TestEngineerDetails[] TestEngineers
{
get
{
lock (_testEngineerLock)
{
if (null == _testEngineers)
{
PopulateEngineers();
}
}
var testEngineers = new List<TestEngineerDetails>(_testEngineers.Values);
testEngineers.Sort(CompareTestEngineers);
return testEngineers.ToArray();
}
}
private void PopulateEngineers()
{
_testEngineers = new Dictionary<string, TestEngineerDetails>();
foreach (var t in _testEngineerList.GetAllTestEngineers())
{
if (!_testEngineers.ContainsKey(t.Name)) { _testEngineers.Add(t.Name, t); }
}
}
private static int CompareTestEngineers(TestEngineerDetails a, TestEngineerDetails b)
{
if (a == b) { return 0; }
if (null == a) { return -1; }
if (null == b) { return 1; }
return a.Name.CompareTo(b.Name);
}
private TestEngineerDetails[] GetAllTestEngineers()
{
var list = new List<TestEngineerDetails>();
list.Add(new TestEngineerDetails()); //This is the "(none)" entry
foreach (var ts in ISO.TestEngineerDetails.GetAllTestEngineerDetails())
{
list.Add(new TestEngineerDetails(ts));
}
return list.ToArray();
}
public TestEngineerDetails GetTestEngineerDetail(string name)
{
var testEngineers = from t in TestEngineers.AsParallel() where t.Name == name select t;
if (null != testEngineers && testEngineers.Count() > 0) { return testEngineers.First(); }
return null;
}
}
}

View File

@@ -0,0 +1,30 @@
using System;
namespace DatabaseExport
{
public class GroupTemplateTableInfo
{
public GroupTemplateTableInfo(string templateName, SerializedSettings.ISOSupportLevels isoSupportLevel, bool sysBuilt, string templateDescription, DateTime lastModified, string lastModifiedBy, bool embedded)
{
TemplateName = templateName;
ISOSupportLevel = isoSupportLevel;
SysBuilt = sysBuilt;
TemplateDescription = templateDescription;
LastModified = lastModified;
LastModifiedBy = lastModifiedBy;
Embedded = embedded;
}
public string TemplateName { get; private set; }
public SerializedSettings.ISOSupportLevels ISOSupportLevel { get; private set; }
public bool SysBuilt { get; private set; }
public string TemplateDescription { get; private set; }
public DateTime LastModified { get; private set; }
public string LastModifiedBy { get; private set; }
public bool Embedded { get; private set; }
public override string ToString()
{
return TemplateName;
}
}
}

View File

@@ -0,0 +1,14 @@
namespace DatabaseExport
{
/// <summary>
/// GUI wrapper for template channels ... it contains a testobjecttemplatechannel
/// </summary>
public class TemplateChannelUI
{
private TestObjectTemplateChannel _channel;
public TemplateChannelUI(TestObjectTemplateChannel channel)
{
_channel = channel;
}
}
}

View File

@@ -0,0 +1,685 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
namespace DatabaseExport
{
public class TestObject : DbTimeStampBase, IComparable<TestObject>
{
public override string LookupTable => DbOperations.TestSetups.TestObjectsTable;
public override ConstraintHelper[] GetConstraints()
{
return new[]
{
new ConstraintHelper
{
ColumnName = DbOperations.TestSetups.TestObjectsFields.SerialNumber.ToString(),
DbType = System.Data.SqlDbType.NVarChar,
DbValue = SerialNumber
}
};
}
public void RefreshHardware()
{
SetHardwareFromISO();
}
public enum Tags
{
SerialNumber,
SerialNumberConverted,
TestObjectType,
ParentObject,
SysBuilt,
Channels,
Hardware,
LastModifiedBy,
LastModifiedText,
AllTemplates,
Template,
TemplateIndex,
ChannelsDescription,
TemplateDescription,
TemplateImage,
Zones,
SelectedGlobalRangeCACOption,
ZoneNames,
CurrentZone,
CurrentZoneIndex,
ChannelVisibility,
ChannelTypesIndex
}
/// <summary>
/// dirty controls whether _isComplete is valid or not
/// if Dirty is true then _isComplete is not valid
/// IsComplete will actually calculate this value
/// </summary>
public bool IsDirty { get; set; } = true;
public int CompareTo(TestObject rhs)
{
if (null == rhs) { return 1; }
return rhs == this ? 0 : SerialNumber.CompareTo(rhs.SerialNumber);
}
/// <summary>
/// returns the iso support level of the group
/// </summary>
/// <returns></returns>
public SerializedSettings.ISOSupportLevels GetObjectISOLevel()
{
if (TemplateType.Contains(TestObjectTemplate.NON_ISO_TESTOBJECT_CHANNEL_TYPE) || TemplateType.Contains(TestObjectTemplateChannel.NONISOCHANNELTYPE))
{
return SerializedSettings.ISOSupportLevels.NO_ISO;
}
return SerializedSettings.ISOSupportLevels.ISO_ONLY;
}
public SensorData GetSensor(string ChannelId, string serialNumber)
{
var sd = SensorsCollection.SensorsList.GetSensorBySerialNumber(serialNumber);
if (null == sd) { return null; }
sd = new SensorData(sd);
var settings = GetISOTestObject().GetSensorSettings(ChannelId, sd.SerialNumber);
var isoTO = GetISOTestObject();
var channel = isoTO.GetChannel(ChannelId);
if (null != channel)
{
//preset the channel iso fields, these can be filter can be overwritten by to settings below
sd.TestObject = channel.Channel.Test_Object;
sd.Position = channel.Channel.Position;
sd.OriginalPosition = channel.Channel.Position;
if (channel.Channel.Default_Filter_Class != "?")
{
//If ISO says "?", then use the sensor's filter class (but still overwrite with any settings below)
sd.FilterClassIso = channel.Channel.Default_Filter_Class;
}
sd.FineLocation1 = channel.Channel.Fine_Loc_1;
sd.FineLocation2 = channel.Channel.Fine_Loc_2;
sd.FineLocation3 = channel.Channel.Fine_Loc_3;
sd.MainLocation = channel.Channel.Trans_Main_Loc;
sd.PhysicalDimension = channel.Channel.Physical_Dimension;
sd.Direction = channel.Channel.Direction;
}
if (null != settings)
{
foreach (var setting in settings)
{
switch (setting.Setting)
{
case ISO.TestObject.SensorSettings.CFC:
sd.FilterClassIso = setting.Value;
switch (sd.FilterClassIso)
{
case "A":
sd.Filter = new FilterClass(FilterClass.FilterClassType.CFC1000);
break;
case "B":
sd.Filter = new FilterClass(FilterClass.FilterClassType.CFC600);
break;
case "C":
sd.Filter = new FilterClass(FilterClass.FilterClassType.CFC180);
break;
case "D":
sd.Filter = new FilterClass(FilterClass.FilterClassType.CFC60);
break;
case "P":
sd.Filter = new FilterClass(FilterClass.FilterClassType.None);
break;
case "S":
//FB 13120 Adhoc filter class
sd.Filter = new FilterClass(FilterClass.FilterClassType.AdHoc);
break;
}
break;
case ISO.TestObject.SensorSettings.Position:
sd.Position = setting.Value;
break;
case ISO.TestObject.SensorSettings.Polarity:
sd.Invert = setting.Value == "-";
break;
case ISO.TestObject.SensorSettings.Range:
sd.Capacity = double.Parse(setting.Value, CultureInfo.InvariantCulture);
break;
case ISO.TestObject.SensorSettings.LimitDuration:
if (!string.IsNullOrWhiteSpace(setting.Value))
{
sd.DigitalOutputLimitDuration = bool.Parse(setting.Value);
sd.LimitDuration = bool.Parse(setting.Value);
sd.LimitSquibFireDuration = bool.Parse(setting.Value);
}
break;
case ISO.TestObject.SensorSettings.Delay:
if (!string.IsNullOrWhiteSpace(setting.Value))
{
sd.DigitalOutputDelayMS = double.Parse(setting.Value, CultureInfo.InvariantCulture);
sd.DelayMS = double.Parse(setting.Value, CultureInfo.InvariantCulture);
sd.SquibFireDelayMS = double.Parse(setting.Value, CultureInfo.InvariantCulture);
}
break;
case ISO.TestObject.SensorSettings.Duration:
if (!string.IsNullOrWhiteSpace(setting.Value))
{
sd.DigitalOutputDurationMS = double.Parse(setting.Value, CultureInfo.InvariantCulture);
sd.DurationMS = double.Parse(setting.Value, CultureInfo.InvariantCulture);
sd.SquibFireDurationMS = double.Parse(setting.Value, CultureInfo.InvariantCulture);
}
break;
case ISO.TestObject.SensorSettings.OutputMode:
if (!string.IsNullOrWhiteSpace(setting.Value))
{
int iValue;
if (int.TryParse(setting.Value, NumberStyles.Any, CultureInfo.InvariantCulture,
out iValue))
{
sd.DigitalOutputMode = (OutputTOMDigitalChannel.DigitalOutputMode)iValue;
}
}
break;
case ISO.TestObject.SensorSettings.SQMode:
if (!string.IsNullOrWhiteSpace(setting.Value))
{
int iValue;
if (int.TryParse(setting.Value, NumberStyles.Any, CultureInfo.InvariantCulture,
out iValue))
{
sd.SquibFireMode = (OutputSquibChannel.SquibFireMode)iValue;
}
}
break;
case ISO.TestObject.SensorSettings.DIMode:
if (!string.IsNullOrWhiteSpace(setting.Value))
{
int iValue;
if (int.TryParse(setting.Value, NumberStyles.Any, CultureInfo.InvariantCulture,
out iValue))
{
sd.InputMode = (DigitalInputScaleMultiplier.InputModes)iValue;
}
}
break;
case ISO.TestObject.SensorSettings.DefaultValue:
if (!string.IsNullOrWhiteSpace(setting.Value))
{
if (double.TryParse(setting.Value, out var defaultValue))
{
sd.ScaleMultiplier.DefaultValue = defaultValue;
}
}
break;
case ISO.TestObject.SensorSettings.ActiveValue:
if (!string.IsNullOrWhiteSpace(setting.Value))
{
if (double.TryParse(setting.Value, out var activeValue))
{
sd.ScaleMultiplier.ActiveValue = activeValue;
}
}
break;
default:
throw new ArgumentOutOfRangeException();
}
}
}
if (sd.FilterClassIso == "?")
{
sd.FilterClassIso = "P"; // "Prefiltered > CFC 1000" (Unfiltered)
}
return sd;
}
public void SetSensor(string channelName, SensorData sensor)
{
var settings = new List<ISO.TestObject.SensorSetting>();
var fields = Enum.GetValues(typeof(ISO.TestObject.SensorSettings)).Cast<ISO.TestObject.SensorSettings>().ToArray();
foreach (var field in fields)
{
var value = "";
switch (field)
{
case ISO.TestObject.SensorSettings.CFC:
value = sensor.FilterClassIso;
break;
case ISO.TestObject.SensorSettings.Position:
value = sensor.Position;
break;
case ISO.TestObject.SensorSettings.Polarity:
value = sensor.Invert ? "-" : "+";
break;
case ISO.TestObject.SensorSettings.Range:
value = sensor.Capacity.ToString(CultureInfo.InvariantCulture);
break;
case ISO.TestObject.SensorSettings.Duration:
value = sensor.DurationMS.ToString(CultureInfo.InvariantCulture);
if (sensor.IsSquib())
{
value = sensor.SquibFireDurationMS.ToString(CultureInfo.InvariantCulture);
}
else if (sensor.IsDigitalOutput())
{
value = sensor.DigitalOutputDurationMS.ToString(CultureInfo.InvariantCulture);
}
break;
case ISO.TestObject.SensorSettings.Delay:
value = sensor.DelayMS.ToString(CultureInfo.InvariantCulture);
if (sensor.IsSquib())
{
value = sensor.SquibFireDelayMS.ToString(CultureInfo.InvariantCulture);
}
else if (sensor.IsDigitalOutput())
{
value = sensor.DigitalOutputDelayMS.ToString(CultureInfo.InvariantCulture);
}
break;
case ISO.TestObject.SensorSettings.LimitDuration:
value = sensor.LimitDuration.ToString(CultureInfo.InvariantCulture);
if (sensor.IsSquib())
{
value = sensor.LimitSquibFireDuration.ToString(CultureInfo.InvariantCulture);
}
else if (sensor.IsDigitalOutput())
{
value = sensor.DigitalOutputLimitDuration.ToString(CultureInfo.InvariantCulture);
}
break;
case ISO.TestObject.SensorSettings.OutputMode:
value = ((int)sensor.DigitalOutputMode).ToString(CultureInfo.InvariantCulture);
break;
case ISO.TestObject.SensorSettings.SQMode:
value = ((int)sensor.SquibFireMode).ToString(CultureInfo.InvariantCulture);
break;
case ISO.TestObject.SensorSettings.DIMode:
value = ((int)sensor.InputMode).ToString(CultureInfo.InvariantCulture);
break;
case ISO.TestObject.SensorSettings.DefaultValue:
value = sensor.ScaleMultiplier.DefaultValue.ToString(CultureInfo.InvariantCulture);
break;
case ISO.TestObject.SensorSettings.ActiveValue:
value = sensor.ScaleMultiplier.ActiveValue.ToString(CultureInfo.InvariantCulture);
break;
default:
continue; // If we don't know about a setting we shouldn't overwrite it with blank.
}
settings.Add(new ISO.TestObject.SensorSetting(field, value, channelName, sensor.SerialNumber));
}
foreach (var setting in settings)
{
GetISOTestObject().SetSensorSetting(channelName, sensor.SerialNumber, setting);
}
}
public TestObject()
{
//PopulateTemplates();
_isoTestObject = new ISO.TestObject();
Template = new TestObjectTemplate();
ParentObject = "";
SysBuilt = false;
}
public DASHardware[] Hardware
{
get
{
var hardware = new List<DASHardware>(_hardware.Values.ToArray());
hardware.Sort();
return hardware.ToArray();
}
}
public void Initialize(TestObject copy)
{
//PopulateTemplates();
var db = ISO13499FileDb.IsoDb;
_isoTestObject = new ISO.TestObject(copy.GetISOTestObject(), ref db);
SerialNumber = copy.SerialNumber;
if (null != copy.Template)
{
var tot = new TestObjectTemplate(copy.Template, ref db);
SetTemplateDontResetISOObject(tot);
}
var copyISOTO = copy.GetISOTestObject();
var ISOTO = GetISOTestObject();
var hardware = new List<DASHardware>();
foreach (var das in copy.Hardware)
{
hardware.Add(new DASHardware(das, null));
}
foreach (var h in hardware)
{
_hardware.Add(h.SerialNumber, h);
}
ParentObject = copy.ParentObject;
SysBuilt = copy.SysBuilt;
if (SysBuilt)
{
_isoTestObject.SerialNumberConverted = copy.SerialNumberConverted;
}
}
public TestObject(TestObject copy)
{
Initialize(copy);
DbTimeStamp = copy.DbTimeStamp;
}
private string _serialNumber = string.Empty;
public string SerialNumber
{
get => _serialNumber;
set
{
SetProperty(ref _serialNumber, value, Tags.SerialNumber.ToString());
GetISOTestObject().SerialNumber = value;
}
}
public string SerialNumberOrOriginalSerialNumber
{
get
{
if (GetISOTestObject().Embedded)
{
return GetISOTestObject().OriginalSerialNumber;
}
return string.IsNullOrWhiteSpace(SerialNumberConverted) ? SerialNumber : SerialNumberConverted;
}
}
private string _serialNumberConverted = string.Empty;
public string SerialNumberConverted
{
get => _serialNumberConverted;
set => SetProperty(ref _serialNumberConverted, value, Tags.SerialNumberConverted.ToString());
}
public string DisplaySerialNumber
{
get
{
if (string.IsNullOrWhiteSpace(SerialNumberConverted) && !SysBuilt)
{
return SerialNumberOrOriginalSerialNumber;
}
return SerialNumberConverted;
}
set
{
//We assume that this is an Added Group being renamed
SerialNumber = TestSetupName + "_" + value;
SerialNumberConverted = value;
GetISOTestObject().OriginalSerialNumber = SerialNumber;
Template.OriginalTemplateName = SerialNumber + "_Template";
GetISOTestObject().OriginalTemplate = Template.OriginalTemplateName;
}
}
public string TestSetupName { get; set; } = string.Empty;
private string _testObjectType = "?";
public string TestObjectType
{
get => _testObjectType;
set => SetProperty(ref _testObjectType, value, Tags.TestObjectType.ToString());
}
private string _parentObject = "";
public string ParentObject
{
get => _parentObject;
set
{
IsDirty = true;
SetProperty(ref _parentObject, value, Tags.ParentObject.ToString());
GetISOTestObject().ParentObject = value;
}
}
private bool _sysBuilt;
public bool SysBuilt
{
get => _sysBuilt;
set => SetProperty(ref _sysBuilt, value, Tags.SysBuilt.ToString());
}
private Dictionary<string, DASHardware> _hardware = new Dictionary<string, DASHardware>();
public bool ContainsHardware(DASHardware h)
{
return _hardware.ContainsKey(h.SerialNumber);
}
public void SetHardwareFromISO()
{
_hardware.Clear();
var isoTO = GetISOTestObject();
foreach (var hid in isoTO.HardwareIds)
{
var h = DASHardwareList.GetList().GetHardware(hid);
if (null == h)
{
continue;
}
//just making sure we have a copy and not the original hardware record.
h = new DASHardware(h.GetHardware());
h.SetTimeStampMemory(h.GetTimeStampMemory());
if (!_hardware.ContainsKey(h.SerialNumber))
{
_hardware[h.SerialNumber] = h;
}
}
}
/// <summary>
/// this call is intended to be available to test template to update the hardware for the group in memory
/// it is not intended to have that hardware stored in the db currently
/// </summary>
/// <param name="hardware"></param>
public void SetHardware(DASHardware[] hardware)
{
_hardware.Clear();
var hids = new List<string>();
foreach (var h in hardware)
{
_hardware[h.SerialNumber] = h;
if (!hids.Contains(h.SerialNumber))
{
hids.Add(h.SerialNumber);
}
}
GetISOTestObject().HardwareIds = hids.ToArray();
}
public void AddHardware(DASHardware hardware)
{
var stamp = hardware.GetTimeStampMemory();
//just making sure we have a copy and not the original hardware record
hardware = new DASHardware(hardware.GetHardware());
hardware.SetTimeStampMemory(stamp);
IsDirty = true;
var toAdd = hardware;
if (hardware.IsDummy())
{
var key = hardware.SerialNumber;
if (_hardware.ContainsKey(key))
{
var current = 1;
while (_hardware.ContainsKey(key))
{
current++;
key = string.Format("{0}({1:00})", hardware.SerialNumber, current);
}
toAdd = new DASHardware(hardware.GetHardware());
toAdd.SetTimeStampMemory(hardware.GetTimeStampMemory());
toAdd.SerialNumber = key;
}
else
{
toAdd = new DASHardware(hardware.GetHardware());
toAdd.SetTimeStampMemory(hardware.GetTimeStampMemory());
}
}
else
{
toAdd = new DASHardware(hardware.GetHardware());
toAdd.SetTimeStampMemory(hardware.GetTimeStampMemory());
}
if (_hardware.ContainsKey(toAdd.SerialNumber))
{
return;
}
_hardware.Add(toAdd.SerialNumber, toAdd);
//toAdd.PropertyChanged += addedHardware_PropertyChanged;
OnPropertyChanged(Tags.Hardware.ToString());
var hids = new List<string>();
foreach (var h in Hardware)
{
hids.Add(h.GetHardware().GetId());
}
_isoTestObject.HardwareIds = hids.ToArray();
}
public ISO.TestObject GetISOTestObject()
{
return _isoTestObject;
}
private TestObjectTemplate _template = null;
public TestObjectTemplate Template
{
get => _template;
set
{
if (value == _template)
{
return;
}
if (null == value)
{
_template = value;
return;
}
if (GetISOTestObject().Template != value.TemplateName)
{
var db = ISO13499FileDb.IsoDb;
GetISOTestObject().SetTemplate(value.TemplateName, ref db);
}
SetProperty(ref _template, value, Tags.Template.ToString());
OnPropertyChanged(Tags.TemplateIndex.ToString());
OnPropertyChanged(Tags.ChannelsDescription.ToString());
OnPropertyChanged(Tags.LastModifiedText.ToString());
OnPropertyChanged(Tags.TemplateDescription.ToString());
OnPropertyChanged(Tags.TemplateImage.ToString());
OnPropertyChanged(Tags.Zones.ToString());
OnPropertyChanged(Tags.SelectedGlobalRangeCACOption.ToString());
var zoneNames = new List<string>();
foreach (var z in Template.TemplateZones)
{
zoneNames.Add(z.Name);
}
ZoneNames = zoneNames.ToArray();
}
}
public void SetTemplateDontResetISOObject(TestObjectTemplate value)
{
if (value == _template)
{
return;
}
if (null == value)
{
_template = value;
return;
}
try
{
_isoTestObject?.SetTemplateOnly(value.TemplateName);
}
catch (Exception)
{
}
var db = ISO13499FileDb.IsoDb;
SetProperty(ref _template, new TestObjectTemplate(value, ref db), Tags.Template.ToString());
OnPropertyChanged(Tags.TemplateIndex.ToString());
OnPropertyChanged(Tags.ChannelsDescription.ToString());
OnPropertyChanged(Tags.LastModifiedText.ToString());
OnPropertyChanged(Tags.TemplateDescription.ToString());
OnPropertyChanged(Tags.TemplateImage.ToString());
OnPropertyChanged(Tags.Zones.ToString());
OnPropertyChanged(Tags.SelectedGlobalRangeCACOption.ToString());
var zoneNames = new List<string>();
foreach (var z in value.TemplateZones)
{
zoneNames.Add(z.Name);
}
ZoneNames = zoneNames.ToArray();
}
public Dictionary<string, string> GetValues()
{
var elementNameValuePairs = new Dictionary<string, string>();
var isoTestObject = GetISOTestObject();
elementNameValuePairs[DbOperations.TestSetups.TestObjectsFields.SerialNumber.ToString()] = SerialNumber;
elementNameValuePairs[DbOperations.TestSetups.TestObjectsFields.LastModifiedBy.ToString()] = isoTestObject.LastModifiedBy;
elementNameValuePairs[DbOperations.TestSetups.TestObjectsFields.LastModified.ToString()] = isoTestObject.LastModified.ToString(CultureInfo.InvariantCulture);
elementNameValuePairs[DbOperations.TestSetups.TestObjectsFields.Template.ToString()] = (null != Template) ? Template.TemplateName : "";
elementNameValuePairs[DbOperations.TestSetups.TestObjectsFields.LocalOnly.ToString()] = isoTestObject.LocalOnly.ToString();
elementNameValuePairs[DbOperations.TestSetups.TestObjectsFields.ParentObject.ToString()] = ParentObject ?? "";
elementNameValuePairs[DbOperations.TestSetups.TestObjectsFields.SysBuilt.ToString()] = SysBuilt.ToString();
elementNameValuePairs[DbOperations.TestSetups.TestObjectsFields.Embedded.ToString()] = isoTestObject.Embedded.ToString(CultureInfo.InvariantCulture);
elementNameValuePairs[DbOperations.TestSetups.TestObjectsFields.OriginalTemplate.ToString()] = isoTestObject.OriginalTemplate;
elementNameValuePairs[DbOperations.TestSetups.TestObjectsFields.OriginalSerialNumber.ToString()] = isoTestObject.OriginalSerialNumber;
return elementNameValuePairs;
}
private List<string> _zoneNames = new List<string>();
public string[] ZoneNames
{
get => _zoneNames.ToArray();
set => SetProperty(ref _zoneNames, new List<string>(value), Tags.ZoneNames.ToString());
}
public string TemplateType => null == Template ? "" : Template.TestObjectType;
public bool LocalOnly { get; } = false;
private ISO.TestObject _isoTestObject = null;
public TestObject(ISO.TestObject to, bool sysBuilt)
{
//PopulateTemplates();
_isoTestObject = to;
SerialNumber = to.SerialNumber;
if (sysBuilt)
{
SerialNumberConverted = to.SerialNumber.Remove(0, SerialNumber.LastIndexOf('_') + 1);
if (to.Template == "SysBuilt_(no channels)") // add to string resources this whole thing not needed anymore?
{
Template = TestObjectTemplateCollection.TemplateCollection.SysBuiltTestObjectTemplate;
}
else
{
Template = TestObjectTemplateCollection.TemplateCollection.GetTemplate(to.Template);
}
TestObjectType = to.TestObjectType;
SysBuilt = true;
}
else
{
Template = TestObjectTemplateCollection.TemplateCollection.GetTemplate(to.Template);
}
LocalOnly = to.LocalOnly;
foreach (var id in to.HardwareIds)
{
DASHardware da = null;
try
{
da = DASHardwareList.GetList().GetHardware(id);
}
catch (Exception)
{
//DTS.Utilities.Logging.APILogger.Log(ex);
}
if (null != da && !ContainsHardware(da))
{
AddHardware(da);
}
}
}
}
}

View File

@@ -0,0 +1,71 @@
using System.Collections.Generic;
using System.Data;
namespace DatabaseExport
{
/// <summary>
/// list that holds groups
/// </summary>
public class TestObjectList
{
private static readonly object MyLock = new object();
private static TestObjectList _testObjectList;
public static TestObjectList TestObjectsList
{
get
{
lock (MyLock)
{
if (null == _testObjectList)
{
_testObjectList = new TestObjectList();
}
}
return _testObjectList;
}
}
public List<string> GetAllGroupSerialNumbers()
{
var serialNumbers = new List<string>();
using (var sql = DbOperations.GetCommand())
{
sql.CommandText = "SELECT A.SerialNumber from tblTestObjects as A";
using (var ds = DbOperations.Connection.QueryDataSet(sql))
{
foreach (DataRow dr in ds.Tables[0].Rows)
{
var groupSerialNumber = (string)dr["SerialNumber"];
if (!serialNumbers.Contains(groupSerialNumber))
{
serialNumbers.Add(groupSerialNumber);
}
}
}
}
return serialNumbers;
}
/// <summary>
/// returns a given test object if it is in the list,
/// returns null otherwise
/// </summary>
/// <param name="serialNumber">serialnumber of group to look for</param>
/// <returns></returns>
public TestObject GetTestObject(string serialNumber)
{
var db = ISO13499FileDb.IsoDb;
var testObject = ISO.TestObject.GetTestObject(serialNumber, ref db);
if (null == testObject) { return null; }
return new TestObject(testObject, testObject.SysBuilt);
}
public TestObject GetAddedGroup(string serialNumber)
{
return GetTestObject(serialNumber);
}
protected TestObjectList()
{
}
}
}

View File

@@ -0,0 +1,514 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace DatabaseExport
{
public class TestObjectTemplate
{
private enum GroupTemplateChannelFields
{
TestObjectNumber,
NameOfTheChannel,
LaboratoryChannelCode,
CustomerChannelCode,
Comments1,
Location,
Dimension,
Direction,
ChannelFrequencyClass,
Unit,
ReferenceSystem,
TransducerType,
TransducerId,
PreFilterType,
CutOffFrequency,
ChannelAmplitudeClass,
ReferenceChannel,
ReferenceChannelName,
DataSource,
DataStatus,
SamplingInterval,
BitResolution,
TimeOfFirstSample,
NumberOfSamples,
OffsetPostTest,
TransducerNaturalFrequency,
TransducerDampingRatio,
Comments,
FirstGlobalMaximumValue,
TimeOfMaximumValue,
FirstGlobalMinimumValue,
TimeOfMinimumValue,
StartOffsetInterval,
EndOffsetInterval,
MMEChannelId,
MMEChannelType,
Required,
DisplayOrder,
LocalOnly
}
private enum GroupTemplateFields
{
TemplateName,
Icon,
Description,
LocalOnly,
Version,
LastModifiedBy,
LastModified,
CRC32,
TestObjectType,
TestObject,
ParentTemplate,
SysBuilt,
OriginalTemplateName,
Embedded
};
public const string NON_ISO_TESTOBJECT_CHANNEL_TYPE = "x_NonISOTestObjectType_x";
public const string NON_ISO_TESTOBJECT_NAME = "x_NonISOTestObjectName_x";
public string LastModifiedBy { get; set; } = "N/A";
public DateTime LastModified { get; set; } = (DateTime)System.Data.SqlTypes.SqlDateTime.MinValue;
private int _currentZoneIndex = -1;
public int CurrentZoneIndex
{
get => _currentZoneIndex;
set
{
if (value >= 0)
{
CurrentZone = TemplateZones[value];
}
else
{
CurrentZone = null;
}
_currentZoneIndex = value;
}
}
private Zone _currentZone = null;//Zone.DummyZone;
public Zone CurrentZone
{
get => _currentZone;
set
{
//if (null != _currentZone && _currentZone != value) { _currentZone.PropertyChanged -= CurrentZone_PropertyChanged; }
_currentZone = value;
//if (null != _currentZone) { _currentZone.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(CurrentZone_PropertyChanged); }
if (null == value) { AreZoneControlsEnabled = false; }
else { AreZoneControlsEnabled = true; }
}
}
public bool AreZoneControlsEnabled { get; set; } = false;
private ISO.TestObjectTemplate _template = null;
public List<TestObjectTemplateChannel> RequiredChannels { get; set; } = new List<TestObjectTemplateChannel>();
public string TemplateParent { get; set; } = "";
public bool SysBuilt { get; set; } = false;
private bool _embedded = false;
public bool Embedded
{
get => _embedded;
set
{
_embedded = value;
if (null != _template) { _template.Embedded = value; }
}
}
private string _originalTemplateName = "";
public string OriginalTemplateName
{
get => _originalTemplateName;
set
{
_originalTemplateName = value;
if (null != _template) { _template.OriginalTemplateName = value; }
}
}
public string TemplateName { get; set; }
public string TemplateDescription { get; set; }
public bool IsLocalOnly { get; set; }
private MMETestObjects _testObject;
public MMETestObjects TestObject
{
get => _testObject;
set
{
_testObject = value;
if (null != _testObject)
{
AvailableTestObjectTypes = ISO13499FileDb.IsoDb.GetUniquePossibleChannelTypes(TestObjectTemplateChannel.NONISOCHANNELTYPE);
if (AvailableTestObjectTypes.Length > 0) { TestObjectTypeIndex = 0; }
else { TestObjectTypeIndex = -1; }
}
}
}
private string _testObjectType;
public string TestObjectType
{
get => _testObjectType;
set
{
_testObjectType = value;
//if (null != _template) { _template.TestObjectType = value; }//we did this so that _template.TestObjectType gets set, however during initialization _template can be null
_channels = new List<MMEPossibleChannels>(ISO13499FileDb.IsoDb.GetPossibleChannelsForType(_testObjectType));
var all = new List<TestObjectTemplateChannel>();
var db = ISO13499FileDb.IsoDb;
foreach (var pc in _channels) { all.Add(new TestObjectTemplateChannel(new TestObjectTemplateChannel(pc), /*ref db,*/ _template)); }
TemplateAllChannels = all.ToArray();
}
}
private List<MMEPossibleChannels> _channels = new List<MMEPossibleChannels>();
private List<TestObjectTemplateChannel> _allChannels = new List<TestObjectTemplateChannel>();
public TestObjectTemplateChannel[] TemplateAllChannels
{
get { _allChannels.Sort(new Comparison<TestObjectTemplateChannel>(CompareChannels)); return _allChannels.ToArray(); }
set
{
_allChannels = new List<TestObjectTemplateChannel>(value);
var channels = new List<TemplateChannelUI>();
foreach (var c in value)
{
var channel = new TemplateChannelUI(c);
channels.Add(channel);
}
TemplateAllUIChannels = channels.ToArray();
}
}
private List<TemplateChannelUI> _allUIChannels = new List<TemplateChannelUI>();
public TemplateChannelUI[] TemplateAllUIChannels
{
get => _allUIChannels.ToArray();
set => _allUIChannels = new List<TemplateChannelUI>(value);
}
private List<Zone> _zones = new List<Zone>();
public Zone[] TemplateZones
{
get => _zones.ToArray();
set { _zones = new List<Zone>(value); var j = CurrentZoneIndex; }
}
private List<string> _availableTestObjectTypes = null;
public string[] AvailableTestObjectTypes
{
get
{
if (null == _availableTestObjectTypes)
{
if (null == TestObject) { return new string[0]; }
_availableTestObjectTypes = new List<string>(ISO13499FileDb.IsoDb.GetTestObjectTypeForTestObject(TestObject.Test_Object));
}
return _availableTestObjectTypes.ToArray();
}
set => _availableTestObjectTypes = new List<string>(value);
}
private int _testObjectTypeIndex = -1;
public int TestObjectTypeIndex
{
get
{
if (string.IsNullOrEmpty(TestObjectType)) { return -1; }
return _availableTestObjectTypes.IndexOf(TestObjectType);
}
set
{
if (value >= 0) { TestObjectType = _availableTestObjectTypes[value]; }
else { TestObjectType = null; }
_testObjectTypeIndex = value;
var all = new List<TestObjectTemplateChannel>();
var db = ISO13499FileDb.IsoDb;
foreach (var pc in _channels) { all.Add(new TestObjectTemplateChannel(new TestObjectTemplateChannel(pc), /*ref db,*/ _template)); }
TemplateAllChannels = all.ToArray();
}
}
public static MMETestObjects GetNonISOTestObject()
{
var existingobjects = ISO13499FileDb.IsoDb.GetTestObjects(false);
var codes = new List<string>();
foreach (var existingobject in existingobjects)
{
if (existingobject.Text_L1 == NON_ISO_TESTOBJECT_NAME)
{
return existingobject;
}
else { codes.Add(existingobject.Test_Object); }
}
//first try to find a suitable alpha character that isn't in use
for (var i = (int)('A'); i <= 'Z'; i++)
{
var s = new string(new char[] { (char)i });
if (!codes.Contains(s))
{
var to = new MMETestObjects(Guid.NewGuid().ToString(), s, NON_ISO_TESTOBJECT_NAME, NON_ISO_TESTOBJECT_NAME, 1,
DateTime.Now, "SYSTEM", false, "", DateTime.Now, "created", "", MMEPossibleChannels.MMEChannelTypes.SQL);
//ISO13499FileDb.IsoDb.Commit(to);
return to;
}
}
//didn't find one, now try for a suitable numeric character
for (var i = (int)'0'; i <= '9'; i++)
{
var s = new string(new char[] { (char)i });
if (!codes.Contains(s))
{
var to = new MMETestObjects(Guid.NewGuid().ToString(), s, NON_ISO_TESTOBJECT_NAME, NON_ISO_TESTOBJECT_NAME, 1,
DateTime.Now, "SYSTEM", false, "", DateTime.Now, "created", "", MMEPossibleChannels.MMEChannelTypes.SQL);
//(App.Current as App).IsoDb.Commit(to);
return to;
}
}
throw new NotSupportedException("Could not create system Non-ISO Group" /*Strings.StringResources.TestObjectTemplate_CouldNotCreateNONISOTESTOBJECT*/);
}
public ISO.TestObjectTemplate ToISOTestObjectTemplate()
{
var log = new System.Diagnostics.EventLog();
log.Source = "DataPROInstaller";
log.WriteEntry("Getting a new ISO.TestObjectTemplate using " + TemplateName);
var template = new ISO.TestObjectTemplate(TemplateName, IsLocalOnly);
log.WriteEntry("Got a new ISO.TestObjectTemplate");
template.Description = TemplateDescription;
log.WriteEntry("Set template.Description to " + TemplateDescription);
template.OriginalTemplateName = OriginalTemplateName;
log.WriteEntry("Set template.OriginalTemplateName to " + OriginalTemplateName);
template.Embedded = Embedded;
log.WriteEntry("Set template.Embedded to " + Embedded);
template.Icon = "";
log.WriteEntry("Set template.Icon to " + "");
template.LocalOnly = IsLocalOnly;
log.WriteEntry("Set LocalOnly to " + IsLocalOnly);
if (TestObject == null)
{
log.WriteEntry("TestObject is null");
}
else if (TestObject.Test_Object == null)
{
log.WriteEntry("TestObject.Test_Object is null");
}
log.WriteEntry("Setting template.TestObject to " + TestObject.Test_Object);
template.TestObject = TestObject.Test_Object;
log.WriteEntry("Set template.TestObject successfully");
template.TestObjectType = TestObjectType;
var zones = new List<TemplateZone>();
foreach (var zone in TemplateZones)
{
var isoZone = new TemplateZone(TemplateName, zone.Name, zone.GetPictureName(), zone.Description);
var zoneRegions = new List<TemplateRegion>();
var i = 0;
foreach (var region in zone.Regions)
{
var isoRegion = region.ToISORegion(this, zone, i++);
zoneRegions.Add(isoRegion);
}
isoZone.TemplateRegions = zoneRegions.ToArray();
zones.Add(isoZone);
}
template.TemplateParent = TemplateParent;
log.WriteEntry("Setting template.Channels to TemplateAllChannels");
template.Channels = TemplateAllChannels;
log.WriteEntry("Set template.Channels successfully");
template.Zones = zones.ToArray();
template.SysBuilt = SysBuilt;
log.WriteEntry("Returning");
return template;
}
private int CompareChannels(TestObjectTemplateChannel left, TestObjectTemplateChannel right)
{
if (left == right) { return 0; }
if (null == left) { return -1; }
if (null == right) { return 1; }
return left.DisplayOrder.CompareTo(right.DisplayOrder);
}
public TestObjectTemplate(TestObjectTemplate copy, ref ISO13499FileDb db)
{
if (null != copy._template) { _template = new ISO.TestObjectTemplate(copy._template, ref db); }
TemplateDescription = copy.TemplateDescription;
TemplateParent = copy.TemplateParent;
TemplateName = copy.TemplateName;
LastModified = copy.LastModified;
LastModifiedBy = copy.LastModifiedBy;
TestObject = copy.TestObject;
TestObjectType = copy.TestObjectType;
var channels = new List<TestObjectTemplateChannel>();
foreach (var c in copy.TemplateAllChannels)
{
channels.Add(new TestObjectTemplateChannel(c, /*ref db,*/ _template));
}
foreach (var c in copy.RequiredChannels)
{
RequiredChannels.Add(new TestObjectTemplateChannel(c, /*ref db,*/ _template));
}
TemplateAllChannels = channels.ToArray();
var zones = new List<Zone>();
foreach (var z in copy.TemplateZones)
{
zones.Add(new Zone(z.ISODllZone, this));
}
TemplateZones = zones.ToArray();
SysBuilt = copy.SysBuilt;
Embedded = copy.Embedded;
OriginalTemplateName = copy.OriginalTemplateName;
}
public TestObjectTemplate(ISO.TestObjectTemplate template, ref ISO13499FileDb db)
{
Initialize(template, ref db, null);
}
private void Initialize(ISO.TestObjectTemplate template, ref ISO13499FileDb db, List<MMETestObjects> testObjects)
{
_template = template;
TemplateDescription = template.Description;
TemplateName = template.TemplateName;
LastModified = template.LastModified;
LastModifiedBy = template.LastModifiedBy;
//if a list of test objects is provided, check if the test object we wish is in the list, if so use it
var bFoundTestObject = false;
if (null != testObjects)
{
var matches = from to in testObjects where to.Test_Object == template.TestObject select to;
if (matches.Count() > 0)
{
TestObject = matches.First();
bFoundTestObject = true;
}
}
if (!bFoundTestObject)
{
TestObject = (ISO13499FileDb.IsoDb.GetTestObjectByIso(template.TestObject));
}
TestObjectType = template.TestObjectType;
OriginalTemplateName = template.OriginalTemplateName;
Embedded = template.Embedded;
var channels = new List<TestObjectTemplateChannel>();
foreach (var c in template.Channels)
{
channels.Add(new TestObjectTemplateChannel(c, /*ref db,*/ _template));
}
TemplateAllChannels = channels.ToArray();
TemplateZones = template.Zones.Select(z => new Zone(z, this)).ToArray();
TemplateParent = template.TemplateParent;
SysBuilt = template.SysBuilt;
}
public TestObjectTemplate()
{
TemplateName = string.Empty;
TemplateDescription = string.Empty;
TemplateParent = string.Empty;
switch (SerializedSettings.ISOSupportLevel)
{
case SerializedSettings.ISOSupportLevels.ISO_ONLY:
TestObject = ISO13499FileDb.IsoDb.GetTestObjects(false).FirstOrDefault();
break;
case SerializedSettings.ISOSupportLevels.NO_ISO:
//need to create a template just for this object!
InitializeNonISO();
break;
case SerializedSettings.ISOSupportLevels.TRANSITORY:
TestObject = ISO13499FileDb.IsoDb.GetTestObjects(false).FirstOrDefault();
break;
}
}
private void InitializeNonISO()
{
//create template, set template channel type to NONISOTYPE
TemplateName = (Guid.NewGuid()).ToString();
TestObject = GetNonISOTestObject();
TestObjectType = NON_ISO_TESTOBJECT_CHANNEL_TYPE;
}
public Dictionary<string, string> GetValues()
{
var elementNameValuePairs = new Dictionary<string, string>();
var isoTemplate = ToISOTestObjectTemplate();
elementNameValuePairs[GroupTemplateFields.TemplateName.ToString()] = isoTemplate.TemplateName;
elementNameValuePairs[GroupTemplateFields.Icon.ToString()] = isoTemplate.Icon;
elementNameValuePairs[GroupTemplateFields.Description.ToString()] = isoTemplate.Description;
elementNameValuePairs[GroupTemplateFields.LocalOnly.ToString()] = isoTemplate.LocalOnly.ToString();
elementNameValuePairs[GroupTemplateFields.Version.ToString()] = isoTemplate.Version.ToString(System.Globalization.CultureInfo.InvariantCulture);
elementNameValuePairs[GroupTemplateFields.LastModifiedBy.ToString()] = /*isoTemplate.*/LastModifiedBy;
elementNameValuePairs[GroupTemplateFields.LastModified.ToString()] = /*isoTemplate.*/LastModified.ToString(System.Globalization.CultureInfo.InvariantCulture);
elementNameValuePairs[GroupTemplateFields.CRC32.ToString()] = isoTemplate.CRC32.ToString(System.Globalization.CultureInfo.InvariantCulture);
elementNameValuePairs[GroupTemplateFields.TestObjectType.ToString()] = isoTemplate.TestObjectType;
elementNameValuePairs[GroupTemplateFields.TestObject.ToString()] = isoTemplate.TestObject;
elementNameValuePairs[GroupTemplateFields.ParentTemplate.ToString()] = isoTemplate.TemplateParent;
elementNameValuePairs[GroupTemplateFields.SysBuilt.ToString()] = isoTemplate.SysBuilt.ToString();
elementNameValuePairs[GroupTemplateFields.OriginalTemplateName.ToString()] = isoTemplate.OriginalTemplateName;
elementNameValuePairs[GroupTemplateFields.Embedded.ToString()] = isoTemplate.Embedded.ToString(System.Globalization.CultureInfo.InvariantCulture);
return elementNameValuePairs;
}
public Dictionary<string, string> GetTemplateChannelValues(TestObjectTemplateChannel channel)
{
var elementNameValuePairs = new Dictionary<string, string>();
elementNameValuePairs[GroupTemplateChannelFields.TestObjectNumber.ToString()] = channel.TestObjectNumber;
elementNameValuePairs[GroupTemplateChannelFields.NameOfTheChannel.ToString()] = channel.NameOfTheChannel;
elementNameValuePairs[GroupTemplateChannelFields.LaboratoryChannelCode.ToString()] = channel.LaboratoryCode;
elementNameValuePairs[GroupTemplateChannelFields.CustomerChannelCode.ToString()] = channel.CustomerChannelCode;
elementNameValuePairs[GroupTemplateChannelFields.Comments1.ToString()] = channel.Comments2;
elementNameValuePairs[GroupTemplateChannelFields.Location.ToString()] = channel.Location;
elementNameValuePairs[GroupTemplateChannelFields.Dimension.ToString()] = channel.Dimension;
elementNameValuePairs[GroupTemplateChannelFields.Direction.ToString()] = channel.Direction;
elementNameValuePairs[GroupTemplateChannelFields.ChannelFrequencyClass.ToString()] = channel.ChannelFrequencyClass;
elementNameValuePairs[GroupTemplateChannelFields.Unit.ToString()] = channel.Unit;
elementNameValuePairs[GroupTemplateChannelFields.ReferenceSystem.ToString()] = channel.ReferenceSystem;
elementNameValuePairs[GroupTemplateChannelFields.TransducerType.ToString()] = channel.TransducerType;
elementNameValuePairs[GroupTemplateChannelFields.TransducerId.ToString()] = channel.TransducerId;
elementNameValuePairs[GroupTemplateChannelFields.PreFilterType.ToString()] = channel.PreFilterType;
elementNameValuePairs[GroupTemplateChannelFields.CutOffFrequency.ToString()] = channel.CutOffFrequency;
elementNameValuePairs[GroupTemplateChannelFields.ChannelAmplitudeClass.ToString()] = channel.ChannelAmplitudeClass;
elementNameValuePairs[GroupTemplateChannelFields.ReferenceChannel.ToString()] = channel.ReferenceChannel.ToString();
elementNameValuePairs[GroupTemplateChannelFields.ReferenceChannelName.ToString()] = channel.ReferenceChannelName;
elementNameValuePairs[GroupTemplateChannelFields.DataSource.ToString()] = channel.DataSource.ToString();
elementNameValuePairs[GroupTemplateChannelFields.DataStatus.ToString()] = channel.DataStatus.ToString();
elementNameValuePairs[GroupTemplateChannelFields.SamplingInterval.ToString()] = channel.SamplingInterval;
elementNameValuePairs[GroupTemplateChannelFields.BitResolution.ToString()] = channel.BitResolution;
elementNameValuePairs[GroupTemplateChannelFields.TimeOfFirstSample.ToString()] = channel.TimeOfFirstSample;
elementNameValuePairs[GroupTemplateChannelFields.NumberOfSamples.ToString()] = channel.NumberOfSamples;
elementNameValuePairs[GroupTemplateChannelFields.OffsetPostTest.ToString()] = channel.OffsetPostTest;
elementNameValuePairs[GroupTemplateChannelFields.TransducerNaturalFrequency.ToString()] = channel.TransducerNaturalFrequency;
elementNameValuePairs[GroupTemplateChannelFields.TransducerDampingRatio.ToString()] = channel.TransducerDampingRatio;
elementNameValuePairs[GroupTemplateChannelFields.Comments.ToString()] = channel.Comments1;
elementNameValuePairs[GroupTemplateChannelFields.FirstGlobalMaximumValue.ToString()] = channel.FirstGlobalMaximumValue;
elementNameValuePairs[GroupTemplateChannelFields.TimeOfMaximumValue.ToString()] = channel.TimeOfMaximumValue;
elementNameValuePairs[GroupTemplateChannelFields.FirstGlobalMinimumValue.ToString()] = channel.FirstGlobalMinimumValue;
elementNameValuePairs[GroupTemplateChannelFields.TimeOfMinimumValue.ToString()] = channel.TimeOfMinimumValue;
elementNameValuePairs[GroupTemplateChannelFields.StartOffsetInterval.ToString()] = channel.StartOffsetInterval;
elementNameValuePairs[GroupTemplateChannelFields.EndOffsetInterval.ToString()] = channel.EndOffsetInterval;
elementNameValuePairs[GroupTemplateChannelFields.MMEChannelId.ToString()] = channel.Channel.Id.ToString(System.Globalization.CultureInfo.InvariantCulture);
elementNameValuePairs[GroupTemplateChannelFields.MMEChannelType.ToString()] = channel.Channel.MMEChannelType.ToString(System.Globalization.CultureInfo.InvariantCulture);
elementNameValuePairs[GroupTemplateChannelFields.Required.ToString()] = channel.Required.ToString();
elementNameValuePairs[GroupTemplateChannelFields.DisplayOrder.ToString()] = channel.DisplayOrder.ToString(System.Globalization.CultureInfo.InvariantCulture);
elementNameValuePairs[GroupTemplateChannelFields.LocalOnly.ToString()] = channel.LocalOnly.ToString();
return elementNameValuePairs;
}
}
}

View File

@@ -0,0 +1,78 @@
using System;
using System.Collections.Generic;
using System.Data;
namespace DatabaseExport
{
public class TestObjectTemplateCollection
{
private static volatile TestObjectTemplateCollection _testObjectCollection;
public static TestObjectTemplateCollection TemplateCollection => _testObjectCollection ?? (_testObjectCollection = new TestObjectTemplateCollection());
public GroupTemplateTableInfo[] GetAllTemplates(bool bIncludeEmbeddedAndSysBuilt = true)
{
var templates = new List<GroupTemplateTableInfo>();
using (var sql = DbOperations.GetCommand())
{
if (bIncludeEmbeddedAndSysBuilt)
{
sql.CommandText =
"SELECT TemplateName, Description, LastModifiedBy, TestObjectType, LastModified, SysBuilt, Embedded from tblTestObjectTemplates";
}
else
{
sql.CommandText = "SELECT TemplateName, Description, LastModifiedBy, TestObjectType, LastModified, SysBuilt, Embedded from tblTestObjectTemplates WHERE (Embedded=0 OR Embedded is NULL) AND SysBuilt=0";
}
using (var ds = DbOperations.Connection.QueryDataSet(sql))
{
foreach (DataRow dr in ds.Tables[0].Rows)
{
var templateName = (string)dr["TemplateName"];
var templateDescription = (string)dr["Description"];
var lastModifiedBy = (string)dr["LastModifiedBy"];
var testObjectType = (string)dr["TestObjectType"];
var lastModified = Convert.ToDateTime(dr["LastModified"]);
var sysBuilt = Convert.ToBoolean(dr["SysBuilt"]);
var embeddedValue = dr["Embedded"];
var embedded = false;
if (!DBNull.Value.Equals(embeddedValue))
{
embedded = Convert.ToBoolean(dr["Embedded"]);
}
var isoSupportLevel =
(testObjectType.Contains(TestObjectTemplate.NON_ISO_TESTOBJECT_CHANNEL_TYPE) ||
testObjectType.Contains(TestObjectTemplateChannel.NONISOCHANNELTYPE))
? SerializedSettings.ISOSupportLevels.NO_ISO
: SerializedSettings.ISOSupportLevels.ISO_ONLY;
templates.Add(new GroupTemplateTableInfo(templateName, isoSupportLevel, sysBuilt,
templateDescription, lastModified, lastModifiedBy, embedded));
}
}
}
return templates.ToArray();
}
private static volatile TestObjectTemplate _sysBuiltTestObjectTemplate;
public TestObjectTemplate SysBuiltTestObjectTemplate => _sysBuiltTestObjectTemplate;
public TestObjectTemplate GetTemplate(string templateId)
{
//if (null == Application.Current) { return null; }
var db = ISO13499FileDb.IsoDb;
var template = ISO.TestObjectTemplate.GetTemplate(ref db, templateId);
if (null == template)
{
return new TestObjectTemplate();
}
else
{
return new TestObjectTemplate(template, ref db);
}
}
}
}

View File

@@ -0,0 +1,167 @@
using System;
using System.Collections.Generic;
namespace DatabaseExport
{
/// <summary>
/// this is a test object that belongs to a test, it's different in that it can have test specific settings ...
/// </summary>
public class TestTestObject : TestObject
{
public TestTestObject(TestObject obj)
: base(obj)
{
}
private string _position = ChannelDefaultsKey;
public MMEPositions Position
{
get => GetGroupPosition(_position);
set
{
SetProperty(ref _position, value.Position, "Position");
if (_position == UserSetKey)
{
GroupPositionComboBoxVisible = System.Windows.Visibility.Hidden;
GroupPositionButtonVisible = System.Windows.Visibility.Visible;
}
else
{
GroupPositionComboBoxVisible = System.Windows.Visibility.Visible;
GroupPositionButtonVisible = System.Windows.Visibility.Hidden;
//set the position for every sensor in the test object using this position
var isoTO = GetISOTestObject();
foreach (var ch in isoTO.AllChannels)
{
if (!ch.Required) { continue; }
if (string.IsNullOrWhiteSpace(ch.SensorSerialNumber)) { continue; }
var sd = GetSensor(ch.Name, ch.SensorSerialNumber); // now using ch.Name instead of ch.GetID(); FB 7391 - Group sensor settings not in test when you set the test obj. and position.
if (null == sd) { continue; }
sd.Position = value.Position;
SetSensor(ch.GetID(), sd);
}
}
}
}
public const string ChannelDefaultsKey = "#";
public const string UserSetKey = "@";
private MMEPositions GetGroupPosition(string groupPositionKey)
{
foreach (var position in AvailableGroupPositions)
{
if (position.Position == groupPositionKey)
{
return position;
}
}
return _userSetGUID;
}
private System.Windows.Visibility _groupPositionComboBoxVisible = System.Windows.Visibility.Visible;
public System.Windows.Visibility GroupPositionComboBoxVisible
{
get
{
if (_groupPositionComboBoxVisible == System.Windows.Visibility.Visible)
{
if (SerializedSettings.ISOSupportLevel == SerializedSettings.ISOSupportLevels.NO_ISO) { return System.Windows.Visibility.Collapsed; }
return _groupPositionComboBoxVisible;
}
return _groupPositionComboBoxVisible;
}
set => _groupPositionComboBoxVisible = value;
}
private System.Windows.Visibility _groupPositionButtonVisible = System.Windows.Visibility.Hidden;
public System.Windows.Visibility GroupPositionButtonVisible
{
get
{
if (_groupPositionButtonVisible == System.Windows.Visibility.Visible)
{
if (SerializedSettings.ISOSupportLevel == SerializedSettings.ISOSupportLevels.NO_ISO) { return System.Windows.Visibility.Collapsed; }
return _groupPositionButtonVisible;
}
return _groupPositionButtonVisible;
}
set => _groupPositionButtonVisible = value;
}
private string _testObject = "?";
public MMETestObjects TestObject
{
get => ISO13499FileDb.IsoDb.GetTestObjectByIso(_testObject);
set
{
if (value == null) return;
SetProperty(ref _testObject, value.Test_Object, "TestObject");
//also set the test object for all sensors!
var isoTO = GetISOTestObject();
foreach (var ch in isoTO.AllChannels)
{
if (!ch.Required) { continue; }
if (string.IsNullOrWhiteSpace(ch.SensorSerialNumber)) { continue; }
var sd = GetSensor(ch.GetID(), ch.SensorSerialNumber);
if (null == sd) { continue; }
sd.TestObject = value.Test_Object;
SetSensor(ch.GetID(), sd);
}
}
}
public void SetTestObject(string s)
{
_testObject = s;
OnPropertyChanged("TestObject");
}
public void SetPosition(string s)
{
_position = s;
OnPropertyChanged("Position");
if (s == UserSetKey)
{
GroupPositionComboBoxVisible = System.Windows.Visibility.Hidden;
GroupPositionButtonVisible = System.Windows.Visibility.Visible;
}
else
{
GroupPositionComboBoxVisible = System.Windows.Visibility.Visible;
GroupPositionButtonVisible = System.Windows.Visibility.Hidden;
}
}
public MMEPositions[] AvailablePositions => ISO13499FileDb.IsoDb.GetPositions();
private const string DATAPRO_DEFINED = "DataPRO-defined";
public static MMEPositions _channelDefaultsGUID = new MMEPositions(Guid.NewGuid().ToString(), ChannelDefaultsKey, "(channel defaults)", "(channel defaults)", 1, DateTime.Now, DATAPRO_DEFINED, false, "", DateTime.Now,
DATAPRO_DEFINED, "", MMEPossibleChannels.MMEChannelTypes.ISO13499_106);
private MMEPositions _userSetGUID = new MMEPositions(Guid.NewGuid().ToString(), UserSetKey, "(multiple)", "(multiple)", 1, DateTime.Now, DATAPRO_DEFINED, false, "", DateTime.Now,
DATAPRO_DEFINED, "", MMEPossibleChannels.MMEChannelTypes.ISO13499_106);
public MMEPositions[] AvailableGroupPositions
{
get
{
var availableGroupPositions = new List<MMEPositions>();
availableGroupPositions.Add(_channelDefaultsGUID);
foreach (var position in AvailablePositions)
{
availableGroupPositions.Add(position);
}
return availableGroupPositions.ToArray();
}
}
private int _excitationWarmupTime = Properties.Settings.Default.DefaultTestExcitationWarmupMS;
public int ExcitationWarmupTimeMS
{
get => _excitationWarmupTime;
set => SetProperty(ref _excitationWarmupTime, value, "ExcitationWarmupTimeMS");
}
private double _targetSampleRate;
public double TargetSampleRate
{
get => _targetSampleRate;
set => SetProperty(ref _targetSampleRate, value, "TargetSampleRate");
}
}
}

View File

@@ -0,0 +1,26 @@
namespace DatabaseExport
{
/// <summary>
/// we will want to remove or add hardware overriding what hardware would be in the test
/// based solely on groups in the test
/// this way we can have dasless groups
/// </summary>
public class HardwareInclusionInstruction
{
public string HardwareId { get; }
public enum Actions
{
Remove, //hardware may be included in test by a group, but ignore it and don't include the hardware...
Add //hardware is not included in test by a group, but add it anyhow
}
public Actions Action { get; }
public HardwareInclusionInstruction(string hardwareId, Actions action)
{
HardwareId = hardwareId;
Action = action;
}
}
}

View File

@@ -0,0 +1,509 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Globalization;
using System.Linq;
using System.Text;
namespace DatabaseExport
{
public class TestTemplateList //: BindableBase
{
/// <summary>
/// this property is to hold a template in memory temporarily
/// without committing it to the db, but to still act as if it is in the db
/// </summary>
public TestTemplate TemporaryTemplate { get; set; }
protected TestTemplateList() { }
public TestTemplate GetTemplate(string name)
{
if (name == "Quick checkout") // StringResources.QuickSensorCheck_DefaultTestName)
{
return TemporaryTemplate;
}
if (string.IsNullOrWhiteSpace(name)) { return null; }
try
{
using (var cmd = DbOperations.GetCommand())
{
cmd.CommandText = string.Format("SELECT * FROM [{0}] WHERE [{1}]=@1",
DbOperations.TestSetups.TestSetupsTable, DbOperations.TestSetups.Fields.SetupName);
DbOperations.CreateParam(cmd, "@1", SqlDbType.NVarChar, name);
using (var ds = DbOperations.Connection.QueryDataSet(cmd))
{
if (ds.Tables.Count <= 0 || ds.Tables[0].Rows.Count <= 0) return null;
var dr = ds.Tables[0].Rows[0];
var tt = new TestTemplate();
tt.SetTimeStampMemory(dr);
//make sure this template is marked as unloaded, because we
//are only going to load the essentials here...
tt._bIsLoaded = false;
var fields =
Enum.GetValues(typeof(DbOperations.TestSetups.Fields))
.Cast<DbOperations.TestSetups.Fields>()
.ToArray();
foreach (var field in fields)
{
try
{
if (DBNull.Value.Equals(dr[field.ToString()]))
{
continue;
}
var o = dr[field.ToString()];
#region DbOperations.TestSetups.Fields
switch (field)
{
case DbOperations.TestSetups.Fields.AllowMissingSensors:
tt.AllowMissingSensors = Convert.ToBoolean(o);
break;
case DbOperations.TestSetups.Fields.AllowSensorIdToBlankChannel:
tt.AllowSensorIdToBlankChannel = Convert.ToBoolean(o);
break;
case DbOperations.TestSetups.Fields.AutomaticProgressionDelayMS:
tt.AutomaticProgressionDelayMS = Convert.ToInt32(o);
break;
case DbOperations.TestSetups.Fields.AutomaticTestProgression:
tt.AutomaticProgression = Convert.ToBoolean(o);
break;
case DbOperations.TestSetups.Fields.AutoVerifyChannels:
tt.AutoVerifyChannels = Convert.ToBoolean(o);
break;
case DbOperations.TestSetups.Fields.CommonStatusLine:
tt.CommonLine = Convert.ToBoolean(o);
break;
case DbOperations.TestSetups.Fields.UploadData:
tt.UploadData = Convert.ToBoolean(o);
break;
case DbOperations.TestSetups.Fields.UploadDataFolder:
tt.UploadFolder = Convert.ToString(o);
break;
case DbOperations.TestSetups.Fields.CustomerDetails:
tt.CustomerDetails =
CustomerDetailsList.CustomerList.GetCustomerDetail(Convert.ToString(o));
break;
case DbOperations.TestSetups.Fields.TestEngineerDetails:
tt.TestEngineerDetails =
TestEngineerDetailsList.TestEngineerList.GetTestEngineerDetail(
Convert.ToString(o));
break;
case DbOperations.TestSetups.Fields.DownloadAll:
tt.DownloadAll = Convert.ToBoolean(o);
break;
case DbOperations.TestSetups.Fields.DownloadFolder:
tt.DownloadFolder = Properties.Settings.Default.DownloadFolder;
// Convert.ToString(o);
break;
case DbOperations.TestSetups.Fields.Export:
tt.ViewExport = Convert.ToBoolean(o);
break;
case DbOperations.TestSetups.Fields.ExportFolder:
tt.ExportFolder = Properties.Settings.Default.DownloadFolder;
//Convert.ToString(o);
break;
case DbOperations.TestSetups.Fields.ExportFormat:
tt.ExportFormats = (SupportedExportFormatBitFlags)Convert.ToUInt64(o);
break;
case DbOperations.TestSetups.Fields.InvertStart:
tt.InvertStartRecordCompletion = Convert.ToBoolean(o);
break;
case DbOperations.TestSetups.Fields.TriggerCheckRealtime:
tt.TriggerCheckRealtime = Convert.ToBoolean(o);
break;
case DbOperations.TestSetups.Fields.TriggerCheckStep:
tt.TriggerCheckStep = Convert.ToBoolean(o);
break;
case DbOperations.TestSetups.Fields.PostTestDiagnostics:
tt.PostTestDiagnosticsLevel = (0 != Convert.ToInt32(o));
break;
case DbOperations.TestSetups.Fields.InvertTrigger:
tt.InvertTriggerCompletion = Convert.ToBoolean(o);
break;
case DbOperations.TestSetups.Fields.LabDetails:
tt.LabDetails = LabratoryDetailsList.LabratoryList.GetLab(Convert.ToString(o));
break;
case DbOperations.TestSetups.Fields.LastModified:
tt.LastModified = Convert.ToDateTime(o);
break;
case DbOperations.TestSetups.Fields.LastModifiedBy:
tt.LastModifiedBy = Convert.ToString(o);
break;
case DbOperations.TestSetups.Fields.LocalOnly:
tt.LocalOnly = Convert.ToBoolean(o);
break;
case DbOperations.TestSetups.Fields.PostTriggerSeconds:
tt.PostTriggerSeconds = Convert.ToDouble(o);
break;
case DbOperations.TestSetups.Fields.PreTriggerSeconds:
tt.PreTriggerSeconds = Convert.ToDouble(o);
break;
case DbOperations.TestSetups.Fields.RealtimePlotCount:
tt.DefaultNumberRealtimeGraphs = Convert.ToInt32(o);
break;
case DbOperations.TestSetups.Fields.RecordingMode:
tt.RecordingMode = (RecordingModes)Convert.ToInt32(o);
break;
case DbOperations.TestSetups.Fields.RequireConfirmationOnErrors:
tt.RequireUserConfirmationOnErrors = Convert.ToBoolean(o);
break;
case DbOperations.TestSetups.Fields.ROIDownload:
tt.DoROIDownload = Convert.ToBoolean(o);
break;
case DbOperations.TestSetups.Fields.ROIEnd:
tt.ROIEnd = Convert.ToDouble(o);
break;
case DbOperations.TestSetups.Fields.ROIStart:
tt.ROIStart = Convert.ToDouble(o);
break;
case DbOperations.TestSetups.Fields.SameAsDownloadFolder:
tt.SameAsDownloadFolder = Convert.ToBoolean(o);
break;
case DbOperations.TestSetups.Fields.SamplesPerSecond:
tt.SamplesPerSecond = Convert.ToDouble(o);
break;
case DbOperations.TestSetups.Fields.Settings:
tt.LoadSettings(Convert.ToString(o));
break;
case DbOperations.TestSetups.Fields.WarnOnBatteryFail:
tt.WarnOnFailedBattery = Convert.ToBoolean(o);
break;
case DbOperations.TestSetups.Fields.SetupDescription:
tt.Description = Convert.ToString(o);
break;
case DbOperations.TestSetups.Fields.SetupName:
tt.Name = Convert.ToString(o);
break;
case DbOperations.TestSetups.Fields.StrictDiagnostics:
tt.StrictDiagnostics = (Convert.ToInt32(o)) != 0;
break;
case DbOperations.TestSetups.Fields.UseCustomerDetails:
tt.UseCustomerDetails = Convert.ToBoolean(o);
break;
case DbOperations.TestSetups.Fields.UseTestEngineerDetails:
tt.UseTestEngineerDetails = Convert.ToBoolean(o);
break;
case DbOperations.TestSetups.Fields.TurnOffExcitation:
tt.TurnOffExcitation = Convert.ToBoolean(o);
break;
case DbOperations.TestSetups.Fields.UseLabDetails:
tt.UseLabratoryDetails = Convert.ToBoolean(o);
break;
case DbOperations.TestSetups.Fields.VerifyChannels:
tt.VerifyChannels = Convert.ToBoolean(o);
break;
case DbOperations.TestSetups.Fields.VerifyChannelsDelayMS:
tt.AutoVerifyDelaySeconds = Convert.ToDouble(o) / 1000D;
break;
case DbOperations.TestSetups.Fields.ViewDiagnostics:
tt.ViewDiagnostics = Convert.ToBoolean(o);
break;
case DbOperations.TestSetups.Fields.ViewDownloadAll:
tt.ViewDownloadAll = Convert.ToBoolean(o);
break;
case DbOperations.TestSetups.Fields.ViewRealtime:
tt.ViewRealtime = Convert.ToBoolean(o);
break;
case DbOperations.TestSetups.Fields.ViewROIDownload:
tt.ViewROIDownload = Convert.ToBoolean(o);
break;
case DbOperations.TestSetups.Fields.Dirty:
tt.SetIsDirty(Convert.ToBoolean(o));
break;
case DbOperations.TestSetups.Fields.Complete:
tt.SetIsComplete(Convert.ToBoolean(o));
break;
case DbOperations.TestSetups.Fields.ISFFile:
tt.ISFFile = Convert.ToString(o);
break;
case DbOperations.TestSetups.Fields.ErrorMessage:
tt.SetCompletionErrorMessage(Convert.ToString(o));
break;
case DbOperations.TestSetups.Fields.CheckoutMode:
tt.CheckoutMode = Convert.ToBoolean(o);
break;
case DbOperations.TestSetups.Fields.QuitTestWithoutWarning:
tt.QuitTestWithoutWarning = Convert.ToBoolean(o);
break;
case DbOperations.TestSetups.Fields.SuppressMissingSensorsWarning:
tt.SuppressMissingSensorsWarning = Convert.ToBoolean(o);
break;
case DbOperations.TestSetups.Fields.NotAllChannelsRealTime:
tt.NotAllChannelsRealTime = Convert.ToBoolean(o);
break;
case DbOperations.TestSetups.Fields.NotAllChannelsViewer:
tt.NotAllChannelsViewer = Convert.ToBoolean(o);
break;
case DbOperations.TestSetups.Fields.UserTags:
tt.TagsBlobBytes = (byte[])o;
break;
case DbOperations.TestSetups.Fields.DoAutoArm:
tt.DoAutoArm = Convert.ToBoolean(o);
break;
case DbOperations.TestSetups.Fields.DoStreaming:
tt.DoStreaming = Convert.ToBoolean(o);
break;
}
#endregion DbOperations.TestSetups.Fields
}
catch (Exception)
{
//APILogger.Log("Failed to process: ", field.ToString(), ex);
}
}
return tt;
}
}
}
catch (Exception)
{
//APILogger.Log(ex);
}
return null;
}
public static SensorData GetSensorFromSettings(string settings, string serial, Dictionary<string, SensorData> lookup)
{
SensorData sd = null;
if (null != lookup && lookup.ContainsKey(serial)) { sd = lookup[serial]; }
if (null == sd) { sd = SensorsCollection.SensorsList.GetSensorBySerialNumber(serial); }
if (string.IsNullOrWhiteSpace(serial))
{
sd = new SensorData { SerialNumber = "" };
}
if (null == sd) { return null; }
sd = new SensorData(sd);
var tokens = settings.Split(',');
foreach (var token in tokens)
{
var subtokens = token.Split('=');
var setting = (ISO.TestObject.SensorSettings)int.Parse(subtokens[0]);
switch (setting)
{
case ISO.TestObject.SensorSettings.CFC:
sd.FilterClassIso = subtokens[1];
break;
case ISO.TestObject.SensorSettings.Position:
sd.Position = subtokens[1];
break;
case ISO.TestObject.SensorSettings.Polarity:
sd.Invert = subtokens[1] == "-";
break;
case ISO.TestObject.SensorSettings.Range:
sd.Capacity = double.Parse(subtokens[1], CultureInfo.InvariantCulture);
break;
case ISO.TestObject.SensorSettings.Delay:
if (!string.IsNullOrWhiteSpace(subtokens[1])) { sd.DelayMS = double.Parse(subtokens[1], CultureInfo.InvariantCulture); sd.DigitalOutputDelayMS = sd.DelayMS; }
break;
case ISO.TestObject.SensorSettings.Duration:
if (!string.IsNullOrWhiteSpace(subtokens[1])) { sd.DurationMS = double.Parse(subtokens[1], CultureInfo.InvariantCulture); sd.DigitalOutputDurationMS = sd.DurationMS; }
break;
case ISO.TestObject.SensorSettings.OutputMode:
if (!string.IsNullOrWhiteSpace(subtokens[1])) { sd.DigitalOutputMode = (OutputTOMDigitalChannel.DigitalOutputMode)Convert.ToInt32(subtokens[1]); }
break;
case ISO.TestObject.SensorSettings.SQMode:
if (!string.IsNullOrWhiteSpace(subtokens[1])) { sd.SquibFireMode = (OutputSquibChannel.SquibFireMode)Convert.ToInt32(subtokens[1]); }
break;
case ISO.TestObject.SensorSettings.DIMode:
if (!string.IsNullOrWhiteSpace(subtokens[1])) { sd.InputMode = (DigitalInputScaleMultiplier.InputModes)Convert.ToInt32(subtokens[1]); }
break;
case ISO.TestObject.SensorSettings.LimitDuration:
if (!string.IsNullOrWhiteSpace(subtokens[1])) { sd.LimitDuration = bool.Parse(subtokens[1]); }
break;
case ISO.TestObject.SensorSettings.ActiveValue:
if (!string.IsNullOrWhiteSpace(subtokens[1])) { sd.ScaleMultiplier.ActiveValue = Convert.ToDouble(subtokens[1]); }
break;
case ISO.TestObject.SensorSettings.DefaultValue:
if (!string.IsNullOrWhiteSpace(subtokens[1])) { sd.ScaleMultiplier.DefaultValue = Convert.ToDouble(subtokens[1]); }
break;
}
}
return sd;
}
public static SensorData GetSensorFromSettings(string settings, string serial)
{
return GetSensorFromSettings(settings, serial, null);
}
public static string GetSensorSettings(SensorData sd)
{
var sb = new StringBuilder();
var settings = Enum.GetValues(typeof(ISO.TestObject.SensorSettings)).Cast<ISO.TestObject.SensorSettings>().ToArray();
var bNeedComma = false;
foreach (var setting in settings)
{
if (bNeedComma) { sb.Append(","); }
bNeedComma = true;
sb.AppendFormat("{0}=", (int)setting);
switch (setting)
{
case ISO.TestObject.SensorSettings.CFC:
sb.Append(sd.FilterClassIso);
break;
case ISO.TestObject.SensorSettings.Position:
sb.Append(sd.Position);
break;
case ISO.TestObject.SensorSettings.Polarity:
sb.Append(sd.Invert ? "-" : "+");
break;
case ISO.TestObject.SensorSettings.Range:
sb.Append(sd.Capacity.ToString(CultureInfo.InvariantCulture));
break;
case ISO.TestObject.SensorSettings.SQMode:
sb.Append(((int)sd.SquibFireMode).ToString(CultureInfo.InvariantCulture));
break;
case ISO.TestObject.SensorSettings.LimitDuration:
sb.Append(sd.LimitDuration.ToString(CultureInfo.InvariantCulture));
break;
case ISO.TestObject.SensorSettings.Duration:
sb.Append(sd.DurationMS.ToString(CultureInfo.InvariantCulture));
break;
case ISO.TestObject.SensorSettings.OutputMode:
sb.Append(((int)sd.DigitalOutputMode).ToString(CultureInfo.InvariantCulture));
break;
case ISO.TestObject.SensorSettings.Delay:
sb.Append(sd.DelayMS.ToString(CultureInfo.InvariantCulture));
break;
case ISO.TestObject.SensorSettings.DIMode:
sb.Append(((int)sd.InputMode).ToString(CultureInfo.InvariantCulture));
break;
case ISO.TestObject.SensorSettings.DefaultValue:
sb.Append(sd.ScaleMultiplier.DefaultValue.ToString(CultureInfo.InvariantCulture));
break;
case ISO.TestObject.SensorSettings.ActiveValue:
sb.Append(
sd.ScaleMultiplier.ActiveValue.ToString(CultureInfo.InvariantCulture));
break;
}
}
return sb.ToString();
}
private static TestTemplateList _list;
private static readonly object ObjectLock = new object();
public static TestTemplateList TestTemplatesList
{
get
{
lock (ObjectLock)
{
if (null == _list) { _list = new TestTemplateList(); }
}
return _list;
}
}
public static bool SysBuiltObject(string serialNumber)
{
var temp = false;
using (var cmd = DbOperations.GetCommand())
{
cmd.CommandText = string.Format("SELECT * FROM [tblTestObjects] where [SerialNumber]=@{0}", "SerialNumber");
DbOperations.CreateParam(cmd, string.Format("@{0}", "SerialNumber"), SqlDbType.NVarChar, serialNumber);
using (var ds2 = DbOperations.Connection.QueryDataSet(cmd))
{
if (ds2.Tables.Count <= 0 || ds2.Tables[0].Rows.Count <= 0) return false;
foreach (DataRow row in ds2.Tables[0].Rows)
{
//really only 1 row
temp = Convert.ToBoolean(row["SysBuilt"]);
}
}
}
return temp;
}
public static void ConvertToDictionary(DataTable dt, ref Dictionary<string, List<Dictionary<string, object>>> lookup, string key)
{
var count = dt.Columns.Count;
foreach (DataRow dr in dt.Rows)
{
var thiskey = Convert.ToString(dr[key]);
if (!lookup.ContainsKey(thiskey)) { lookup.Add(thiskey, new List<Dictionary<string, object>>()); }
var properties = new Dictionary<string, object>(count);
foreach (DataColumn c in dt.Columns)
{
properties[c.ColumnName] = dr[c.ColumnName];
}
lookup[thiskey].Add(properties);
}
}
public TestTemplateTableObject[] GetAllTemplates()
{
var objects = new List<TestTemplateTableObject>();
using (var cmd = DbOperations.GetCommand())
{
cmd.CommandText =
"SELECT SetupName, SetupDescription, RecordingMode, Dirty, Complete, LastModified, LastModifiedBy, ErrorMessage, CustomerDetails, UseCustomerDetails, UserTags FROM tblTestSetups";
using (var ds = DbOperations.Connection.QueryDataSet(cmd))
{
foreach (DataRow dr in ds.Tables[0].Rows)
{
try
{
var setupName = (string)dr["SetupName"];
var setupDescription = (string)dr["SetupDescription"];
var recordingMode = Convert.ToInt32(dr["RecordingMode"]);
var dirty = Convert.ToBoolean(dr["Dirty"]);
var complete = Convert.ToBoolean(dr["Complete"]);
var lastModified = Convert.ToDateTime(dr["LastModified"]);
var lastModifiedBy = (string)dr["LastModifiedBy"];
var errorMessage = Convert.ToString(dr["ErrorMessage"]);
var customerDetails = (string)dr["CustomerDetails"];
var useCustomerDetails = Convert.ToBoolean(dr["UseCustomerDetails"]);
var tagBlobObj = dr["UserTags"];
byte[] tagBlob = null;
int[] tagIds = null;
if (DBNull.Value.Equals(tagBlobObj))
{
tagBlob = new byte[0];
tagIds = new int[0];
}
else
{
tagBlob = (byte[])dr["UserTags"];
tagIds = GetTagIds(tagBlob);
}
if (dirty)
{
var tt = TestTemplatesList.GetTemplate(setupName);
complete = tt.IsComplete;
}
objects.Add(new TestTemplateTableObject(setupName, setupDescription,
(RecordingModes)recordingMode, lastModified, lastModifiedBy, complete,
errorMessage, useCustomerDetails, customerDetails, tagIds));
}
catch (Exception)
{
//APILogger.Log(ex);
}
}
}
}
return objects.ToArray();
}
private int[] GetTagIds(byte[] bytes)
{
var tagsBlob = new int[bytes.Length / sizeof(int)];
try
{
Buffer.BlockCopy(bytes, 0, tagsBlob, 0, bytes.Length);
return tagsBlob;
}
catch (Exception)
{
//APILogger.Log(ex);
}
return new int[0];
}
}
}

View File

@@ -0,0 +1,43 @@
using System;
namespace DatabaseExport
{
/// <summary>
/// this is a lightweight version of test TestTemplate, holding just the essential information
/// [updated]: this concept is already present in testtemplate,
/// by default it only loads information in the tblTestSetup, and then uses the IsLoaded flag to
/// check whether it's populated information from other tables or not.
/// I'll leave the class here for now in case we want to expand on it in the future, also I cleaned up a few things in the process anyhow
/// </summary>
public class TestTemplateLite
{
public string Name { get; set; }
public string Description { get; set; } = "";
public RecordingModes RecordingMode { get; set; }
private double _preTriggerSeconds;
public double PreTriggerSeconds
{
get
{
switch (RecordingMode)
{
case RecordingModes.Recorder:
case RecordingModes.HybridRecorder:
return 0D;
case RecordingModes.CircularBuffer:
return _preTriggerSeconds;
default:
return _preTriggerSeconds;
}
}
set => _preTriggerSeconds = value;
}
public double PostTriggerSeconds { get; set; }
public DateTime LastModified { get; set; }
public string LastModifiedBy { get; set; }
public bool IsComplete { get; set; }
}
}

View File

@@ -0,0 +1,45 @@
using System;
namespace DatabaseExport
{
/// <summary>
/// this is a simplified class to represent a row in the tblTestTemplates table for tables
/// it was designed as a short term alternative to TestTempalte itself
/// </summary>
public class TestTemplateTableObject
{
public TestTemplateTableObject(string name,
string description,
RecordingModes recordingMode,
DateTime lastModified,
string lastModifiedBy,
bool isComplete,
string completionErrorMessage,
bool useCustomerDetails,
string customerDetails,
int[] tagIds)
{
Name = name;
Description = description;
RecordingMode = recordingMode;
LastModified = lastModified;
LastModifiedBy = lastModifiedBy;
IsComplete = isComplete;
CompletionErrorMessage = completionErrorMessage;
UseCustomerDetails = useCustomerDetails;
CustomerDetails = customerDetails;
TagIds = tagIds;
}
public string Name { get; private set; }
public string Description { get; private set; }
public RecordingModes RecordingMode { get; private set; }
public DateTime LastModified { get; private set; }
public string LastModifiedBy { get; private set; }
public bool IsComplete { get; private set; }
public string CompletionErrorMessage { get; private set; }
public bool UseCustomerDetails { get; private set; }
public string CustomerDetails { get; private set; }
public int[] TagIds { get; private set; }
}
}