init
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
using DTS.Common.Classes.Sensors;
|
||||
using DTS.Common.Enums.Sensors;
|
||||
using DTS.Common.SharedResource.Strings;
|
||||
using System;
|
||||
|
||||
namespace DTS.Common.Import.Parsers.CSV
|
||||
{
|
||||
public class Version3CSVSensorParser : AbstractCSVParser
|
||||
{
|
||||
public override int Version => 3;
|
||||
public override void ParseVersion(CSVImportTags.Tags field, string sVal, ParseParameters pp)
|
||||
{
|
||||
switch (field)
|
||||
{
|
||||
case CSVImportTags.Tags.GroupName:
|
||||
// check sval for empty
|
||||
if (string.IsNullOrEmpty(sVal) || string.IsNullOrWhiteSpace(sVal))
|
||||
{
|
||||
pp.Errors.Add(string.Format(StringResources.ImportSensorsPreviewControl_CSVImport_NoGroupNameFound, pp.SensorData.SerialNumber));
|
||||
return;
|
||||
}
|
||||
// check duplicate sd.serialnumber
|
||||
if (pp.SensorGroupNameLookup.ContainsKey(pp.SensorData.SerialNumber))
|
||||
{
|
||||
pp.Errors.Add(string.Format(StringResources.ImportSensorsPreviewControl_CSVImport_DuplicateSensorSN, pp.SensorData.SerialNumber));
|
||||
return;
|
||||
}
|
||||
pp.SensorGroupNameLookup.Add(pp.SensorData.SerialNumber, sVal);
|
||||
if (!pp.GroupNameToTestObjectLookup.ContainsKey(sVal))
|
||||
{
|
||||
pp.GroupNameToTestObjectLookup.Add(sVal, pp.SensorTestObject);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (pp.GroupNameToTestObjectLookup[sVal] != pp.SensorTestObject && !ImportCreateDynamicGroups)
|
||||
{
|
||||
var errorMessage =
|
||||
string.Format(StringResources.CSVImportMultipleTestObjectsInGroup,
|
||||
sVal);
|
||||
if (!pp.Errors.Contains(errorMessage))
|
||||
{
|
||||
pp.Errors.Add(errorMessage);
|
||||
}
|
||||
throw new Exception("Parse error");
|
||||
}
|
||||
}
|
||||
break;
|
||||
case CSVImportTags.Tags.GroupType:
|
||||
// check sval for empty
|
||||
if (string.IsNullOrEmpty(sVal) || string.IsNullOrWhiteSpace(sVal))
|
||||
{
|
||||
pp.Errors.Add(string.Format(StringResources.ImportSensorsPreviewControl_CSVImport_NoGroupTypeFound, pp.SensorData.SerialNumber));
|
||||
return;
|
||||
}
|
||||
// check duplicate sd.serialnumber
|
||||
if (pp.SensorGroupTypeLookup.ContainsKey(pp.SensorData.SerialNumber))
|
||||
{
|
||||
pp.Errors.Add(string.Format(StringResources.ImportSensorsPreviewControl_CSVImport_DuplicateSensorSN, pp.SensorData.SerialNumber));
|
||||
return;
|
||||
}
|
||||
pp.SensorGroupTypeLookup.Add(pp.SensorData.SerialNumber, sVal);
|
||||
break;
|
||||
case CSVImportTags.Tags.Unknown: break;
|
||||
default: throw new NotSupportedException("Unknown field: " + field);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
using DataPROWin7.DataModel;
|
||||
using DataPROWin7.DataModel.Classes.Hardware;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace DTS.Common.Import.Persist
|
||||
{
|
||||
//FB 38039 Refactored the common methods for save test setup
|
||||
public static class SaveTestSetupHelper
|
||||
{
|
||||
|
||||
public static void AddHardwareFromEmbeddedGroups(TestTemplate t, SaveGroups saveGroups, List<int> hardwareRemoved, List<int> hardwareIncluded)
|
||||
{
|
||||
//finally add hardware from embedded groups
|
||||
foreach (var group in t.Groups)
|
||||
{
|
||||
//Set the StaticGroupId if this embedded Group came from a static Group
|
||||
if (group.StaticGroupId != null && saveGroups != null && saveGroups.OldGroupIdToNewGroupId.ContainsKey(group.StaticGroupId))
|
||||
{
|
||||
group.StaticGroupId = saveGroups?.OldGroupIdToNewGroupId[group.StaticGroupId];
|
||||
}
|
||||
foreach (var hid in group.IncludedHardware)
|
||||
{
|
||||
if (hardwareRemoved.Contains(hid)) { continue; }
|
||||
if (!hardwareIncluded.Contains(hid))
|
||||
{
|
||||
hardwareIncluded.Add(hid);
|
||||
}
|
||||
}
|
||||
}
|
||||
t.AddedHardware = hardwareIncluded.ToArray();
|
||||
t.RemovedHardware = hardwareRemoved.ToArray();
|
||||
}
|
||||
public static void FixDasAff(Dictionary<string, DASHardware> hardwareLookup, TestTemplate t)
|
||||
{
|
||||
//FB15759: If we had to skip setting DAS AAF on the file prep side (freq == 0), fix it now.
|
||||
for (int i = 0; i < t.DASAAFRateList.Count; i++)
|
||||
{
|
||||
var key = t.DASAAFRateList.ElementAt(i).Key;
|
||||
if (0 == t.DASAAFRateList[key] && hardwareLookup.ContainsKey(key))
|
||||
{
|
||||
t.DASAAFRateList[key] = TestTemplate.GetAAFForHardware(hardwareLookup[key], (int)t.DASSampleRateList[key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Dictionary<string, DASHardware> PopulateHarwareLookup()
|
||||
{
|
||||
var hardwareLookup = new Dictionary<string, DASHardware>();
|
||||
foreach (var h in DASHardwareList.GetAllHardware())
|
||||
{
|
||||
hardwareLookup[h.SerialNumber] = h;
|
||||
}
|
||||
|
||||
return hardwareLookup;
|
||||
}
|
||||
|
||||
public static void DeleteExistingTestSetups(IEnumerable<TestTemplate> testSetups, string userName)
|
||||
{
|
||||
var testArray = testSetups?.ToArray();
|
||||
var testNames = new List<string>(testArray?.Select(p => p.Name));
|
||||
TestTemplateList.TestTemplatesList.DeleteTestSetups(testNames, userName);
|
||||
}
|
||||
public static void UpdateLevelTriggers(ref Dictionary<string, string> oldIdToNewIdLookup, SaveCustomChannels saveCustomChannels, IEnumerable<TestTemplate> testSetups)
|
||||
{
|
||||
//now that all the groups are committed, see what now is, and update what once was in level triggers to what now is.
|
||||
//note we could do it with the channel remaps lookup above ...
|
||||
|
||||
foreach (var eChannelText in saveCustomChannels.CustomChannelTextIdToOldChannelId)
|
||||
{
|
||||
var isocode = eChannelText.Key;
|
||||
var oldId = eChannelText.Value;
|
||||
var newCustomChannel = CustomChannelList.List.GetChannelByISOCode(isocode, false);
|
||||
if (null == newCustomChannel) continue;
|
||||
var oldCH = saveCustomChannels.CustomChannelOldChannelIdToChannel[oldId];
|
||||
var newId = oldCH.GetIdWithSpecificChannelId(newCustomChannel.Channel.Id);
|
||||
oldIdToNewIdLookup[oldId] = newId;
|
||||
foreach (var t in testSetups)
|
||||
{
|
||||
t.ReplaceLevelTriggerChannel(oldId, newId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
using DTS.Common.Import.Interfaces;
|
||||
using DTS.Common.Utils;
|
||||
using DTS.Slice.Users;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DTS.Common.Import
|
||||
{
|
||||
public class DTSXMLParseImport : IParseImport
|
||||
{
|
||||
|
||||
private ImportObject _importObject;
|
||||
private readonly Func<bool> _isCancelled;
|
||||
private readonly IImportNotification _importNotification;
|
||||
public List<IUIItems> UIItems { get; set; }
|
||||
public DTSXMLParseImport(ImportObject importObject, IImportNotification importNotification, Func<bool> isCancelled = null)
|
||||
{
|
||||
_isCancelled = isCancelled;
|
||||
_importObject = importObject;
|
||||
_importNotification = importNotification;
|
||||
}
|
||||
public ImportObject Parse(IEnumerable<string> importFiles)
|
||||
{
|
||||
XMLParseProcessor parseProcesser = new XMLParseProcessor(_importObject, _importNotification, importFiles, _isCancelled);
|
||||
parseProcesser.UIItems = UIItems;
|
||||
_importObject = parseProcesser.Process();
|
||||
AssignLinkedDASSerials(ref _importObject);
|
||||
return _importObject;
|
||||
}
|
||||
|
||||
private void AssignLinkedDASSerials(ref ImportObject importObject)
|
||||
{
|
||||
foreach (var h in importObject.Hardware())
|
||||
{
|
||||
if (!h.IsPseudoRack()) continue;
|
||||
var matches = from hw in importObject.Hardware() where hw.ParentDAS == h.SerialNumber select hw.SerialNumber;
|
||||
var enumerable = matches as string[] ?? matches.ToArray();
|
||||
if (enumerable.Any())
|
||||
{
|
||||
h.LinkedDASSerials = enumerable.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user