Files
DP44/Common/DTS.Common.Import/XMLParseProcessor.cs

72 lines
2.9 KiB
C#
Raw Normal View History

2026-04-17 14:55:32 -04:00
using DTS.Common.Import.Enums;
using DTS.Common.Import.Interfaces;
using DTS.Common.Utils;
using DTS.Slice.Users;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DTS.Common.Import
{
public class XMLParseProcessor
{
private readonly IEnumerable<string> _fileNames;
private ImportObject _importObject;
private readonly IImportNotification _importNotification;
private readonly Func<bool> _isCancelled;
private readonly bool _skipNormalizing;
public List<IUIItems> UIItems { get; set; }
public XMLParseProcessor(ImportObject importObject, IImportNotification importNotification, IEnumerable<string> fileNames, Func<bool> isCancelled, bool skipNormalizing)
{
_fileNames = fileNames;
_importObject = importObject;
_importNotification = importNotification;
_isCancelled = isCancelled;
_skipNormalizing = skipNormalizing;
}
public ImportObject Process()
{
foreach (var fileName in _fileNames)
{
_importNotification.SetStatus.Invoke(new ImportStatus { ExtraStatus = ImportExtraStatus.ReadingXML, PossibleStatus = PossibleStatus.Working });
XmlParserFactory.UIItems = UIItems;
var parseVariants = XmlParserFactory.CreateXMLParsers(fileName, _importNotification, _isCancelled, _skipNormalizing);
//FB 36879 Prevent exception if there is no variants to parse
double itemsToComplete = 0;
if (parseVariants.Any())
{
itemsToComplete = XMLUtils.DTSXMLFile.GetItemsToCompleteCount(fileName);
}
foreach (var variant in parseVariants)
{
variant.Parse(ref _importObject);
NotifyProgress(itemsToComplete);
}
}
return _importObject;
}
private void NotifyProgress(double itemsToComplete)
{
if (itemsToComplete <= 0) { return; }
var completed = _importObject.Calibrations().Count() + _importObject.Sensors().Count() + _importObject.CustomChannels().Count()
+ _importObject.Groups().Count() + _importObject.GroupTemplates().Count() +
_importObject.TestSetups().Count() + _importObject.Hardware().Count()
+ _importObject.CustomerDetails().Count() + _importObject.TestEngineerDetails().Count() + _importObject.LabDetails().Count();
double progress = completed / itemsToComplete;
if (progress >= 1)
{
progress = 1;
}
_importNotification.SetProgress(progress);
}
}
}