58 lines
2.3 KiB
C#
58 lines
2.3 KiB
C#
using DataPROWin7.DataModel.Classes.Hardware;
|
|
using DTS.Common.Import.Enums;
|
|
using DTS.Common.Interface.DASFactory.Diagnostics;
|
|
using DTS.Common.SharedResource.Strings;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace DTS.Common.Import.Persist
|
|
{
|
|
public class SaveHardware : SaveVariantBase
|
|
{
|
|
public Dictionary<int, int> OldDASIdToNewDASId { get; set; } = new Dictionary<int, int>();
|
|
|
|
//track das.TestId so that we can update it if test id is updated
|
|
//key here is the old test id in das.TestId
|
|
public Dictionary<int, List<IISOHardware>> TestIdToHardware { get; set; } = new Dictionary<int, List<IISOHardware>>();
|
|
public SaveHardware(ImportObject importObject, IPersistCalculator persistCalculator, IImportNotification importNotification, Func<bool> isCancelled = null) :
|
|
base(importObject, persistCalculator, importNotification, isCancelled)
|
|
{
|
|
}
|
|
|
|
public override void Save()
|
|
{
|
|
_importNotification.SetStatus.Invoke(new ImportStatus { ExtraStatus = ImportExtraStatus.ReadingHardware, PossibleStatus = PossibleStatus.Importing });
|
|
_importObject.Hardware().ToList().Sort();
|
|
|
|
foreach (var h in _importObject.Hardware())
|
|
{
|
|
if (IsCancelled()) { return; }
|
|
|
|
var oldId = h.DASId;
|
|
DASHardwareList.GetList().Commit(h, false, true); //false and true are the defaults
|
|
if (h.DASId != oldId)
|
|
{
|
|
OldDASIdToNewDASId[oldId] = h.DASId;
|
|
}
|
|
|
|
var iso = h.GetHardware();
|
|
if (null != iso.TestId)
|
|
{
|
|
var id = (int)iso.TestId;
|
|
if (!TestIdToHardware.ContainsKey(id))
|
|
{
|
|
TestIdToHardware[id] = new List<IISOHardware>();
|
|
}
|
|
TestIdToHardware[id].Add(iso);
|
|
}
|
|
_persistCalculator.AddDone(); //for each hardware
|
|
_persistCalculator.AddDone(h.Channels?.Length ?? 0);
|
|
_importNotification.SetProgress(_persistCalculator.ProgressValue);
|
|
}
|
|
}
|
|
}
|
|
}
|