// Copyright (C) Stichting Deltares 2025. All rights reserved. // // This file is part of the application DAM - UI. // // DAM - UI is free software: you can redistribute it and/or modify // it under the terms of the GNU 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 General Public License for more details. // // You should have received a copy of the GNU 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; using System.Collections.Generic; using System.Linq; using System.Xml.Serialization; using Deltares.Geotechnics.SurfaceLines; using Deltares.Standard.IO; using Deltares.Standard.IO.Xml; using XmlSerializer = Deltares.Standard.IO.Xml.XmlSerializer; namespace Deltares.Dam.Data.DataPlugins.Configuration; public class DataSourceContainer { /// /// Initializes a new instance of the class. /// public DataSourceContainer() { DataAttributes = new List(); } /// /// Gets or sets the data source esri projection. /// /// /// The data source esri projection. /// public string DataSourceEsriProjection { get; set; } = null; /// /// Gets or sets the map soil profile2 d. /// /// /// The map soil profile2 d. /// public string MapSoilProfile2D { get; set; } = null; /// /// Gets or sets the sensor configuration filename. /// /// /// The sensor configuration filename. /// public string SensorConfigurationFilename { get; set; } = null; /// /// Gets or sets the soil profile characteristic point reference. /// /// /// The soil profile characteristic point reference. /// public CharacteristicPointType SoilProfileCharacteristicPointReference { get; set; } /// /// Gets or sets a value indicating whether this instance is import as relative profiles. /// /// /// true if this instance is import as relative profiles; otherwise, false. /// public bool IsImportAsRelativeProfiles { get; set; } /// /// Gets or sets the data source list. /// /// /// The data source list. /// public List DataSourceList { get; set; } = new List(); /// /// Gets or sets the data attributes. /// /// /// The data attributes. /// [XmlArrayItem("Attribute")] public List DataAttributes { get; set; } /// /// Adds the specified attribute. /// /// The attribute. public void Add(DataAttribute attribute) { DataAttributes.Add(attribute); } /// /// Serializes the specified container. /// /// The container. /// The file. /// /// container /// or /// file /// public static void Serialize(DataSourceContainer container, string file) { if (container == null) { throw new ArgumentNullException("container"); } if (file == null) { throw new ArgumentNullException("file"); } var xmlSerializer = new XmlSerializer(); xmlSerializer.Serialize(container, file); } /// /// Deserializes the specified file. /// /// The file. /// /// file public static DataSourceContainer Deserialize(string file) { if (file == null) { throw new ArgumentNullException("file"); } var xmlDeserializer = new XmlDeserializer(); var classFactory = new DefaultClassFactory(); var container = (DataSourceContainer) xmlDeserializer.XmlDeserialize(file, typeof(DataSourceContainer), classFactory); return container; } /// /// Validates the specified container. /// /// The container. /// The allowed attributes. /// /// /// container /// or /// allowedAttributes /// public static IEnumerable Validate(DataSourceContainer container, IEnumerable allowedAttributes) { if (container == null) { throw new ArgumentNullException("container"); } if (allowedAttributes == null) { throw new ArgumentNullException("allowedAttributes"); } if (container.DataAttributes != null) { foreach (DataAttribute attribute in container.DataAttributes.Where(attribute => !allowedAttributes.Contains(attribute.AttributeName))) { yield return new NotSupportedException($"The attribute {attribute} is not supported."); } } } }