Index: Core/Components/src/Core.Components.DotSpatial.Forms/Core.Components.DotSpatial.Forms.csproj =================================================================== diff -u -r396d39591f11aad05a6cd0e66ead43fefd9713c3 -r5b2528a7b0f0443681e0fbeba5793d2aa00c98c0 --- Core/Components/src/Core.Components.DotSpatial.Forms/Core.Components.DotSpatial.Forms.csproj (.../Core.Components.DotSpatial.Forms.csproj) (revision 396d39591f11aad05a6cd0e66ead43fefd9713c3) +++ Core/Components/src/Core.Components.DotSpatial.Forms/Core.Components.DotSpatial.Forms.csproj (.../Core.Components.DotSpatial.Forms.csproj) (revision 5b2528a7b0f0443681e0fbeba5793d2aa00c98c0) @@ -75,6 +75,7 @@ UserControl + Component Index: Core/Components/src/Core.Components.DotSpatial.Forms/IBackgroundLayerStatus.cs =================================================================== diff -u --- Core/Components/src/Core.Components.DotSpatial.Forms/IBackgroundLayerStatus.cs (revision 0) +++ Core/Components/src/Core.Components.DotSpatial.Forms/IBackgroundLayerStatus.cs (revision 5b2528a7b0f0443681e0fbeba5793d2aa00c98c0) @@ -0,0 +1,71 @@ +// 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 Lesser 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 Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser 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 Core.Components.DotSpatial.Layer.BruTile; +using Core.Components.Gis.Data; + +namespace Core.Components.DotSpatial.Forms +{ + internal interface IBackgroundLayerStatus : IDisposable + { + /// + /// Gets a value indicating that the most recent attempt to create the background + /// layer failed (returning true) or was successful (returning false). + /// + bool PreviousBackgroundLayerCreationFailed { get; } + + /// + /// Gets a value for the initialized background layer. + /// + BruTileLayer BackgroundLayer { get; } + + /// + /// Mark that a (new) background layer has successfully been initialized. + /// + /// The constructed layer. + /// The data used to construct . + /// Thrown when any of the input parameters is null. + void SuccessfullyInitializedLayer(BruTileLayer backgroundLayer, ImageBasedMapData dataSource); + + /// + /// Mark that the attempt to create a new background layer failed. + /// + void LayerInitializationFailed(); + + /// + /// Clears the status information for the background layer and disposes + /// as well. + /// + /// Optional: A flag to indicate + /// if recreation of with the same parameters is expected + /// (true) or is expected to be replaced (false) + void ClearConfiguration(bool expectRecreationOfSameBackgroundLayer = false); + + /// + /// Indicates if a corresponds with the . + /// + /// The map data. + /// Returns true if corresponds with + /// , or false when this is not the case. + bool HasSameConfiguration(ImageBasedMapData mapData); + } +} \ No newline at end of file Index: Core/Components/src/Core.Components.DotSpatial.Forms/WmtsBackgroundLayerStatus.cs =================================================================== diff -u -raeb0c6618ebf88db04e417b47693c704c7151181 -r5b2528a7b0f0443681e0fbeba5793d2aa00c98c0 --- Core/Components/src/Core.Components.DotSpatial.Forms/WmtsBackgroundLayerStatus.cs (.../WmtsBackgroundLayerStatus.cs) (revision aeb0c6618ebf88db04e417b47693c704c7151181) +++ Core/Components/src/Core.Components.DotSpatial.Forms/WmtsBackgroundLayerStatus.cs (.../WmtsBackgroundLayerStatus.cs) (revision 5b2528a7b0f0443681e0fbeba5793d2aa00c98c0) @@ -29,30 +29,18 @@ /// Class responsible for keeping track of various status information related to the /// used to create a background layer in a map view. /// - internal class WmtsBackgroundLayerStatus : IDisposable + internal class WmtsBackgroundLayerStatus : IBackgroundLayerStatus { + public bool PreviousBackgroundLayerCreationFailed { get; private set; } + + public BruTileLayer BackgroundLayer { get; private set; } + public void Dispose() { BackgroundLayer?.Dispose(); } - /// - /// Gets a value indicating that the most recent attempt to create the background - /// layer failed (returning true) or was successful (returning false). - /// - internal bool PreviousBackgroundLayerCreationFailed { get; private set; } - - /// - /// Gets a value for the initialized background layer. - /// - internal BruTileLayer BackgroundLayer { get; private set; } - - /// - /// Mark that a (new) background layer has successfully been initialized. - /// - /// The constructed layer. - /// The data used to construct . - internal void SuccessfullyInitializedLayer(BruTileLayer backgroundLayer, WmtsMapData dataSource) + public void SuccessfullyInitializedLayer(BruTileLayer backgroundLayer, ImageBasedMapData dataSource) { if (backgroundLayer == null) { @@ -62,32 +50,28 @@ { throw new ArgumentNullException(nameof(dataSource)); } + var wmtsDataSource = dataSource as WmtsMapData; + if (wmtsDataSource == null) + { + PreviousBackgroundLayerCreationFailed = true; + return; + } - SourceCapabilitiesUrl = dataSource.SourceCapabilitiesUrl; - SelectedCapabilityId = dataSource.SelectedCapabilityIdentifier; - PreferredFormat = dataSource.PreferredFormat; + SourceCapabilitiesUrl = wmtsDataSource.SourceCapabilitiesUrl; + SelectedCapabilityId = wmtsDataSource.SelectedCapabilityIdentifier; + PreferredFormat = wmtsDataSource.PreferredFormat; BackgroundLayer = backgroundLayer; PreviousBackgroundLayerCreationFailed = false; } - /// - /// Mark that the attempt to create a new background layer failed. - /// - internal void LayerInitializationFailed() + public void LayerInitializationFailed() { ClearConfiguration(); PreviousBackgroundLayerCreationFailed = true; } - /// - /// Clears the status information for the background layer and disposes - /// as well. - /// - /// Optional: A flag to indicate - /// if recreation of with the same parameters is expected - /// (true) or is expected to be replaced (false) - internal void ClearConfiguration(bool expectRecreationOfSameBackgroundLayer = false) + public void ClearConfiguration(bool expectRecreationOfSameBackgroundLayer = false) { SourceCapabilitiesUrl = null; SelectedCapabilityId = null; @@ -105,22 +89,22 @@ } } - /// - /// Indicates if a corresponds with the . - /// - /// The map data. - /// Returns true if corresponds with - /// , or false when this is not the case. - internal bool HasSameConfiguration(WmtsMapData mapData) + public bool HasSameConfiguration(ImageBasedMapData mapData) { if (mapData == null) { throw new ArgumentNullException(nameof(mapData)); } - return Equals(mapData.SourceCapabilitiesUrl, SourceCapabilitiesUrl) - && Equals(mapData.SelectedCapabilityIdentifier, SelectedCapabilityId) - && Equals(mapData.PreferredFormat, PreferredFormat); + var wmtsDataSource = mapData as WmtsMapData; + if (wmtsDataSource == null) + { + return false; + } + + return Equals(wmtsDataSource.SourceCapabilitiesUrl, SourceCapabilitiesUrl) + && Equals(wmtsDataSource.SelectedCapabilityIdentifier, SelectedCapabilityId) + && Equals(wmtsDataSource.PreferredFormat, PreferredFormat); } private string SourceCapabilitiesUrl { get; set; } Index: Core/Components/test/Core.Components.DotSpatial.Forms.Test/WmtsBackgroundLayerStatusTest.cs =================================================================== diff -u -r99f9004206bfb9de084275d749b7aeccafd6da18 -r5b2528a7b0f0443681e0fbeba5793d2aa00c98c0 --- Core/Components/test/Core.Components.DotSpatial.Forms.Test/WmtsBackgroundLayerStatusTest.cs (.../WmtsBackgroundLayerStatusTest.cs) (revision 99f9004206bfb9de084275d749b7aeccafd6da18) +++ Core/Components/test/Core.Components.DotSpatial.Forms.Test/WmtsBackgroundLayerStatusTest.cs (.../WmtsBackgroundLayerStatusTest.cs) (revision 5b2528a7b0f0443681e0fbeba5793d2aa00c98c0) @@ -63,6 +63,7 @@ using (var layerStatus = new WmtsBackgroundLayerStatus()) { // Assert + Assert.IsInstanceOf(layerStatus); Assert.IsInstanceOf(layerStatus); Assert.IsNull(layerStatus.BackgroundLayer); @@ -86,6 +87,22 @@ } [Test] + public void HasSameConfiguration_MapDataNotWmtsMapData_ReturnFalse() + { + // Setup + using (var layerStatus = new WmtsBackgroundLayerStatus()) + { + var mapData = new SimpleImageBasedMapData(); + + // Call + bool isSame = layerStatus.HasSameConfiguration(mapData); + + // Assert + Assert.IsFalse(isSame); + } + } + + [Test] public void HasSameConfiguration_NoInitializedLayer_ReturnFalse() { // Setup @@ -197,6 +214,28 @@ } [Test] + public void SuccessfullyInitializedLayer_MapDataNotWmtsMapData_ReturnsTrue() + { + // Setup + var mocks = new MockRepository(); + var tileFetcher = mocks.Stub(); + IConfiguration configuration = CreateStubConfiguration(mocks, tileFetcher); + mocks.ReplayAll(); + + using (var layer = new BruTileLayer(configuration)) + using (var layerStatus = new WmtsBackgroundLayerStatus()) + { + var mapData = new SimpleImageBasedMapData(); + + // Call + layerStatus.SuccessfullyInitializedLayer(layer, mapData); + + // Assert + Assert.IsTrue(layerStatus.PreviousBackgroundLayerCreationFailed); + } + } + + [Test] public void SuccessfullyInitializedLayer_InitializationPreviouslyFailed_PreviousBackgroundLayerCreationFailedFalse() { // Setup @@ -319,5 +358,10 @@ configuration.Stub(c => c.Dispose()); return configuration; } + + private class SimpleImageBasedMapData : ImageBasedMapData + { + public SimpleImageBasedMapData() : base("SimpleImageBasedMapData") {} + } } } \ No newline at end of file