init
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
using DTS.Common.Enums.DBExport;
|
||||
using DTS.Common.Enums.Sensors;
|
||||
using DTS.Common.Import.Interfaces;
|
||||
using DTS.Common.Interface;
|
||||
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 XMLParseCalibrations : XMLParseBase
|
||||
{
|
||||
public XMLParseCalibrations(XmlElement root, double importedVersion, Func<bool> isCancelled = null) : base(root, importedVersion, isCancelled)
|
||||
{
|
||||
}
|
||||
public IImportNotification ImportNotification { get; set; }
|
||||
public override void Parse(ref ImportObject importObject)
|
||||
{
|
||||
ImportNotification?.SetStatus(new ImportStatus { PossibleStatus = Enums.PossibleStatus.Reading, ExtraStatus = Enums.ImportExtraStatus.ReadingCalibrations });
|
||||
var scs = ParseCalibrations(_root);
|
||||
var newRoot = ConvertCalibrations(scs);
|
||||
importObject.AddCalibrations(ParseCalibrations(newRoot));
|
||||
|
||||
}
|
||||
public XmlElement ConvertCalibrations(IEnumerable<SensorCalibration> calibrations)
|
||||
{
|
||||
_writer.WriteStartElement(TopLevelFields.Calibrations.ToString());
|
||||
foreach (var c in calibrations)
|
||||
{
|
||||
_writer.Flush();
|
||||
c.WriteXML(ref _writer);
|
||||
_writer.Flush();
|
||||
}
|
||||
_writer.WriteEndElement();
|
||||
return GetXmlElement();
|
||||
}
|
||||
|
||||
public IEnumerable<SensorCalibration> ParseCalibrations(XmlElement root)
|
||||
{
|
||||
List<SensorCalibration> scs = new List<SensorCalibration>();
|
||||
if (_importedVersion >= FileUtils.DataPROPre20XmlVersion)
|
||||
{
|
||||
foreach (var node in root.ChildNodes)
|
||||
{
|
||||
if (IsCancelled()) { return scs; }
|
||||
if (node is XmlElement)
|
||||
{
|
||||
var sc = new SensorCalibration();
|
||||
sc.ReadXML(node as XmlElement);
|
||||
scs.Add(sc);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (_importedVersion == 1.0D)
|
||||
{
|
||||
foreach (var node in root.ChildNodes)
|
||||
{
|
||||
if (IsCancelled()) { return scs; }
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
using CsvHelper;
|
||||
using DTS.Common.Classes;
|
||||
using DTS.Common.Enums.Sensors;
|
||||
using DTS.Common.Import.Interfaces;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace DTS.Common.Import.Parsers.CSV
|
||||
{
|
||||
public class Version5CSVTestParser : IParseCSVTest
|
||||
{
|
||||
private InputClockSource ParseInputClockSource(string val)
|
||||
{
|
||||
return Enum.TryParse(val, out InputClockSource source) ? source : default;
|
||||
}
|
||||
|
||||
private OutputClockSource ParseOutputClockSource(string val)
|
||||
{
|
||||
return Enum.TryParse(val, out OutputClockSource source) ? source : default;
|
||||
}
|
||||
|
||||
private static bool ParseBoolValue(string val)
|
||||
{
|
||||
return bool.TryParse(val, out var bTemp) ? bTemp : default;
|
||||
}
|
||||
|
||||
public int Version => 5;
|
||||
public void ParseVersion(CsvReader csvReader, TestSetupImportData tsid)
|
||||
{
|
||||
var foundHeader = false;
|
||||
List<string> tokens = new List<string>();
|
||||
while (!foundHeader && csvReader.Read())
|
||||
{
|
||||
tokens = CsvUtil.ReadFields(csvReader, false);
|
||||
|
||||
if (null == tokens) { return; }
|
||||
if (0 == tokens.Count || string.IsNullOrEmpty(tokens[0])) { continue; }
|
||||
var field = CSVImportTags.GetTagForString(tokens[0]);
|
||||
var version = CSVImportTags.GetVersionForTag(field);
|
||||
if (version != 5) { return; } //no version 5 tokens in here ...
|
||||
foundHeader = true;
|
||||
}
|
||||
|
||||
var tokens2 = CsvUtil.ReadFields(csvReader);
|
||||
|
||||
if (null == tokens2) { return; }
|
||||
|
||||
for (var i = 0; i < tokens.Count && i < tokens2.Count; i++)
|
||||
{
|
||||
GetValueForField(tsid, tokens, tokens2, i);
|
||||
}
|
||||
}
|
||||
|
||||
private void GetValueForField(TestSetupImportData tsid, List<string> tokens, List<string> tokens2, int index)
|
||||
{
|
||||
var field = CSVImportTags.GetTagForString(tokens[index]);
|
||||
var val = tokens2[index];
|
||||
switch (field)
|
||||
{
|
||||
case CSVImportTags.Tags.ClockMasterInputType:
|
||||
{
|
||||
tsid.ClockMasterInput = ParseInputClockSource(val);
|
||||
}
|
||||
break;
|
||||
case CSVImportTags.Tags.ClockMasterOutputType:
|
||||
{
|
||||
tsid.ClockMasterOutput = ParseOutputClockSource(val);
|
||||
}
|
||||
break;
|
||||
case CSVImportTags.Tags.ManageClocksOutsideDPMaster:
|
||||
{
|
||||
tsid.ManageClocksOutsideOfDataPROMaster = ParseBoolValue(val);
|
||||
}
|
||||
break;
|
||||
case CSVImportTags.Tags.ManageClocksOutsideDPSlave:
|
||||
{
|
||||
tsid.ManageClocksOutsideOfDataPROSlave = ParseBoolValue(val);
|
||||
}
|
||||
break;
|
||||
case CSVImportTags.Tags.ClockSlaveInputType:
|
||||
{
|
||||
tsid.ClockSlaveInput = ParseOutputClockSource(val);
|
||||
}
|
||||
break;
|
||||
case CSVImportTags.Tags.ClockSlaveOutputType:
|
||||
{
|
||||
tsid.ClockSlaveOutput = ParseOutputClockSource(val);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user