// Copyright (C) Stichting Deltares 2017. All rights reserved.
//
// This file is part of Ringtoets.
//
// Ringtoets 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;
namespace Ringtoets.Common.Data.AssessmentSection
{
///
/// A background data configuration of WMTS tile sources.
///
public class WmtsBackgroundDataConfiguration : IBackgroundDataConfiguration
{
///
/// Creates a new instance of that is not configured.
///
public WmtsBackgroundDataConfiguration() : this(false, null, null, null) {}
///
/// Creates a new instance of that is configured.
///
/// Indicates if the configuration is configured to use as a tile source.
/// The URL to the capabilities of the WMTS.
/// The name of the capability to use.
/// The MIME-type specification of the preferred tile image format.
/// Thrown when any of the parameters are null when
/// is true.
/// /// Thrown when any of the parameters are not null when
/// is false.
public WmtsBackgroundDataConfiguration(bool isConfigured, string sourceCapabilitiesUrl,
string selectedCapabilityIdentifier, string preferredFormat)
{
if (isConfigured)
{
InitalizeConfiguredWmtsBackgroundDataConfiguration(sourceCapabilitiesUrl,
selectedCapabilityIdentifier,
preferredFormat);
}
else
{
InitalizeUnconfiguredWmtsBackgroundDataConfiguration(sourceCapabilitiesUrl,
selectedCapabilityIdentifier,
preferredFormat);
}
}
///
/// Gets if the configuration is ready to use as a tile source.
///
public bool IsConfigured { get; private set; }
///
/// Gets the URL to the capabilities of the WMTS.
///
public string SourceCapabilitiesUrl { get; private set; }
///
/// Gets the name of the capability to use.
///
public string SelectedCapabilityIdentifier { get; private set; }
///
/// Gets the MIME-type specification of the preferred tile image format.
///
public string PreferredFormat { get; private set; }
///
/// Initializes the properties of the corresponding
/// to an unconfigured WMTS tile source.
///
/// The URL to the capabilities of the WMTS.
/// The name of the capability to use.
/// The MIME-type specification of the preferred tile image format.
/// Thrown when any of the parameters are not null.
private void InitalizeUnconfiguredWmtsBackgroundDataConfiguration(string sourceCapabilitiesUrl,
string selectedCapabilityIdentifier,
string preferredFormat)
{
const string exceptionMessage = "Value must be null when instantiating an unconfigured configuration.";
if (sourceCapabilitiesUrl != null)
{
throw new ArgumentException(exceptionMessage, nameof(sourceCapabilitiesUrl));
}
if (selectedCapabilityIdentifier != null)
{
throw new ArgumentException(exceptionMessage, nameof(selectedCapabilityIdentifier));
}
if (preferredFormat != null)
{
throw new ArgumentException(exceptionMessage, nameof(preferredFormat));
}
IsConfigured = false;
}
///
/// Initializes the properties of the corresponding
/// to a configured WMTS tile source.
///
/// The URL to the capabilities of the WMTS.
/// The name of the capability to use.
/// The MIME-type specification of the preferred tile image format.
/// Thrown when any of the parameters are null.
private void InitalizeConfiguredWmtsBackgroundDataConfiguration(string sourceCapabilitiesUrl,
string selectedCapabilityIdentifier,
string preferredFormat)
{
if (sourceCapabilitiesUrl == null)
{
throw new ArgumentNullException(nameof(sourceCapabilitiesUrl));
}
if (selectedCapabilityIdentifier == null)
{
throw new ArgumentNullException(nameof(selectedCapabilityIdentifier));
}
if (preferredFormat == null)
{
throw new ArgumentNullException(nameof(preferredFormat));
}
IsConfigured = true;
SourceCapabilitiesUrl = sourceCapabilitiesUrl;
SelectedCapabilityIdentifier = selectedCapabilityIdentifier;
PreferredFormat = preferredFormat;
}
}
}