init
This commit is contained in:
95
Common/DTS.Common.Import/XML/XMLPre20ParseCalibrations.cs
Normal file
95
Common/DTS.Common.Import/XML/XMLPre20ParseCalibrations.cs
Normal file
@@ -0,0 +1,95 @@
|
||||
using DTS.Common.Enums;
|
||||
using DTS.Common.Enums.DBExport;
|
||||
using DTS.Common.Enums.Sensors;
|
||||
using DTS.Common.Import.Interfaces;
|
||||
using DTS.Common.Utils;
|
||||
using DTS.SensorDB;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml;
|
||||
|
||||
namespace DTS.Common.Import.XML
|
||||
{
|
||||
public class XMLPre20ParseCalibrations : XMLParseBase
|
||||
{
|
||||
private readonly XMLParseCalibrations _xmlParseCalibrations;
|
||||
public XMLPre20ParseCalibrations(XmlElement root, double importedVersion, XMLParseCalibrations xmlParseCalibrations, Func<bool> isCancelled = null) : base(root, importedVersion, isCancelled)
|
||||
{
|
||||
_xmlParseCalibrations = xmlParseCalibrations;
|
||||
}
|
||||
|
||||
public override void Parse(ref ImportObject importObject)
|
||||
{
|
||||
var calibrations = ParsePre20Calibrations(ref importObject);
|
||||
if (calibrations == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var newRoot = _xmlParseCalibrations.ConvertCalibrations(calibrations);
|
||||
if (newRoot == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
importObject.AddCalibrations(_xmlParseCalibrations.ParseCalibrations(newRoot));
|
||||
}
|
||||
|
||||
private void AddToSensor(SensorCalibration sc, ref ImportObject importObject)
|
||||
{
|
||||
if (sc == null) { return; }
|
||||
var sensor = importObject.Sensors().FirstOrDefault(s => s.SerialNumber == sc.SerialNumber);
|
||||
if (sensor != null)
|
||||
{
|
||||
sensor.Calibration = sc;
|
||||
}
|
||||
}
|
||||
private IEnumerable<SensorCalibration> ParsePre20Calibrations(ref ImportObject importObject)
|
||||
{
|
||||
List<SensorCalibration> scs = new List<SensorCalibration>();
|
||||
if (_importedVersion >= FileUtils.DataPROPre20XmlVersion)
|
||||
{
|
||||
foreach (var node in _root.ChildNodes)
|
||||
{
|
||||
if (node is XmlElement)
|
||||
{
|
||||
var sc = new SensorCalibration();
|
||||
sc.ReadXML(node as XmlElement);
|
||||
scs.Add(sc);
|
||||
AddToSensor(sc, ref importObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (_importedVersion == 1.0D)
|
||||
{
|
||||
foreach (var node in _root.ChildNodes)
|
||||
{
|
||||
if (node is XmlElement)
|
||||
{
|
||||
var sc = new SensorCalibration();
|
||||
sc.ReadXML(node as XmlElement);
|
||||
|
||||
sc.Records.Records[0].AtCapacity = false;
|
||||
|
||||
if (sc.NonLinear)
|
||||
{
|
||||
sc.Records.Records[0].SensitivityUnits = SensorConstants.SensUnits.NONE;
|
||||
}
|
||||
else if (sc.IsProportional)
|
||||
{
|
||||
sc.Records.Records[0].SensitivityUnits = SensorConstants.SensUnits.mVperVperEU;
|
||||
}
|
||||
else
|
||||
{
|
||||
sc.Records.Records[0].SensitivityUnits = SensorConstants.SensUnits.mVperEU;
|
||||
}
|
||||
scs.Add(sc);
|
||||
}
|
||||
}
|
||||
}
|
||||
return scs;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user