init
This commit is contained in:
@@ -0,0 +1,768 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
|
||||
namespace DatabaseImport
|
||||
{
|
||||
public abstract class SensorBase : TagAwareBase
|
||||
{
|
||||
public int CompareTo(SensorModel rhs)
|
||||
{
|
||||
if (null == Model) { Model = ""; }
|
||||
if (null == rhs.Model) { rhs.Model = ""; }
|
||||
return Model.CompareTo(rhs.Model);
|
||||
}
|
||||
|
||||
public virtual bool IsDigitalInput() { return Bridge == Test.Module.Channel.Sensor.BridgeType.DigitalInput; }
|
||||
|
||||
public virtual bool IsDigitalOutput() { return Bridge == Test.Module.Channel.Sensor.BridgeType.TOMDigital; }
|
||||
public virtual bool IsSquib() { return Bridge == Test.Module.Channel.Sensor.BridgeType.SQUIB; }
|
||||
protected bool _checkOffset = true;
|
||||
public bool CheckOffset
|
||||
{
|
||||
get => _checkOffset;
|
||||
set => SetProperty(ref _checkOffset, value, "CheckOffset");
|
||||
}
|
||||
|
||||
|
||||
protected bool _measureNoise = true;
|
||||
public bool MeasureNoise
|
||||
{
|
||||
get => _measureNoise;
|
||||
set => SetProperty(ref _measureNoise, value, "MeasureNoise");
|
||||
}
|
||||
|
||||
protected bool _measureExcitation = true;
|
||||
public bool MeasureExcitation
|
||||
{
|
||||
get => _measureExcitation;
|
||||
set => SetProperty(ref _measureExcitation, value, "MeasureExcitation");
|
||||
}
|
||||
|
||||
protected bool _invert = false;
|
||||
public bool Invert
|
||||
{
|
||||
get => _invert;
|
||||
set => SetProperty(ref _invert, value, "Invert");
|
||||
}
|
||||
|
||||
protected string _Model = "";
|
||||
public string Model
|
||||
{
|
||||
get => _Model;
|
||||
set => SetProperty(ref _Model, value, "Model");
|
||||
}
|
||||
|
||||
protected string _Manufacturer = "";
|
||||
public string Manufacturer
|
||||
{
|
||||
get => _Manufacturer;
|
||||
set => SetProperty(ref _Manufacturer, value, "Manufacturer");
|
||||
}
|
||||
|
||||
protected string _UserPartNumber = "";
|
||||
public string UserPartNumber
|
||||
{
|
||||
get => _UserPartNumber;
|
||||
set => SetProperty(ref _UserPartNumber, value, "UserPartNumber");
|
||||
}
|
||||
|
||||
protected double _Capacity = 2400D;
|
||||
public double Capacity
|
||||
{
|
||||
get => _Capacity;
|
||||
set => SetProperty(ref _Capacity, value, "Capacity");
|
||||
}
|
||||
protected CouplingModes _couplingMode = CouplingModes.AC;
|
||||
public CouplingModes CouplingMode
|
||||
{
|
||||
get => _couplingMode;
|
||||
set => SetProperty(ref _couplingMode, value, "CouplingMode");
|
||||
}
|
||||
|
||||
protected LowHigh _OffsetTolerance = new LowHigh(-100D, 100D);
|
||||
public double OffsetToleranceLow
|
||||
{
|
||||
get => _OffsetTolerance.Low;
|
||||
set { _OffsetTolerance.Low = value; OnPropertyChanged("OffsetToleranceLow"); }
|
||||
}
|
||||
public double OffsetToleranceHigh
|
||||
{
|
||||
get => _OffsetTolerance.High;
|
||||
set { _OffsetTolerance.High = value; OnPropertyChanged("OffsetToleranceHigh"); }
|
||||
}
|
||||
|
||||
protected string _DisplayUnit = "";
|
||||
public virtual string DisplayUnit
|
||||
{
|
||||
get => _DisplayUnit;
|
||||
set => SetProperty(ref _DisplayUnit, value, SensorBaseFields.MeasurementUnit.ToString());
|
||||
}
|
||||
protected SensorRange _Range = new SensorRange(10D, 100D, 1000D);
|
||||
public double RangeLow
|
||||
{
|
||||
get => 0 == _Range.Low ? Capacity : _Range.Low;
|
||||
set { _Range.Low = value; OnPropertyChanged("RangeLow"); }
|
||||
}
|
||||
public double RangeMedium
|
||||
{
|
||||
get => 0 == _Range.Medium ? Capacity : _Range.Medium;
|
||||
set { _Range.Medium = value; OnPropertyChanged("RangeMedium"); }
|
||||
}
|
||||
public double RangeHigh
|
||||
{
|
||||
get => 0 == _Range.High ? Capacity : _Range.High;
|
||||
set { _Range.High = value; OnPropertyChanged("RangeHigh"); }
|
||||
}
|
||||
|
||||
protected List<ExcitationVoltageOptions.ExcitationVoltageOption> _supportedExcitation = new List<ExcitationVoltageOptions.ExcitationVoltageOption>(
|
||||
new[] { ExcitationVoltageOptions.ExcitationVoltageOption.Volt5 });
|
||||
public ExcitationVoltageOptions.ExcitationVoltageOption[] SupportedExcitation
|
||||
{
|
||||
get => _supportedExcitation.ToArray();
|
||||
set => SetProperty(ref _supportedExcitation, new List<ExcitationVoltageOptions.ExcitationVoltageOption>(value), "SupportedExcitation");
|
||||
}
|
||||
protected SensorCalibration _calibration = new SensorCalibration();
|
||||
/// <summary>
|
||||
/// sensor models shouldn't have a cal date, but this is the min cal date we can use and not cause problems unintentionally somewhere else
|
||||
/// </summary>
|
||||
public virtual SensorCalibration Calibration
|
||||
{
|
||||
get => _calibration;
|
||||
set => SetProperty(ref _calibration, value, "Calibration");
|
||||
}
|
||||
|
||||
protected Test.Module.Channel.Sensor.BridgeType _Bridge = Test.Module.Channel.Sensor.BridgeType.FullBridge;
|
||||
public Test.Module.Channel.Sensor.BridgeType Bridge
|
||||
{
|
||||
get => _Bridge;
|
||||
set => SetProperty(ref _Bridge, value, "Bridge");
|
||||
}
|
||||
|
||||
protected ShuntMode _Shunt = ShuntMode.Emulation;
|
||||
public ShuntMode Shunt
|
||||
{
|
||||
get => _Shunt;
|
||||
set => SetProperty(ref _Shunt, value, "Shunt");
|
||||
}
|
||||
|
||||
protected double _BridgeResistance = 350D;
|
||||
|
||||
public double BridgeResistance
|
||||
{
|
||||
get => _BridgeResistance;
|
||||
set => SetProperty(ref _BridgeResistance, value, "BridgeResistance");
|
||||
}
|
||||
|
||||
protected FilterClass _Filter = new FilterClass(FilterClass.FilterClassType.CFC1000);
|
||||
public FilterClass Filter
|
||||
{
|
||||
get => _Filter;
|
||||
set => SetProperty(ref _Filter, value, "Filter");
|
||||
}
|
||||
protected bool _UniPolar = false;
|
||||
public bool UniPolar
|
||||
{
|
||||
get => _UniPolar;
|
||||
set => SetProperty(ref _UniPolar, value, "UniPolar");
|
||||
}
|
||||
|
||||
protected bool _IgnoreRange = false;
|
||||
public bool IgnoreRange
|
||||
{
|
||||
get => _IgnoreRange;
|
||||
set => SetProperty(ref _IgnoreRange, value, "IgnoreRange");
|
||||
}
|
||||
|
||||
protected string _lastUpdatedBy;
|
||||
public string LastUpdatedBy
|
||||
{
|
||||
get => _lastUpdatedBy;
|
||||
set => SetProperty(ref _lastUpdatedBy, value, "LastUpdatedBy");
|
||||
}
|
||||
|
||||
protected int _version = 1;
|
||||
public int Version
|
||||
{
|
||||
get => _version;
|
||||
set => SetProperty(ref _version, value, "Version");
|
||||
}
|
||||
protected bool _localOnly = false;
|
||||
public bool LocalOnly => _localOnly;
|
||||
public void SetLocalOnly(bool bLocalOnly) { SetProperty(ref _localOnly, bLocalOnly, "LocalOnly"); }
|
||||
|
||||
protected short _axisNumber = 0;
|
||||
public short AxisNumber
|
||||
{
|
||||
get => _axisNumber;
|
||||
set => SetProperty(ref _axisNumber, value, "AxisNumber");
|
||||
}
|
||||
|
||||
protected short _numberOfAxes = 1;
|
||||
public short NumberOfAxes
|
||||
{
|
||||
get => _numberOfAxes;
|
||||
set => SetProperty(ref _numberOfAxes, value, "NumberOfAxes");
|
||||
}
|
||||
protected int _calInterval = 365;
|
||||
public int CalInterval
|
||||
{
|
||||
get => _calInterval;
|
||||
set => SetProperty(ref _calInterval, value, "CalInterval");
|
||||
}
|
||||
public string Polarity
|
||||
{
|
||||
get => _invert ? "-" : "+";
|
||||
set { Invert = value == "-"; OnPropertyChanged("Polarity"); }
|
||||
}
|
||||
|
||||
protected DateTime _lastModified = (DateTime)System.Data.SqlTypes.SqlDateTime.MinValue;
|
||||
|
||||
public DateTime LastModified
|
||||
{
|
||||
get => _lastModified;
|
||||
set => SetProperty(ref _lastModified, value, "LastModified");
|
||||
}
|
||||
|
||||
protected IsoCode _isoCode = new IsoCode("");
|
||||
|
||||
public string ISOCode
|
||||
{
|
||||
get => _isoCode.StringRepresentation;
|
||||
set => SetProperty(ref _isoCode, new IsoCode(value), "ISOCode");
|
||||
}
|
||||
|
||||
public string PhysicalDimension
|
||||
{
|
||||
get => _isoCode.PhysicalDimension;
|
||||
set => _isoCode.PhysicalDimension = value;
|
||||
}
|
||||
|
||||
public string Direction
|
||||
{
|
||||
get => _isoCode.Direction;
|
||||
set => _isoCode.Direction = value;
|
||||
}
|
||||
|
||||
|
||||
private bool _doNotUse = false;
|
||||
public bool DoNotUse
|
||||
{
|
||||
get => _doNotUse;
|
||||
set => SetProperty(ref _doNotUse, value, "DoNotUse");
|
||||
}
|
||||
|
||||
private bool _broken = false;
|
||||
public bool Broken
|
||||
{
|
||||
get => _broken;
|
||||
set => SetProperty(ref _broken, value, "Broken");
|
||||
}
|
||||
|
||||
|
||||
public enum SensorBaseFields
|
||||
{
|
||||
CheckOffset,
|
||||
Invert,
|
||||
Model,
|
||||
Manufacturer,
|
||||
UserPartNumber,
|
||||
Capacity,
|
||||
CouplingMode,
|
||||
OffsetToleranceLow,
|
||||
OffsetToleranceHigh,
|
||||
MeasurementUnit,
|
||||
RangeLow,
|
||||
RangeMedium,
|
||||
RangeHigh,
|
||||
SupportedExcitation,
|
||||
Calibration,
|
||||
Bridge,
|
||||
Shunt,
|
||||
BridgeResistance,
|
||||
Filter,
|
||||
UniPolar,
|
||||
IgnoreRange,
|
||||
LastUpdatedBy,
|
||||
Version,
|
||||
LocalOnly,
|
||||
AxisNumber,
|
||||
NumberOfAxes,
|
||||
CalInterval,
|
||||
Polarity,
|
||||
LastModified,
|
||||
ISOCode,
|
||||
PhysicalDimension,
|
||||
Direction,
|
||||
Broken,
|
||||
DoNotUse
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// modifies an isocode's Filter Class based on a sensor's Filter if the isocode's Filter Class is "?"
|
||||
/// FB 8037 - sensor's default filter not displayed after SIF import
|
||||
/// </summary>
|
||||
/// <param name="importingIsoCode">the starting ISO code which may or may not already have a filter</param>
|
||||
/// <param name="sensorFilterClass">the sensor's filter class to be used if the channel doesn't already have one</param>
|
||||
/// <returns>a string representation of the ISO code with a non-'?' Filter Class if the sensor's Filter is one of the ISO values</returns>
|
||||
public string BuildIsoCodeFromFilter(string importingIsoCode, FilterClass.FilterClassType sensorFilterClass)
|
||||
{
|
||||
var isoCodeWithFilter = new IsoCode(importingIsoCode);
|
||||
if (isoCodeWithFilter.FilterClass == "?")
|
||||
{
|
||||
isoCodeWithFilter.FilterClass = FClassToIsoFilterCode(sensorFilterClass);
|
||||
};
|
||||
return isoCodeWithFilter.StringRepresentation;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// returns the ISO Code for a Filter Class
|
||||
/// </summary>
|
||||
private static string FClassToIsoFilterCode(FilterClass.FilterClassType fClass)
|
||||
{
|
||||
var isoFilterCode = "?";
|
||||
|
||||
switch (fClass)
|
||||
{
|
||||
case FilterClass.FilterClassType.CFC1000:
|
||||
isoFilterCode = "A";
|
||||
break;
|
||||
case FilterClass.FilterClassType.CFC600:
|
||||
isoFilterCode = "B";
|
||||
break;
|
||||
case FilterClass.FilterClassType.CFC180:
|
||||
isoFilterCode = "C";
|
||||
break;
|
||||
case FilterClass.FilterClassType.CFC60:
|
||||
isoFilterCode = "D";
|
||||
break;
|
||||
case FilterClass.FilterClassType.None:
|
||||
isoFilterCode = "P";
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException("fClass", fClass, null);
|
||||
}
|
||||
return isoFilterCode;
|
||||
}
|
||||
|
||||
}
|
||||
public class SensorModel : SensorBase, IComparable<SensorModel>
|
||||
{
|
||||
public enum IRTraccFormats
|
||||
{
|
||||
Manual,
|
||||
DiagnosticZeroMMmV,
|
||||
ZeroMMmV,
|
||||
AverageOverTime,
|
||||
Polynomial
|
||||
}
|
||||
private enum XMLFields
|
||||
{
|
||||
Model,
|
||||
Manufacturer,
|
||||
UserPartNumber,
|
||||
Capacity,
|
||||
OffsetTolerance,
|
||||
MeasurementUnit,
|
||||
SensorRange,
|
||||
Sensitivity,
|
||||
Excitation,
|
||||
IsProportional,
|
||||
Bridge,
|
||||
Shunt,
|
||||
BridgeResistance,
|
||||
RemoveOffset,
|
||||
FilterClass,
|
||||
ZeroMethod,
|
||||
InitialEU,
|
||||
NonLinear,
|
||||
UniPolar,
|
||||
PolynomialStyle,
|
||||
IRTraccFormat,
|
||||
LinearizationFormula,
|
||||
PhysicalDimension,
|
||||
IgnoreRange,
|
||||
Invert,
|
||||
CouplingMode,
|
||||
CheckOffset
|
||||
}
|
||||
public SensorModel(System.Xml.XmlElement node)
|
||||
{
|
||||
var initialEU = 0D;
|
||||
foreach (var childnode in node.ChildNodes)
|
||||
{
|
||||
if (!(childnode is System.Xml.XmlElement elem)) { continue; }
|
||||
try
|
||||
{
|
||||
var field = (XMLFields)Enum.Parse(typeof(XMLFields), elem.Name);
|
||||
var value = elem.InnerText;
|
||||
switch (field)
|
||||
{
|
||||
case XMLFields.Bridge:
|
||||
Bridge = (Test.Module.Channel.Sensor.BridgeType)Enum.Parse(typeof(Test.Module.Channel.Sensor.BridgeType), value);
|
||||
break;
|
||||
case XMLFields.BridgeResistance:
|
||||
BridgeResistance = double.Parse(value, System.Globalization.CultureInfo.InvariantCulture);
|
||||
break;
|
||||
case XMLFields.Capacity:
|
||||
Capacity = double.Parse(value, System.Globalization.CultureInfo.InvariantCulture);
|
||||
break;
|
||||
case XMLFields.Excitation:
|
||||
SupportedExcitation = new ExcitationVoltageOptions.ExcitationVoltageOption[] { (ExcitationVoltageOptions.ExcitationVoltageOption)Enum.Parse(typeof(ExcitationVoltageOptions.ExcitationVoltageOption), value) };
|
||||
break;
|
||||
case XMLFields.FilterClass:
|
||||
Filter = new FilterClass(value);
|
||||
break;
|
||||
case XMLFields.IgnoreRange:
|
||||
IgnoreRange = bool.Parse(value);
|
||||
break;
|
||||
case XMLFields.Invert:
|
||||
Invert = bool.Parse(value);
|
||||
break;
|
||||
case XMLFields.InitialEU:
|
||||
initialEU = double.Parse(value, System.Globalization.CultureInfo.InvariantCulture);
|
||||
//InitialEU = double.Parse(value, System.Globalization.CultureInfo.InvariantCulture);
|
||||
break;
|
||||
case XMLFields.IsProportional:
|
||||
Calibration.IsProportional = bool.Parse(value);
|
||||
break;
|
||||
case XMLFields.LinearizationFormula:
|
||||
Calibration.Records.Records[0].Poly = new LinearizationFormula();
|
||||
Calibration.Records.Records[0].Poly.FromSerializeString(value);
|
||||
break;
|
||||
case XMLFields.Manufacturer:
|
||||
Manufacturer = value;
|
||||
//System.Diagnostics.Trace.WriteLine(Manufacturer);
|
||||
break;
|
||||
case XMLFields.MeasurementUnit:
|
||||
DisplayUnit = value;
|
||||
break;
|
||||
case XMLFields.Model:
|
||||
Model = value;
|
||||
//System.Diagnostics.Trace.WriteLine(Model);
|
||||
break;
|
||||
case XMLFields.NonLinear:
|
||||
Calibration.NonLinear = bool.Parse(value);
|
||||
break;
|
||||
case XMLFields.OffsetTolerance:
|
||||
{
|
||||
var tol = new LowHigh(value);
|
||||
OffsetToleranceHigh = tol.High;
|
||||
OffsetToleranceLow = tol.Low;
|
||||
}
|
||||
break;
|
||||
case XMLFields.PhysicalDimension:
|
||||
PhysicalDimension = value;
|
||||
break;
|
||||
case XMLFields.PolynomialStyle:
|
||||
//var polystyle = (PolynomialStyles)Enum.Parse(typeof(PolynomialStyles), value);
|
||||
//switch (polystyle)
|
||||
//{
|
||||
// case PolynomialStyles.
|
||||
//}
|
||||
//don't need this anymore?
|
||||
break;
|
||||
case XMLFields.IRTraccFormat:
|
||||
var irFormat = (IRTraccFormats)Enum.Parse(typeof(IRTraccFormats), value);
|
||||
switch (irFormat)
|
||||
{
|
||||
case IRTraccFormats.AverageOverTime: Calibration.Records.Records[0].Poly.NonLinearStyle = NonLinearStyles.IRTraccAverageOverTime; break;
|
||||
case IRTraccFormats.DiagnosticZeroMMmV: Calibration.Records.Records[0].Poly.NonLinearStyle = NonLinearStyles.IRTraccDiagnosticsZero; break;
|
||||
case IRTraccFormats.Manual: Calibration.Records.Records[0].Poly.NonLinearStyle = NonLinearStyles.IRTraccManual; break;
|
||||
case IRTraccFormats.ZeroMMmV: Calibration.Records.Records[0].Poly.NonLinearStyle = NonLinearStyles.IRTraccZeroMMmV; break;
|
||||
case IRTraccFormats.Polynomial: Calibration.Records.Records[0].Poly.NonLinearStyle = NonLinearStyles.Polynomial; break;
|
||||
}
|
||||
break;
|
||||
case XMLFields.RemoveOffset:
|
||||
Calibration.RemoveOffset = bool.Parse(value);
|
||||
break;
|
||||
case XMLFields.Sensitivity:
|
||||
Calibration.Records.Records[0].Sensitivity = double.Parse(value, System.Globalization.CultureInfo.InvariantCulture);
|
||||
break;
|
||||
case XMLFields.SensorRange:
|
||||
{
|
||||
var Range = new SensorRange(value);
|
||||
RangeHigh = Range.High;
|
||||
RangeLow = Range.Low;
|
||||
RangeMedium = Range.Medium;
|
||||
}
|
||||
break;
|
||||
case XMLFields.Shunt:
|
||||
Shunt = (ShuntMode)Enum.Parse(typeof(ShuntMode), value);
|
||||
break;
|
||||
case XMLFields.UniPolar:
|
||||
UniPolar = bool.Parse(value);
|
||||
break;
|
||||
case XMLFields.UserPartNumber:
|
||||
UserPartNumber = value;
|
||||
break;
|
||||
case XMLFields.ZeroMethod:
|
||||
{
|
||||
Calibration.ZeroMethod = new ZeroMethod(value);
|
||||
}
|
||||
break;
|
||||
case XMLFields.CouplingMode:
|
||||
CouplingMode = (CouplingModes)Enum.Parse(typeof(CouplingModes), value);
|
||||
break;
|
||||
case XMLFields.CheckOffset:
|
||||
CheckOffset = bool.Parse(value);
|
||||
break;
|
||||
default:
|
||||
throw new NotSupportedException("field :" + field);
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//APILogger.Log("Failed to parse xml", ex, elem.Name, elem.Value);
|
||||
}
|
||||
Calibration.InitialOffset = new InitialOffset(initialEU);
|
||||
}
|
||||
}
|
||||
private Test.Module.Channel.Sensor.BridgeType ConvertToBridge(int bridge)
|
||||
{
|
||||
switch (bridge)
|
||||
{
|
||||
case 0: return Test.Module.Channel.Sensor.BridgeType.IEPE;
|
||||
case 4: return Test.Module.Channel.Sensor.BridgeType.HalfBridge_SigPlus;
|
||||
case 3: return Test.Module.Channel.Sensor.BridgeType.FullBridge;
|
||||
case 2: return Test.Module.Channel.Sensor.BridgeType.HalfBridge;
|
||||
case 1: return Test.Module.Channel.Sensor.BridgeType.QuarterBridge;
|
||||
default: return Test.Module.Channel.Sensor.BridgeType.FullBridge;
|
||||
}
|
||||
}
|
||||
|
||||
internal SensorModel(DataRow dr)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
Polarity = (string)dr[DbOperations.SensorDB.SensorModelFields.Polarity.ToString()];
|
||||
AxisNumber = Convert.ToInt16(dr[DbOperations.SensorDB.SensorModelFields.AxisNumber.ToString()]);
|
||||
Bridge = ConvertToBridge(Convert.ToInt32(dr[DbOperations.SensorDB.SensorModelFields.Bridge.ToString()]));
|
||||
BridgeResistance = Convert.ToDouble(dr[DbOperations.SensorDB.SensorModelFields.BridgeResistance.ToString()]);
|
||||
CalInterval = Convert.ToInt32(dr[DbOperations.SensorDB.SensorModelFields.CalInterval.ToString()]);
|
||||
Capacity = Convert.ToDouble(dr[DbOperations.SensorDB.SensorModelFields.Capacity.ToString()]);
|
||||
CouplingMode = (CouplingModes)Convert.ToInt32(dr[DbOperations.SensorDB.SensorModelFields.CouplingMode.ToString()]);
|
||||
Filter = new FilterClass((string)dr[DbOperations.SensorDB.SensorModelFields.FilterClass.ToString()]);
|
||||
IgnoreRange = Convert.ToBoolean(dr[DbOperations.SensorDB.SensorModelFields.IgnoreRange.ToString()]);
|
||||
CheckOffset = Convert.ToBoolean(dr[DbOperations.SensorDB.SensorModelFields.CheckOffset.ToString()]);
|
||||
Invert = Convert.ToBoolean(dr[DbOperations.SensorDB.SensorModelFields.Invert.ToString()]);
|
||||
LastModified = (DateTime)dr[DbOperations.SensorDB.SensorModelFields.LastModified.ToString()];
|
||||
SetLocalOnly(Convert.ToBoolean(dr[DbOperations.SensorDB.SensorModelFields.LocalOnly.ToString()]));
|
||||
Manufacturer = (string)dr[DbOperations.SensorDB.SensorModelFields.Manufacturer.ToString()];
|
||||
DisplayUnit = (string)dr[DbOperations.SensorDB.SensorModelFields.MeasurementUnit.ToString()];
|
||||
Model = (string)dr[DbOperations.SensorDB.SensorModelFields.Model.ToString()];
|
||||
LastUpdatedBy = (string)dr[DbOperations.SensorDB.SensorModelFields.ModifiedBy.ToString()];
|
||||
NumberOfAxes = Convert.ToInt16(dr[DbOperations.SensorDB.SensorModelFields.NumberOfAxes.ToString()]);
|
||||
OffsetToleranceHigh = Convert.ToDouble(dr[DbOperations.SensorDB.SensorModelFields.OffsetToleranceHigh.ToString()]);
|
||||
OffsetToleranceLow = Convert.ToDouble(dr[DbOperations.SensorDB.SensorModelFields.OffsetToleranceLow.ToString()]);
|
||||
RangeMedium = Convert.ToDouble(dr[DbOperations.SensorDB.SensorModelFields.RangeAve.ToString()]);
|
||||
RangeHigh = Convert.ToDouble(dr[DbOperations.SensorDB.SensorModelFields.RangeHigh.ToString()]);
|
||||
RangeLow = Convert.ToDouble(dr[DbOperations.SensorDB.SensorModelFields.RangeLow.ToString()]);
|
||||
Shunt = (ShuntMode)Convert.ToInt32(dr[DbOperations.SensorDB.SensorModelFields.Shunt.ToString()]);
|
||||
UniPolar = Convert.ToBoolean(dr[DbOperations.SensorDB.SensorModelFields.UniPolar.ToString()]);
|
||||
UserPartNumber = (string)dr[DbOperations.SensorDB.SensorModelFields.UserPartNumber.ToString()];
|
||||
Version = Convert.ToInt32(dr[DbOperations.SensorDB.SensorModelFields.Version.ToString()]);
|
||||
ISOCode = (string)dr[DbOperations.SensorDB.SensorModelFields.ISOCode.ToString()];
|
||||
Calibration = new SensorCalibration((string)dr[DbOperations.SensorDB.SensorModelFields.CalibrationRecord.ToString()]);
|
||||
var options = new List<ExcitationVoltageOptions.ExcitationVoltageOption>();
|
||||
var tokens = ((string)dr[DbOperations.SensorDB.SensorModelFields.SupportedExcitation.ToString()]).Split(new[] { System.Globalization.CultureInfo.InvariantCulture.TextInfo.ListSeparator }, StringSplitOptions.None);
|
||||
foreach (var token in tokens)
|
||||
{
|
||||
if (Enum.TryParse(token, out ExcitationVoltageOptions.ExcitationVoltageOption option)) { options.Add(option); }
|
||||
}
|
||||
|
||||
SupportedExcitation = options.ToArray();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//APILogger.Log("Failed to process fields: ", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class SensorModelCollection : INotifyPropertyChanged
|
||||
{
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
protected bool SetProperty<T>(ref T storage, T value, string propertyName = null)
|
||||
{
|
||||
if (Equals(storage, value)) return false;
|
||||
|
||||
storage = value;
|
||||
OnPropertyChanged(propertyName);
|
||||
return true;
|
||||
}
|
||||
protected void OnPropertyChanged(string propertyName = null)
|
||||
{
|
||||
//if (!HookedUp) { return; }
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
private Dictionary<string, Dictionary<string, SensorModel>> _sensorModels = new Dictionary<string, Dictionary<string, SensorModel>>();
|
||||
private static void PopulateCollection()
|
||||
{
|
||||
if (null == _collection)
|
||||
{
|
||||
_collection = new SensorModelCollection();
|
||||
}
|
||||
else
|
||||
{
|
||||
_collection._sensorModels.Clear();
|
||||
}
|
||||
_collection.LoadAllSensorModels();
|
||||
}
|
||||
// protected SensorModelCollection() { }
|
||||
private static SensorModelCollection _collection = null;
|
||||
public static SensorModelCollection SensorModelList
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
if (null == _collection)
|
||||
{
|
||||
PopulateCollection();
|
||||
}
|
||||
return _collection;
|
||||
}
|
||||
}
|
||||
}
|
||||
private static readonly object _lock = new object();
|
||||
/// <summary>
|
||||
/// deletes all Sensor Models
|
||||
/// originally created so TDM imports could clear all tables except DAS tables
|
||||
/// </summary>
|
||||
public void DeleteAll()
|
||||
{
|
||||
_sensorModels.Clear();
|
||||
try
|
||||
{
|
||||
using (var cmd = DbOperations.GetSQLCommand(true))
|
||||
{
|
||||
try
|
||||
{
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
cmd.CommandText = DbOperationsEnum.StoredProcedure.sp_SensorModelsDelete.ToString();
|
||||
cmd.Parameters.Add(new SqlParameter("@Model", SqlDbType.NVarChar, 50) { Value = null });
|
||||
cmd.Parameters.Add(new SqlParameter("@Manufacturer", SqlDbType.NVarChar, 50) { Value = null });
|
||||
var errorNumberParam =
|
||||
new SqlParameter("@errorNumber", SqlDbType.Int) { Direction = ParameterDirection.Output };
|
||||
cmd.Parameters.Add(errorNumberParam);
|
||||
var errorMessageParam =
|
||||
new SqlParameter("@errorMessage", SqlDbType.NVarChar, 250)
|
||||
{
|
||||
Direction = ParameterDirection.Output
|
||||
};
|
||||
cmd.Parameters.Add(errorMessageParam);
|
||||
|
||||
cmd.ExecuteNonQuery();
|
||||
if (int.Parse(errorNumberParam.Value.ToString()) != 0)
|
||||
{
|
||||
//errorMessageParam.Value
|
||||
}
|
||||
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
finally
|
||||
{
|
||||
cmd.Connection.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception) { /*APILogger.Log("Failed to delete sensor models, ", ex); */}
|
||||
LoadAllSensorModels();
|
||||
}
|
||||
private const string FILE_NAME = "Model.SensorDB.xml";
|
||||
protected void LoadAllSensorModels(string path)
|
||||
{
|
||||
var filename = System.IO.Path.Combine(path, FILE_NAME);
|
||||
if (!System.IO.File.Exists(filename))
|
||||
{
|
||||
return;
|
||||
}
|
||||
var doc = new System.Xml.XmlDocument();
|
||||
var xml = System.IO.File.ReadAllText(filename);
|
||||
doc.LoadXml(xml);
|
||||
var nodes = doc.GetElementsByTagName("SensorModels");
|
||||
foreach (var node in nodes)
|
||||
{
|
||||
if (!(node is System.Xml.XmlElement element)) { continue; }
|
||||
foreach (var childNode in element.GetElementsByTagName("SensorModel"))
|
||||
{
|
||||
if (!(childNode is System.Xml.XmlElement elem)) { continue; }
|
||||
LoadSensor(elem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void LoadAllSensorModels()
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var cmd = DbOperations.GetSQLCommand(true))
|
||||
{
|
||||
try
|
||||
{
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
cmd.CommandText = DbOperationsEnum.StoredProcedure.sp_SensorModelsGet.ToString();
|
||||
|
||||
#region params
|
||||
|
||||
cmd.Parameters.Add(new SqlParameter("@Model", SqlDbType.NVarChar, 50) { Value = null });
|
||||
|
||||
#endregion params
|
||||
|
||||
//cmd.ExecuteNonQuery();
|
||||
|
||||
using (var ds = DbOperations.Connection.QueryDataSet(cmd))
|
||||
{
|
||||
if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
|
||||
{
|
||||
foreach (DataRow dr in ds.Tables[0].Rows)
|
||||
{
|
||||
try
|
||||
{
|
||||
var sm = new SensorModel(dr);
|
||||
if (!_sensorModels.ContainsKey(sm.Manufacturer))
|
||||
{
|
||||
_sensorModels.Add(sm.Manufacturer, new Dictionary<string, SensorModel>());
|
||||
}
|
||||
if (!_sensorModels[sm.Manufacturer].ContainsKey(sm.Model))
|
||||
{
|
||||
_sensorModels[sm.Manufacturer].Add(sm.Model, sm);
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//APILogger.Log("Failed to process a row in the database: ", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
cmd.Connection.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception) { /*APILogger.Log("Failed to retrieve sensor models, ", ex); */}
|
||||
}
|
||||
|
||||
private void LoadSensor(System.Xml.XmlElement node)
|
||||
{
|
||||
try
|
||||
{
|
||||
var sm = new SensorModel(node);
|
||||
if (!_sensorModels.ContainsKey(sm.Manufacturer))
|
||||
{
|
||||
_sensorModels.Add(sm.Manufacturer, new Dictionary<string, SensorModel>());
|
||||
}
|
||||
_sensorModels[sm.Manufacturer][sm.Model] = sm;
|
||||
}
|
||||
catch (Exception) { /*APILogger.Log("failed to get node from sensor model db, ", ex); */}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user