using DTS.Common.Import.Interfaces; using System; using System.Collections.Generic; using System.Xml; namespace DTS.Common.Import.XML { public abstract class XMLParseBase : IParseVariant { protected static readonly Dictionary _dasIdMapping = new Dictionary(); //Use string to handle both new (Id (int.ToString())) and old (Name (string)) exports protected static readonly Dictionary _groupIdMapping = new Dictionary(); protected static readonly Dictionary _sensorIdMapping = new Dictionary(); protected static readonly Dictionary _channelIdMapping = new Dictionary(); protected double _importedVersion; protected readonly Func IsCancelled; protected readonly XmlElement _root; protected XmlWriter _writer; protected bool _skipNormalizing; private readonly XmlDocument _doc; public string FileName { get; set; } public abstract void Parse(ref ImportObject importObject); protected XMLParseBase(XmlElement root, double importedVersion, Func isCancelled = null, bool skipNormalizing = false) { _importedVersion = importedVersion; IsCancelled = isCancelled == null ? () => false : isCancelled; _root = root; _skipNormalizing = skipNormalizing; _doc = new XmlDocument(); _writer = _doc.CreateNavigator().AppendChild(); } protected XmlElement GetXmlElement() { _writer.Close(); return _doc.DocumentElement; } } }