init
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
using CsvHelper;
|
||||
using DTS.Common.Classes;
|
||||
using DTS.Common.Enums.Sensors;
|
||||
using DTS.Common.Import.Interfaces;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace DTS.Common.Import.Parsers.CSV
|
||||
{
|
||||
public class Version6CSVTestParser : IParseCSVTest
|
||||
{
|
||||
public int Version => 6;
|
||||
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 != 6) { return; } //no version 5 tokens in here ...
|
||||
foundHeader = true;
|
||||
}
|
||||
|
||||
ReadBody(csvReader, tsid, tokens);
|
||||
}
|
||||
|
||||
private static int ParseIntValue(string val)
|
||||
{
|
||||
return int.TryParse(val, out var iTemp) ? iTemp : default;
|
||||
}
|
||||
private static bool ParseBoolValue(string val)
|
||||
{
|
||||
return bool.TryParse(val, out var bTemp) ? bTemp : default;
|
||||
}
|
||||
|
||||
private static void ReadBody(CsvReader csvReader, TestSetupImportData testSetupImportData, List<string> tokens)
|
||||
{
|
||||
while (csvReader.Read())
|
||||
{
|
||||
var tokens2 = CsvUtil.ReadFields(csvReader, false);
|
||||
if (null == tokens2 || 0 == tokens2.Count || string.IsNullOrWhiteSpace(tokens2[1]))
|
||||
{
|
||||
//we found a new line, we are done with this table
|
||||
break;
|
||||
}
|
||||
var dasSerial = string.Empty;
|
||||
for (var i = 0; i < tokens.Count && i < tokens2.Count; i++)
|
||||
{
|
||||
var field = CSVImportTags.GetTagForString(tokens[i]);
|
||||
var val = tokens2[i];
|
||||
|
||||
switch (field)
|
||||
{
|
||||
case CSVImportTags.Tags.DASSerial:
|
||||
dasSerial = val;
|
||||
break;
|
||||
case CSVImportTags.Tags.DASSampleRate:
|
||||
{
|
||||
testSetupImportData.SampleRateForDAS[dasSerial] = ParseIntValue(val);
|
||||
}
|
||||
break;
|
||||
case CSVImportTags.Tags.PTPDomainId:
|
||||
{
|
||||
testSetupImportData.DomainIdForDAS[dasSerial] = (uint)ParseIntValue(val);
|
||||
}
|
||||
break;
|
||||
case CSVImportTags.Tags.ClockMaster:
|
||||
{
|
||||
testSetupImportData.IsClockMaster[dasSerial] = ParseBoolValue(val);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
using DTS.Common.Import.Interfaces;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Xml;
|
||||
|
||||
namespace DTS.Common.Import.XML
|
||||
{
|
||||
public abstract class XMLParseBase : IParseVariant
|
||||
{
|
||||
protected static readonly Dictionary<int, int> _dasIdMapping = new Dictionary<int, int>();
|
||||
//Use string to handle both new (Id (int.ToString())) and old (Name (string)) exports
|
||||
protected static readonly Dictionary<string, int> _groupIdMapping = new Dictionary<string, int>();
|
||||
protected static readonly Dictionary<int, int> _sensorIdMapping = new Dictionary<int, int>();
|
||||
protected static readonly Dictionary<long, long> _channelIdMapping = new Dictionary<long, long>();
|
||||
|
||||
protected double _importedVersion;
|
||||
|
||||
protected readonly Func<bool> IsCancelled;
|
||||
protected readonly XmlElement _root;
|
||||
protected XmlWriter _writer;
|
||||
|
||||
protected bool _skipNormalizing;
|
||||
private readonly XmlDocument _doc;
|
||||
|
||||
public string FileName { get; set; }
|
||||
public abstract void Parse(ref ImportObject importObject);
|
||||
|
||||
protected XMLParseBase(XmlElement root, double importedVersion, Func<bool> isCancelled = null, bool skipNormalizing = false)
|
||||
{
|
||||
_importedVersion = importedVersion;
|
||||
|
||||
IsCancelled = isCancelled == null ? () => false : isCancelled;
|
||||
|
||||
_root = root;
|
||||
|
||||
_skipNormalizing = skipNormalizing;
|
||||
_doc = new XmlDocument();
|
||||
_writer = _doc.CreateNavigator().AppendChild();
|
||||
}
|
||||
|
||||
protected XmlElement GetXmlElement()
|
||||
{
|
||||
_writer.Close();
|
||||
return _doc.DocumentElement;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user