223 lines
8.8 KiB
C#
223 lines
8.8 KiB
C#
using DataPROWin7.DataModel;
|
|
using DataPROWin7.DataModel.Classes.Hardware;
|
|
using DTS.Common.Import.Enums;
|
|
using DTS.SensorDB;
|
|
using DTS.Slice.Users;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using static System.Net.Mime.MediaTypeNames;
|
|
|
|
namespace DTS.Common.Import.Persist
|
|
{
|
|
public class SaveTestSetup : SaveVariantBase
|
|
{
|
|
private readonly SaveCustomChannels _saveCustomChannels;
|
|
private readonly SaveHardware _saveHardware;
|
|
private readonly SaveGroups _saveGroups;
|
|
public User CurrentUser { get; set; }
|
|
//FB 38039 Get/ Set setup name used in run test
|
|
public string TestSetupName { get; set; }
|
|
public SaveTestSetup(ImportObject importObject, IPersistCalculator persistCalculator, IImportNotification importNotification,
|
|
SaveCustomChannels saveCustomChannels, SaveHardware saveHardware, SaveGroups saveGroups,
|
|
Func<bool> isCancelled = null) :
|
|
base(importObject, persistCalculator, importNotification, isCancelled)
|
|
{
|
|
_saveCustomChannels = saveCustomChannels;
|
|
_saveHardware = saveHardware;
|
|
_saveGroups = saveGroups;
|
|
}
|
|
//FB 38039 Default used for run test
|
|
private void ConfigureDefaultRunTestTestSetup(TestTemplate testSetup)
|
|
{
|
|
testSetup.DoROIDownload = true;
|
|
|
|
testSetup.ViewROIDownload = true;
|
|
|
|
testSetup.DownloadAll = true;
|
|
|
|
testSetup.ViewDownloadAll = true;
|
|
|
|
testSetup.RequireUserConfirmationOnErrors = true;
|
|
|
|
//FB 43757, 43817 keep the default from testsetup default setting for upload data
|
|
|
|
testSetup.ViewDiagnostics = true;
|
|
|
|
testSetup.VerifyChannels = true;
|
|
|
|
testSetup.ViewExport = true;
|
|
|
|
testSetup.DefaultNumberRealtimeGraphs = 1;
|
|
|
|
testSetup.ExportFormats = DTS.Common.Enums.SupportedExportFormatBitFlags.rdfadc;
|
|
|
|
testSetup.AllowMissingSensors = false;
|
|
|
|
testSetup.StrictDiagnostics = true;
|
|
|
|
testSetup.AutomaticProgression = true;
|
|
|
|
testSetup.DoAutoArm = false;
|
|
|
|
testSetup.DoEnableRepeat = false;
|
|
|
|
testSetup.DoStreaming = false;
|
|
|
|
testSetup.AllowSensorIdToBlankChannel = false;
|
|
testSetup.AllowMissingSensors = false;
|
|
testSetup.SuppressMissingSensorsWarning = false;
|
|
testSetup.CheckListRequirePass = true;
|
|
}
|
|
|
|
public override void Save()
|
|
{
|
|
var testSetups = _importObject.TestSetups();
|
|
|
|
if (_importObject.TestSetupImportFileFormat == ImportFileFormat.SingleTestSetup && !string.IsNullOrEmpty(TestSetupName))
|
|
{
|
|
//FB 38039 this test is used for run test
|
|
var testSetup = testSetups.FirstOrDefault();
|
|
if (testSetup == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
testSetup.Name = TestSetupName;
|
|
testSetup.TestId = TestSetupName;
|
|
ConfigureDefaultRunTestTestSetup(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;
|
|
|
|
var allSensorsInDb = SensorsCollection.SensorsList.GetAllSensors(true);
|
|
|
|
foreach (var channels in t.ChannelsForGroup)
|
|
{
|
|
foreach (var ch in channels.Value)
|
|
{
|
|
if (_importObject.OldSensorDatabaseIdsToNew().ContainsKey(ch.SensorId))
|
|
{
|
|
ch.SensorId = _importObject.OldSensorDatabaseIdToNew(ch.SensorId);
|
|
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);
|
|
}
|
|
}
|
|
|
|
var hardwareIncluded = t.AddedHardware.ToList();
|
|
var hardwareRemoved = t.RemovedHardware.ToList();
|
|
|
|
var listToProcess = new List<Tuple<int, int>>();
|
|
foreach (var e in _saveHardware.OldDASIdToNewDASId)
|
|
{
|
|
listToProcess.Add(new Tuple<int, int>(e.Key, e.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.Item2))
|
|
{
|
|
throw new Exception("Panic, new id already in list");
|
|
}
|
|
|
|
if (hardwareRemoved.Contains(tuple.Item2))
|
|
{
|
|
throw new Exception("Panic, new id already in list");
|
|
}
|
|
|
|
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;
|
|
}
|
|
if (t.TestSetupUniqueId == null)
|
|
{
|
|
t.TestSetupUniqueId = Guid.NewGuid().ToString();
|
|
}
|
|
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 });
|
|
}
|
|
|
|
}
|
|
}
|