init
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
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;
|
||||
public List<IUIItems> UIItems { get; set; }
|
||||
|
||||
public XMLParseProcessor(ImportObject importObject, IImportNotification importNotification, IEnumerable<string> fileNames, Func<bool> isCancelled)
|
||||
{
|
||||
_fileNames = fileNames;
|
||||
_importObject = importObject;
|
||||
_importNotification = importNotification;
|
||||
_isCancelled = isCancelled;
|
||||
}
|
||||
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);
|
||||
//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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user