56 lines
2.1 KiB
C#
56 lines
2.1 KiB
C#
using DTS.Common.Enums.DBExport;
|
|
using DTS.Common.Import.Interfaces;
|
|
using DTS.Common.Interface.Groups.GroupList;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Xml;
|
|
|
|
namespace DTS.Common.Import.XML
|
|
{
|
|
public class XMLParseCustomerDetails : XMLParseBase
|
|
{
|
|
public XMLParseCustomerDetails(XmlElement root, double importedVersion, Func<bool> isCancelled = null) : base(root, importedVersion, isCancelled)
|
|
{
|
|
}
|
|
public IImportNotification ImportNotification { get; set; }
|
|
public override void Parse(ref ImportObject importObject)
|
|
{
|
|
ImportNotification?.SetStatus(new ImportStatus { PossibleStatus = Enums.PossibleStatus.Reading, ExtraStatus = Enums.ImportExtraStatus.ReadingCustomerDetails });
|
|
var customerDetails = ParseCustomerDetails(_root);
|
|
var newRoot = ConvertCustomerDetails(customerDetails);
|
|
customerDetails = ParseCustomerDetails(newRoot);
|
|
importObject.AddCustomerDetailsList(customerDetails);
|
|
}
|
|
|
|
private XmlElement ConvertCustomerDetails(IEnumerable<ISO.CustomerDetails> customerDetails)
|
|
{
|
|
_writer.WriteStartElement(TopLevelFields.CustomerDetails.ToString());
|
|
foreach (var c in customerDetails)
|
|
{
|
|
_writer.Flush();
|
|
c.WriteXML(ref _writer);
|
|
_writer.Flush();
|
|
}
|
|
|
|
_writer.WriteEndElement();
|
|
return GetXmlElement();
|
|
}
|
|
private List<ISO.CustomerDetails> ParseCustomerDetails(XmlElement root)
|
|
{
|
|
List<ISO.CustomerDetails> customerDetails = new List<ISO.CustomerDetails>();
|
|
foreach (var node in root.ChildNodes)
|
|
{
|
|
if (IsCancelled()) { return customerDetails; }
|
|
if (node is XmlElement)
|
|
{
|
|
customerDetails.Add(ISO.CustomerDetails.ReadXML(node as XmlElement));
|
|
}
|
|
}
|
|
return customerDetails;
|
|
}
|
|
}
|
|
}
|