using System.Reflection; using System.Xml.Linq; using Deltares.DamEngine.Data.Geotechnics; namespace Deltares.DamEngine.Calculators.KernelWrappers.DamMacroStability.Assemblers { public class SoilLayerAssembler : DtoAssembler { #region Constant declarations /// /// Holds the common part of the path to the embedded resource /// private const string EmbeddedResourcePath = "Deltares.Dam.Data.Xsd"; private const string XMLAttributeDummyID = "dummyID"; /// /// Holds the xml element name /// public const string XmlElementName = "Layer"; /// /// Holds the xml namespace /// private const string XmlElementNamespace = "http://deltares.nl/2008/" + XmlShemaName; /// /// Holds the name of the xml schema /// private const string XmlShemaName = "ProfileDefinition"; /// /// Holds the xsd resource path /// private const string XsdEmbeddedResourcePath = EmbeddedResourcePath + "." + XmlShemaName + ".xsd"; #endregion public SoilLayerAssembler() : base(XmlElementName, XmlElementNamespace, Assembly.GetExecutingAssembly().GetEmbeddedFile(XsdEmbeddedResourcePath)) { this.AddOrUpdateMapping("Id", XMLAttributeDummyID); this.AddOrUpdateMapping("Name", "ID"); } public override SoilLayer1D CreateDomainObject(XElement dtoObj) { SoilLayer1D soilLayer = base.CreateDomainObject(dtoObj); soilLayer.Soil = new Soil(); return soilLayer; } public override XElement CreateDataTransferObject(SoilLayer1D soilLayer) { XElement el = base.CreateDataTransferObject(soilLayer); XAttribute at = el.Attribute(XMLAttributeDummyID); if (at != null) at.Remove(); at = new XAttribute("SoilID", soilLayer.Soil != null ? soilLayer.Soil.Name : ""); el.Add(at); return el; } } }