//-----------------------------------------------------------------------
//
// Copyright (c) 2011 Deltares. All rights reserved.
//
// Tom The
// tom.the@deltares.nl
// 05-04-2011
// Container for list of data sources for serialization
//-----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Serialization;
using Deltares.Geotechnics;
using Deltares.Standard;
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));
}
}
}
}
}