// Copyright (C) Stichting Deltares 2018. All rights reserved. // // This file is part of the application DAM - Clients Library. // // 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; using Deltares.Geotechnics.SurfaceLines; using Deltares.Standard; 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 { private string mapSoilProfile2D = null; private string sensorConfigurationFilename = null; private bool isImportAsRelativeProfiles; private CharacteristicPointType soilProfileCharacteristicPointReference; private List dataAttributes; private List dataSourceList = new List(); private string dataSourceEsriProjection = null; /// /// Initializes a new instance of the class. /// public DataSourceContainer() { this.dataAttributes = new List(); } /// /// Adds the specified attribute. /// /// The attribute. public void Add(DataAttribute attribute) { this.dataAttributes.Add(attribute); } /// /// Gets or sets the data source esri projection. /// /// /// The data source esri projection. /// public string DataSourceEsriProjection { get { return this.dataSourceEsriProjection; } set { this.dataSourceEsriProjection = value; } } /// /// Gets or sets the map soil profile2 d. /// /// /// The map soil profile2 d. /// public string MapSoilProfile2D { get { return this.mapSoilProfile2D; } set { this.mapSoilProfile2D = value; } } /// /// Gets or sets the sensor configuration filename. /// /// /// The sensor configuration filename. /// public string SensorConfigurationFilename { get { return this.sensorConfigurationFilename; } set { this.sensorConfigurationFilename = value; } } /// /// Gets or sets the soil profile characteristic point reference. /// /// /// The soil profile characteristic point reference. /// public CharacteristicPointType SoilProfileCharacteristicPointReference { get { return this.soilProfileCharacteristicPointReference; } set { this.soilProfileCharacteristicPointReference = value; } } /// /// 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 { return this.isImportAsRelativeProfiles; } set { this.isImportAsRelativeProfiles = value; } } /// /// Gets or sets the data source list. /// /// /// The data source list. /// public List DataSourceList { get { return this.dataSourceList; } set { this.dataSourceList = value; } } /// /// Gets or sets the data attributes. /// /// /// The data attributes. /// [XmlArrayItem("Attribute")] public List DataAttributes { get { return this.dataAttributes; } set { this.dataAttributes = value; } } /// /// 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 (var attribute in container.DataAttributes.Where(attribute => !allowedAttributes.Contains(attribute.AttributeName))) { yield return new NotSupportedException(string.Format("The attribute {0} is not supported.", attribute)); } } } } }