235 lines
9.3 KiB
C#
235 lines
9.3 KiB
C#
using DataPROWin7.DataModel;
|
|
using DTS.Common.Import.Enums;
|
|
using DTS.Common.Interface.Channels;
|
|
using DTS.Common.Interface.Groups.GroupList;
|
|
using DTS.Common.SharedResource.Strings;
|
|
using DTS.SensorDB;
|
|
using DTS.Slice.Users;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace DTS.Common.Import.Persist
|
|
{ //FB 38039 Checkout testsetup save vriant
|
|
public class SaveCheckoutTestSetup : SaveVariantBase
|
|
{
|
|
private readonly SaveCustomChannels _saveCustomChannels;
|
|
private readonly SaveHardware _saveHardware;
|
|
private readonly SaveGroups _saveGroups;
|
|
private readonly string _setupName;
|
|
public User CurrentUser { get; set; }
|
|
public SaveCheckoutTestSetup(ImportObject importObject, IPersistCalculator persistCalculator, IImportNotification importNotification,
|
|
SaveCustomChannels saveCustomChannels, SaveHardware saveHardware, SaveGroups saveGroups,
|
|
Func<bool> isCancelled = null, string setupName = null) :
|
|
base(importObject, persistCalculator, importNotification, isCancelled)
|
|
{
|
|
_saveCustomChannels = saveCustomChannels;
|
|
_saveHardware = saveHardware;
|
|
_saveGroups = saveGroups;
|
|
_setupName = setupName;
|
|
}
|
|
private void ConfigureCheckoutTestSetup(TestTemplate TestSetupCheckout)
|
|
{
|
|
TestSetupCheckout.DoROIDownload = true;
|
|
|
|
TestSetupCheckout.ViewROIDownload = true;
|
|
|
|
TestSetupCheckout.DownloadAll = true;
|
|
|
|
TestSetupCheckout.ViewDownloadAll = true;
|
|
|
|
TestSetupCheckout.RequireUserConfirmationOnErrors = false;
|
|
|
|
TestSetupCheckout.UploadData = false;
|
|
|
|
TestSetupCheckout.ViewDiagnostics = true;
|
|
|
|
TestSetupCheckout.VerifyChannels = true;
|
|
|
|
TestSetupCheckout.ViewExport = false;
|
|
|
|
TestSetupCheckout.DefaultNumberRealtimeGraphs = 1;
|
|
|
|
TestSetupCheckout.ExportFormats = DTS.Common.Enums.SupportedExportFormatBitFlags.none; // no export for this test
|
|
|
|
TestSetupCheckout.AllowMissingSensors = true;
|
|
|
|
TestSetupCheckout.StrictDiagnostics = false;
|
|
|
|
TestSetupCheckout.AutomaticProgression = true;
|
|
|
|
TestSetupCheckout.DoAutoArm = false;
|
|
|
|
TestSetupCheckout.DoStreaming = false;
|
|
|
|
TestSetupCheckout.DoEnableRepeat = false;
|
|
|
|
TestSetupCheckout.AllowSensorIdToBlankChannel = true;
|
|
TestSetupCheckout.AllowMissingSensors = true;
|
|
TestSetupCheckout.CheckoutMode = true;
|
|
TestSetupCheckout.QuitTestWithoutWarning = true;
|
|
TestSetupCheckout.SuppressMissingSensorsWarning = true;
|
|
TestSetupCheckout.NotAllChannelsViewer = true;
|
|
TestSetupCheckout.NotAllChannelsRealTime = true;
|
|
TestSetupCheckout.CheckListRequirePass = false;
|
|
}
|
|
|
|
public override void Save()
|
|
{
|
|
|
|
var testSetups = _importObject.TestSetups();
|
|
|
|
if (_importObject.TestSetupImportFileFormat == ImportFileFormat.SingleTestSetup)
|
|
{
|
|
var testSetup = testSetups.FirstOrDefault();
|
|
if (testSetup == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
testSetup.Name = _setupName;
|
|
testSetup.TestId = _setupName;
|
|
testSetup.TestSetupUniqueId = Guid.NewGuid().ToString();
|
|
ConfigureCheckoutTestSetup(testSetup);
|
|
}
|
|
|
|
|
|
Dictionary<string, string> oldIdToNewIdLookup = new Dictionary<string, string>();
|
|
|
|
SaveTestSetupHelper.UpdateLevelTriggers(ref oldIdToNewIdLookup, _saveCustomChannels, testSetups);
|
|
|
|
SaveTestSetupHelper.DeleteExistingTestSetups(testSetups, CurrentUser.UserName);
|
|
|
|
Dictionary<string, DASHardware> hardwareLookup = SaveTestSetupHelper.PopulateHarwareLookup();
|
|
|
|
|
|
_importNotification.SetStatus.Invoke(new ImportStatus { ExtraStatus = ImportExtraStatus.ReadingTestSetups, PossibleStatus = PossibleStatus.Importing });
|
|
foreach (var t in testSetups)
|
|
{
|
|
SaveTestSetupHelper.FixDasAff(hardwareLookup, t);
|
|
|
|
//keep track of test id prior to commit, so that we can correct das.TestId
|
|
//if we need to
|
|
var idPriorToCommit = t.Id;
|
|
t.Id = 0;
|
|
|
|
Dictionary<IGroup, IGroupChannel[]> groupChannelsLookup = new Dictionary<IGroup, IGroupChannel[]>();
|
|
var allSensorsInDb = SensorsCollection.SensorsList.GetAllSensors(true);
|
|
|
|
foreach (var cfg in t.ChannelsForGroup)
|
|
{
|
|
IGroup checkoutGroup = GroupHelper.CreateEmptyGroup();
|
|
checkoutGroup.Name = cfg.Key.DisplayName;
|
|
checkoutGroup.DisplayName = checkoutGroup.Name;
|
|
checkoutGroup.DisplayOrder = cfg.Key.DisplayOrder;
|
|
|
|
List<IGroupChannel> groupChannelList = new List<IGroupChannel>();
|
|
foreach (var ch in cfg.Value)
|
|
{
|
|
var match = allSensorsInDb?.FirstOrDefault(s => s.DatabaseId == ch.SensorId);
|
|
if (null != match)
|
|
{
|
|
ch.SetSensorData(match, null, false);
|
|
}
|
|
|
|
if (_saveHardware.OldDASIdToNewDASId.ContainsKey(ch.DASId))
|
|
{
|
|
ch.DASId = _saveHardware.OldDASIdToNewDASId[ch.DASId];
|
|
}
|
|
//15262 Absolute zero sensors in test setup change to ave over time after import.
|
|
//zero method may be undefined on older imports
|
|
//make sure we set the zero method before embedded group is committed ...
|
|
SaveSensor.FixMissingZeroMethodParameter(ch, _saveGroups.DefaultZeroMethod, _saveGroups.DefaultZeroStart, _saveGroups.DefaultZeroEnd);
|
|
SaveSensor.FixMissingInitialOffset(ch, _saveGroups.DefaultInitialOffset);
|
|
groupChannelList.Add(ch);
|
|
}
|
|
groupChannelsLookup[checkoutGroup] = groupChannelList.ToArray();
|
|
}
|
|
|
|
|
|
t.Groups.Clear();
|
|
t.ChannelsForGroup.Clear();
|
|
|
|
t.ChannelsForGroup = groupChannelsLookup;
|
|
foreach (var g in groupChannelsLookup)
|
|
{
|
|
t.Groups.Add(g.Key);
|
|
}
|
|
|
|
var hardwareIncluded = t.AddedHardware.ToList();
|
|
var hardwareRemoved = t.RemovedHardware.ToList();
|
|
|
|
var listToProcess = new List<Tuple<int, int>>();
|
|
using (var e = _saveHardware.OldDASIdToNewDASId.GetEnumerator())
|
|
{
|
|
while (e.MoveNext())
|
|
{
|
|
listToProcess.Add(new Tuple<int, int>(e.Current.Key, e.Current.Value));
|
|
}
|
|
}
|
|
//arrange the to process by the largest new id
|
|
listToProcess.Sort((a, b) =>
|
|
{
|
|
if (a == b)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
return b.Item2.CompareTo(a.Item2);
|
|
});
|
|
|
|
foreach (var tuple in listToProcess)
|
|
{
|
|
if (tuple.Item1 == tuple.Item2)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
if (hardwareIncluded.Contains(tuple.Item1))
|
|
{
|
|
hardwareIncluded.Remove(tuple.Item1);
|
|
hardwareIncluded.Add(tuple.Item2);
|
|
}
|
|
|
|
if (hardwareRemoved.Contains(tuple.Item1))
|
|
{
|
|
hardwareRemoved.Remove(tuple.Item1);
|
|
hardwareRemoved.Add(tuple.Item2);
|
|
}
|
|
}
|
|
|
|
SaveTestSetupHelper.AddHardwareFromEmbeddedGroups(t, _saveGroups, hardwareRemoved, hardwareIncluded);
|
|
|
|
t.ReplaceCalculatedChannel(oldIdToNewIdLookup);
|
|
|
|
if (IsCancelled())
|
|
{
|
|
return;
|
|
}
|
|
|
|
TestTemplateList.TestTemplatesList.Commit(t, false);
|
|
if (idPriorToCommit > 0 && _saveHardware.TestIdToHardware.ContainsKey(idPriorToCommit))
|
|
{
|
|
foreach (var enumH in _saveHardware.TestIdToHardware[idPriorToCommit])
|
|
{
|
|
enumH.TestId = t.Id;
|
|
enumH.Update();
|
|
}
|
|
}
|
|
_persistCalculator.AddDone();
|
|
_importNotification.SetProgress(_persistCalculator.ProgressValue);
|
|
}
|
|
|
|
oldIdToNewIdLookup.Clear();
|
|
|
|
if (_importObject.Errors().Any())
|
|
{
|
|
//report errors
|
|
}
|
|
//FB 36879 Still parsing it should report as Working status
|
|
_importNotification.SetStatus.Invoke(new ImportStatus { ExtraStatus = ImportExtraStatus.None, PossibleStatus = PossibleStatus.Working });
|
|
|
|
}
|
|
}
|
|
}
|