init
This commit is contained in:
85
Common/DTS.Common.Import/Persist/SaveTestSetupHelper.cs
Normal file
85
Common/DTS.Common.Import/Persist/SaveTestSetupHelper.cs
Normal file
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user