using DTS.Slice.Users; using System; using System.Collections.Generic; using System.Linq; namespace DTS.Common.Import { public class DTSXMLParseImport : IParseImport { private ImportObject _importObject; private readonly Func _isCancelled; private readonly IImportNotification _importNotification; private readonly bool _skipNormalizing; public List UIItems { get; set; } public DTSXMLParseImport(ImportObject importObject, IImportNotification importNotification, Func isCancelled = null, bool skipNormalizing = false) { _isCancelled = isCancelled; _importObject = importObject; _importNotification = importNotification; _skipNormalizing = skipNormalizing; } public ImportObject Parse(IEnumerable importFiles) { XMLParseProcessor parseProcesser = new XMLParseProcessor(_importObject, _importNotification, importFiles, _isCancelled, _skipNormalizing); parseProcesser.UIItems = UIItems; _importObject = parseProcesser.Process(); AssignLinkedDASSerials(ref _importObject); return _importObject; } private void AssignLinkedDASSerials(ref ImportObject importObject) { foreach (var h in importObject.Hardware()) { if (!h.IsPseudoRack()) continue; var matches = from hw in importObject.Hardware() where hw.ParentDAS == h.SerialNumber select hw.SerialNumber; var enumerable = matches as string[] ?? matches.ToArray(); if (enumerable.Any()) { h.LinkedDASSerials = enumerable.ToArray(); } } } } }