221 lines
12 KiB
C#
221 lines
12 KiB
C#
using DTS.Common.Classes.Groups.ChannelSettings;
|
|
using DTS.Common.Classes.Groups;
|
|
using DTS.Common.Enums.Sensors;
|
|
using DTS.Common.Import.Interfaces;
|
|
using DTS.Common.Interface.Channels;
|
|
using DTS.Common.Interface.Groups.GroupList;
|
|
using DTS.Common.Interface.GroupTemplate;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Xml;
|
|
using static System.Net.Mime.MediaTypeNames;
|
|
using DTS.Common.Enums.DBExport;
|
|
using DTS.Common.Classes.Sensors;
|
|
|
|
namespace DTS.Common.Import.XML
|
|
{
|
|
public class XMLPre20ParseGroups : XMLParseBase
|
|
{
|
|
private readonly ISO.ISO13499FileDb _iSO13499FileDb;
|
|
private readonly XMLParseGroups _xmlParseGroups;
|
|
public XMLPre20ParseGroups(XmlElement root, double importedVersion, DTS.Common.ISO.ISO13499FileDb iSO13499FileDb,
|
|
XMLParseGroups xmlParseGroups, Func<bool> isCancelled = null) : base(root, importedVersion, isCancelled)
|
|
{
|
|
_iSO13499FileDb = iSO13499FileDb;
|
|
_xmlParseGroups = xmlParseGroups;
|
|
}
|
|
|
|
public override void Parse(ref ImportObject importObject)
|
|
{
|
|
var groups = ParsePre20Groups(ref importObject);
|
|
importObject.AddGroups(groups);
|
|
|
|
var newRoot = MigratePre20Groups(groups, ref importObject);
|
|
var staticGroups = _xmlParseGroups.ParseGroups(newRoot, ref importObject);
|
|
importObject.AddStaticGroups(staticGroups);
|
|
}
|
|
|
|
private XmlElement MigratePre20Groups(IEnumerable<DataPROWin7.DataModel.TestObject> groups, ref ImportObject importObject)
|
|
{
|
|
_writer.WriteStartElement(TopLevelFields.Groups.ToString());
|
|
var count = -1;
|
|
foreach (var g in groups)
|
|
{
|
|
if (!g.GetISOTestObject().Embedded && !g.SysBuilt)
|
|
{
|
|
//Only make static Groups out of non-embedded and non-Added Groups
|
|
IGroup iGroup = GroupHelper.CreateEmptyGroup();
|
|
iGroup.Name = g.SerialNumber;
|
|
|
|
iGroup.LastModified = g.LastModified;
|
|
iGroup.LastModifiedBy = g.LastModifiedBy;
|
|
iGroup.Embedded = false;
|
|
|
|
iGroup.Id = count;
|
|
count--;
|
|
_groupIdMapping[iGroup.Name] = iGroup.Id;
|
|
|
|
iGroup.IncludedHardwareStringList = g.GetISOTestObject().HardwareIds;
|
|
var dasIdList = new List<string>();
|
|
foreach (var hardwareString in iGroup.IncludedHardwareStringList)
|
|
{
|
|
dasIdList.Add(hardwareString.Substring(0, hardwareString.IndexOf('_')));
|
|
}
|
|
iGroup.IncludedHardwareStringList = dasIdList.ToArray();
|
|
foreach (var ch in g.GetISOTestObject().AllChannels)
|
|
{
|
|
if (!ch.Required || string.IsNullOrEmpty(ch.SensorSerialNumber)) continue;
|
|
|
|
var groupChannel = new GroupChannel(true, iGroup.Name, iGroup, new IChannelSetting[0]);
|
|
groupChannel.IsoChannelName = ch.NameOfTheChannel; //???
|
|
groupChannel.UserChannelName = ch.NameOfTheChannel; //???
|
|
groupChannel.UserCode = string.Empty;
|
|
if (!string.IsNullOrWhiteSpace(ch.HardwareId))
|
|
{
|
|
var hardwareUnderscoreSplit = ch.HardwareId.Split('_');
|
|
groupChannel.Hardware = hardwareUnderscoreSplit[0];
|
|
|
|
foreach (var hardware in importObject.Hardware())
|
|
{
|
|
if (hardware.SerialNumber == groupChannel.Hardware)
|
|
{
|
|
groupChannel.DASId = hardware.DASId;
|
|
break;
|
|
}
|
|
}
|
|
|
|
var hardwareXSplit = ch.HardwareId.Split('x');
|
|
groupChannel.DASChannelIndex = Convert.ToInt32(hardwareXSplit[1]) - 1;
|
|
}
|
|
var channelParts = ch.GetId().Split('_');
|
|
groupChannel.GroupChannelOrder = Convert.ToInt32(channelParts[channelParts.Length - 1]);
|
|
groupChannel.TestSetupOrder = -1;
|
|
foreach (var sensor in importObject.Sensors())
|
|
{
|
|
if (sensor.SerialNumber == ch.SensorSerialNumber)
|
|
{
|
|
groupChannel.SetSensorData(sensor, null);
|
|
groupChannel.SensorId = sensor.DatabaseId;
|
|
break;
|
|
}
|
|
}
|
|
groupChannel.IsDisabled = false;
|
|
groupChannel.LastModified = g.LastModified;
|
|
groupChannel.LastModifiedBy = g.LastModifiedBy;
|
|
var sensorSettings = g.GetISOTestObject().GetSensorSettings(ch.GetId(), ch.SensorSerialNumber);
|
|
var channelSettingList = new List<DTS.Common.Interface.Channels.IChannelSetting>();
|
|
foreach (var sensorSetting in sensorSettings)
|
|
{
|
|
var channelSettingBase = new ChannelSettingBase((int)sensorSetting.Setting + 1,
|
|
sensorSetting.Setting.ToString(),
|
|
sensorSetting.Value);
|
|
switch (sensorSetting.Setting)
|
|
{
|
|
case SensorConstants.SensorSettings.OutputMode:
|
|
case SensorConstants.SensorSettings.SQMode:
|
|
case SensorConstants.SensorSettings.DIMode:
|
|
case SensorConstants.SensorSettings.UartBaudRate:
|
|
case SensorConstants.SensorSettings.UartDataBits:
|
|
if (int.TryParse(sensorSetting.Value, out var tmp))
|
|
{
|
|
channelSettingBase.IntValue = tmp;
|
|
}
|
|
else
|
|
{
|
|
|
|
continue;
|
|
}
|
|
break;
|
|
case SensorConstants.SensorSettings.CFC:
|
|
//FB 15574 convert cfc iso to FilterClass and replace the cfc setting with filter class
|
|
var cfc = sensorSetting.Value;
|
|
var filterClass = FilterClass.GetFilterClassSettingFromCFC(cfc);
|
|
|
|
channelSettingBase = new ChannelSettingBase((int)SensorConstants.SensorSettings.FilterClass + 1,
|
|
SensorConstants.SensorSettings.FilterClass.ToString(), filterClass);
|
|
channelSettingBase.Value = filterClass;
|
|
|
|
groupChannel.IsoCode = ch.ISOCode.Substring(0, 15) + cfc;
|
|
break;
|
|
case SensorConstants.SensorSettings.Polarity:
|
|
case SensorConstants.SensorSettings.Position:
|
|
case SensorConstants.SensorSettings.ZeroMethod:
|
|
case SensorConstants.SensorSettings.UserValue1:
|
|
case SensorConstants.SensorSettings.UserValue2:
|
|
case SensorConstants.SensorSettings.UserValue3:
|
|
case SensorConstants.SensorSettings.InitialOffset:
|
|
case SensorConstants.SensorSettings.UartStopBits:
|
|
case SensorConstants.SensorSettings.UartParity:
|
|
case SensorConstants.SensorSettings.UartFlowControl:
|
|
case SensorConstants.SensorSettings.UartDataFormat:
|
|
channelSettingBase.Value = sensorSetting.Value;
|
|
break;
|
|
case SensorConstants.SensorSettings.LimitDuration:
|
|
channelSettingBase.BoolValue = Convert.ToBoolean(sensorSetting.Value);
|
|
break;
|
|
case SensorConstants.SensorSettings.Range:
|
|
case SensorConstants.SensorSettings.Duration:
|
|
case SensorConstants.SensorSettings.Delay:
|
|
case SensorConstants.SensorSettings.DefaultValue:
|
|
case SensorConstants.SensorSettings.ActiveValue:
|
|
case SensorConstants.SensorSettings.ZeroMethodStart:
|
|
case SensorConstants.SensorSettings.ZeroMethodEnd:
|
|
channelSettingBase.DoubleValue = Convert.ToDouble(sensorSetting.Value);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
channelSettingList.Add(channelSettingBase);
|
|
|
|
}
|
|
groupChannel.ChannelSettings = channelSettingList.ToArray();
|
|
|
|
iGroup.GroupChannelList.Add(groupChannel);
|
|
}
|
|
|
|
_writer.Flush();
|
|
iGroup.WriteXML(ref _writer);
|
|
_writer.Flush();
|
|
}
|
|
}
|
|
_writer.WriteEndElement();
|
|
return GetXmlElement();
|
|
}
|
|
private IEnumerable<DataPROWin7.DataModel.TestObject> ParsePre20Groups(ref ImportObject importObject)
|
|
{
|
|
List<DataPROWin7.DataModel.TestObject> groups = new List<DataPROWin7.DataModel.TestObject>();
|
|
var importedHardware = new Dictionary<string, DataPROWin7.DataModel.DASHardware>();
|
|
foreach (var h in importObject.Hardware())
|
|
{
|
|
importedHardware[h.GetHardware().GetId()] = h;
|
|
}
|
|
|
|
var templateLookup = new Dictionary<string, ISO.TestObjectTemplate>();
|
|
var templateLookup2 = new Dictionary<string, DataPROWin7.DataModel.TestObjectTemplate>();
|
|
|
|
foreach (var template in importObject.GroupTemplates())
|
|
{
|
|
templateLookup[template.TemplateName] = template.ToISOTestObjectTemplate();
|
|
templateLookup2[template.TemplateName] = template;
|
|
}
|
|
foreach (var node in _root.ChildNodes)
|
|
{
|
|
if (!(node is XmlElement)) continue;
|
|
var to = DataPROWin7.DataModel.TestObject.ReadXML(node as XmlElement, templateLookup, importObject.Calibrations()?.ToList(), importObject.Sensors()?.ToList());
|
|
if (string.IsNullOrEmpty(to.Template)) continue;
|
|
if (!templateLookup2.ContainsKey(to.Template))
|
|
{
|
|
var db = _iSO13499FileDb;
|
|
var template = new DataPROWin7.DataModel.TestObjectTemplate(templateLookup[to.Template], ref db);
|
|
templateLookup2[to.Template] = template;
|
|
}
|
|
groups.Add(new DataPROWin7.DataModel.TestObject(to, to.SysBuilt, templateLookup2[to.Template], importedHardware));
|
|
}
|
|
return groups;
|
|
}
|
|
}
|
|
}
|