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 OldDASIdToNewDASId { get; set; } = new Dictionary(); //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> TestIdToHardware { get; set; } = new Dictionary>(); public SaveHardware(ImportObject importObject, IPersistCalculator persistCalculator, IImportNotification importNotification, Func 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(); } TestIdToHardware[id].Add(iso); } _persistCalculator.AddDone(); //for each hardware _persistCalculator.AddDone(h.Channels?.Length ?? 0); _importNotification.SetProgress(_persistCalculator.ProgressValue); } } } }