// Copyright (C) Stichting Deltares 2016. 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; using System.Collections.Generic; using System.Linq; using Application.Ringtoets.Storage.DbContext; using Core.Common.Base.Data; using Ringtoets.Common.Data.AssessmentSection; namespace Application.Ringtoets.Storage.Read { /// /// Extension methods for read operations for /// based on the . /// internal static class BackgroundDataEntityReadExtensions { /// /// Read the and use the information /// to construct . /// /// The /// to create for. /// A new . /// Thrown when /// is null. internal static BackgroundData Read(this BackgroundDataEntity entity) { if (entity == null) { throw new ArgumentNullException(nameof(entity)); } IBackgroundDataConfiguration configuration = null; if ((BackgroundDataType) entity.BackgroundDataType == BackgroundDataType.Wmts) { configuration = ReadWmtsConfiguration(entity.BackgroundDataMetaEntities); } else if ((BackgroundDataType) entity.BackgroundDataType == BackgroundDataType.WellKnown) { configuration = ReadWellKnownConfiguration(entity.BackgroundDataMetaEntities); } var backgroundData = new BackgroundData(configuration) { IsVisible = Convert.ToBoolean(entity.IsVisible), Transparency = (RoundedDouble) entity.Transparency, Name = entity.Name }; return backgroundData; } private static IBackgroundDataConfiguration ReadWmtsConfiguration(IEnumerable backgroundDataMetaEntities) { string sourceCapabilitiesUrl = null; string selectedCapabilityIdentifier = null; string preferredFormat = null; bool isConfigured = Convert.ToBoolean(Convert.ToInt16(backgroundDataMetaEntities .Single(entity => entity.Key.Equals(BackgroundDataIdentifiers.IsConfigured)) .Read().Value)); if (isConfigured) { foreach (BackgroundDataMetaEntity backgroundDataMetaEntity in backgroundDataMetaEntities) { if (backgroundDataMetaEntity.Key.Equals(BackgroundDataIdentifiers.SourceCapabilitiesUrl)) { sourceCapabilitiesUrl = backgroundDataMetaEntity.Read().Value; } if (backgroundDataMetaEntity.Key.Equals(BackgroundDataIdentifiers.SelectedCapabilityIdentifier)) { selectedCapabilityIdentifier = backgroundDataMetaEntity.Read().Value; } if (backgroundDataMetaEntity.Key.Equals(BackgroundDataIdentifiers.PreferredFormat)) { preferredFormat = backgroundDataMetaEntity.Read().Value; } } } return new WmtsBackgroundDataConfiguration(isConfigured, sourceCapabilitiesUrl, selectedCapabilityIdentifier, preferredFormat); } private static IBackgroundDataConfiguration ReadWellKnownConfiguration(IEnumerable backgroundDataMetaEntities) { KeyValuePair parameter = backgroundDataMetaEntities.Single(metaEntity => metaEntity.Key.Equals(BackgroundDataIdentifiers.WellKnownTileSource)) .Read(); var wellKnownTileSource = (RingtoetsWellKnownTileSource) Convert.ToInt32(parameter.Value); return new WellKnownBackgroundDataConfiguration(wellKnownTileSource); } } }