// Copyright (C) Stichting Deltares 2024. All rights reserved. // // This file is part of the Dam Engine. // // The Dam Engine is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Affero General Public License for more details. // // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . // // All names, logos, and references to "Deltares" are registered trademarks of // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. using System.Reflection; using System.Xml.Linq; using Deltares.DamEngine.Data.Geotechnics; namespace Deltares.DamEngine.Calculators.KernelWrappers.Assemblers; public class SoilLayerAssembler : DtoAssembler { /// /// Initializes a new instance of the class. /// public SoilLayerAssembler() : base(XmlElementName, xmlElementNamespace, Assembly.GetExecutingAssembly().GetEmbeddedFile(xsdEmbeddedResourcePath)) { AddOrUpdateMapping("Id", xmlAttributeDummyId); AddOrUpdateMapping("Name", "ID"); } /// /// override for CreateDomainObject /// /// /// public override SoilLayer1D CreateDomainObject(XElement dtoObj) { SoilLayer1D soilLayer = base.CreateDomainObject(dtoObj); soilLayer.Soil = new Soil(); return soilLayer; } /// /// Creates the data transfer object. /// /// The soil layer. /// 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; } #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 }