Index: Core/Components/src/Core.Components.DotSpatial.Forms/BackgroundLayerStatus.cs =================================================================== diff -u --- Core/Components/src/Core.Components.DotSpatial.Forms/BackgroundLayerStatus.cs (revision 0) +++ Core/Components/src/Core.Components.DotSpatial.Forms/BackgroundLayerStatus.cs (revision 5f0893eb7fb4e2e25ae762ef20aa05eac0e40acf) @@ -0,0 +1,117 @@ +// 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 +{ + /// + /// Abstract class for keeping track of various status information related to the + /// used to create a background layer in a map view. + /// + internal abstract class BackgroundLayerStatus : IDisposable + { + /// + /// Gets a value indicating that the most recent attempt to create the background + /// layer failed (returning true) or was successful (returning false). + /// + public bool PreviousBackgroundLayerCreationFailed { get; protected set; } + + /// + /// Gets the initialized background layer. + /// + public BruTileLayer BackgroundLayer { get; protected set; } + + /// + /// 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. + public void LayerInitializationSuccessful(BruTileLayer backgroundLayer, ImageBasedMapData dataSource) + { + if (backgroundLayer == null) + { + throw new ArgumentNullException(nameof(backgroundLayer)); + } + if (dataSource == null) + { + throw new ArgumentNullException(nameof(dataSource)); + } + + OnLayerInitializationSuccessful(backgroundLayer, dataSource); + } + + /// + /// Mark that the attempt to create a new background layer failed. + /// + 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). + public abstract 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. + public bool HasSameConfiguration(ImageBasedMapData mapData) + { + if (mapData == null) + { + throw new ArgumentNullException(nameof(mapData)); + } + + return OnHasSameConfiguration(mapData); + } + + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + protected virtual void Dispose(bool disposing) + { + if (disposing) + { + BackgroundLayer?.Dispose(); + } + } + + protected abstract void OnLayerInitializationSuccessful(BruTileLayer backgroundLayer, ImageBasedMapData dataSource); + + protected abstract bool OnHasSameConfiguration(ImageBasedMapData mapData); + } +} \ No newline at end of file Index: Core/Components/src/Core.Components.DotSpatial.Forms/BackgroundLayerStatusFactory.cs =================================================================== diff -u -r797872a6e0525f12c0f84b03e996a9d42630ad0b -r5f0893eb7fb4e2e25ae762ef20aa05eac0e40acf --- Core/Components/src/Core.Components.DotSpatial.Forms/BackgroundLayerStatusFactory.cs (.../BackgroundLayerStatusFactory.cs) (revision 797872a6e0525f12c0f84b03e996a9d42630ad0b) +++ Core/Components/src/Core.Components.DotSpatial.Forms/BackgroundLayerStatusFactory.cs (.../BackgroundLayerStatusFactory.cs) (revision 5f0893eb7fb4e2e25ae762ef20aa05eac0e40acf) @@ -25,22 +25,22 @@ namespace Core.Components.DotSpatial.Forms { /// - /// Factory for creating . + /// Factory for creating . /// public static class BackgroundLayerStatusFactory { /// - /// Creates a new instance of corresponding to + /// Creates a new instance of corresponding to /// the type of . /// /// The type of to create a - /// for. - /// A new instance of . + /// for. + /// A new instance of . /// Thrown when /// is null. /// Thrown when the type of /// is not supported. - internal static IBackgroundLayerStatus CreateBackgroundLayerStatus(ImageBasedMapData mapData) + internal static BackgroundLayerStatus CreateBackgroundLayerStatus(ImageBasedMapData mapData) { if (mapData == null) { Index: Core/Components/src/Core.Components.DotSpatial.Forms/Core.Components.DotSpatial.Forms.csproj =================================================================== diff -u -rbb84e8f229fbe284207a2ca2f4ce2244f4ce6076 -r5f0893eb7fb4e2e25ae762ef20aa05eac0e40acf --- Core/Components/src/Core.Components.DotSpatial.Forms/Core.Components.DotSpatial.Forms.csproj (.../Core.Components.DotSpatial.Forms.csproj) (revision bb84e8f229fbe284207a2ca2f4ce2244f4ce6076) +++ Core/Components/src/Core.Components.DotSpatial.Forms/Core.Components.DotSpatial.Forms.csproj (.../Core.Components.DotSpatial.Forms.csproj) (revision 5f0893eb7fb4e2e25ae762ef20aa05eac0e40acf) @@ -76,7 +76,7 @@ UserControl - + Component Fisheye: Tag 5f0893eb7fb4e2e25ae762ef20aa05eac0e40acf refers to a dead (removed) revision in file `Core/Components/src/Core.Components.DotSpatial.Forms/IBackgroundLayerStatus.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Core/Components/src/Core.Components.DotSpatial.Forms/MapControl.cs =================================================================== diff -u -rbb84e8f229fbe284207a2ca2f4ce2244f4ce6076 -r5f0893eb7fb4e2e25ae762ef20aa05eac0e40acf --- Core/Components/src/Core.Components.DotSpatial.Forms/MapControl.cs (.../MapControl.cs) (revision bb84e8f229fbe284207a2ca2f4ce2244f4ce6076) +++ Core/Components/src/Core.Components.DotSpatial.Forms/MapControl.cs (.../MapControl.cs) (revision 5f0893eb7fb4e2e25ae762ef20aa05eac0e40acf) @@ -60,7 +60,7 @@ private RdNewMouseCoordinatesMapExtension mouseCoordinatesMapExtension; private MapDataCollection data; - private IBackgroundLayerStatus backgroundLayerStatus; + private BackgroundLayerStatus backgroundLayerStatus; private ImageBasedMapData backgroundMapData; /// Index: Core/Components/src/Core.Components.DotSpatial.Forms/WellKnownBackgroundLayerStatus.cs =================================================================== diff -u -r797872a6e0525f12c0f84b03e996a9d42630ad0b -r5f0893eb7fb4e2e25ae762ef20aa05eac0e40acf --- Core/Components/src/Core.Components.DotSpatial.Forms/WellKnownBackgroundLayerStatus.cs (.../WellKnownBackgroundLayerStatus.cs) (revision 797872a6e0525f12c0f84b03e996a9d42630ad0b) +++ Core/Components/src/Core.Components.DotSpatial.Forms/WellKnownBackgroundLayerStatus.cs (.../WellKnownBackgroundLayerStatus.cs) (revision 5f0893eb7fb4e2e25ae762ef20aa05eac0e40acf) @@ -19,7 +19,6 @@ // 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; @@ -29,77 +28,46 @@ /// Class responsible for keeping track of various status information related to the /// used to create a background layer in a map control. /// - internal class WellKnownBackgroundLayerStatus : IBackgroundLayerStatus + internal class WellKnownBackgroundLayerStatus : BackgroundLayerStatus { - public bool PreviousBackgroundLayerCreationFailed { get; private set; } + private WellKnownTileSource? wellKnownTileSource; - public BruTileLayer BackgroundLayer { get; private set; } - - public virtual void Dispose() + public override void ClearConfiguration(bool expectRecreationOfSameBackgroundLayer = false) { - BackgroundLayer?.Dispose(); - } + wellKnownTileSource = null; - public void LayerInitializationSuccessful(BruTileLayer backgroundLayer, ImageBasedMapData dataSource) - { - if (backgroundLayer == null) + if (BackgroundLayer != null) { - throw new ArgumentNullException(nameof(backgroundLayer)); + BackgroundLayer.Dispose(); + BackgroundLayer = null; } - if (dataSource == null) + + if (!expectRecreationOfSameBackgroundLayer) { - throw new ArgumentNullException(nameof(dataSource)); + PreviousBackgroundLayerCreationFailed = false; } + } + + protected override void OnLayerInitializationSuccessful(BruTileLayer backgroundLayer, ImageBasedMapData dataSource) + { var wellKnownTileSourceMapData = dataSource as WellKnownTileSourceMapData; if (wellKnownTileSourceMapData == null) { PreviousBackgroundLayerCreationFailed = true; return; } - WellKnownTileSource = wellKnownTileSourceMapData.TileSource; + wellKnownTileSource = wellKnownTileSourceMapData.TileSource; BackgroundLayer = backgroundLayer; PreviousBackgroundLayerCreationFailed = false; } - public void LayerInitializationFailed() + protected override bool OnHasSameConfiguration(ImageBasedMapData mapData) { - ClearConfiguration(); - PreviousBackgroundLayerCreationFailed = true; - } - - public void ClearConfiguration(bool expectRecreationOfSameBackgroundLayer = false) - { - WellKnownTileSource = null; - - if (BackgroundLayer != null) - { - BackgroundLayer.Dispose(); - BackgroundLayer = null; - } - - if (!expectRecreationOfSameBackgroundLayer) - { - PreviousBackgroundLayerCreationFailed = false; - } - } - - public bool HasSameConfiguration(ImageBasedMapData mapData) - { - if (mapData == null) - { - throw new ArgumentNullException(nameof(mapData)); - } - var wellKnownTileSourceMapData = mapData as WellKnownTileSourceMapData; - if (wellKnownTileSourceMapData == null) - { - return false; - } - return Equals(wellKnownTileSourceMapData.TileSource, WellKnownTileSource); + return wellKnownTileSourceMapData != null + && Equals(wellKnownTileSourceMapData.TileSource, wellKnownTileSource); } - - private WellKnownTileSource? WellKnownTileSource { get; set; } } } \ No newline at end of file Index: Core/Components/src/Core.Components.DotSpatial.Forms/WmtsBackgroundLayerStatus.cs =================================================================== diff -u -r797872a6e0525f12c0f84b03e996a9d42630ad0b -r5f0893eb7fb4e2e25ae762ef20aa05eac0e40acf --- Core/Components/src/Core.Components.DotSpatial.Forms/WmtsBackgroundLayerStatus.cs (.../WmtsBackgroundLayerStatus.cs) (revision 797872a6e0525f12c0f84b03e996a9d42630ad0b) +++ Core/Components/src/Core.Components.DotSpatial.Forms/WmtsBackgroundLayerStatus.cs (.../WmtsBackgroundLayerStatus.cs) (revision 5f0893eb7fb4e2e25ae762ef20aa05eac0e40acf) @@ -19,7 +19,6 @@ // 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; @@ -29,54 +28,35 @@ /// Class responsible for keeping track of various status information related to the /// used to create a background layer in a map control. /// - internal class WmtsBackgroundLayerStatus : IBackgroundLayerStatus + internal class WmtsBackgroundLayerStatus : BackgroundLayerStatus { - public bool PreviousBackgroundLayerCreationFailed { get; private set; } + private string sourceCapabilitiesUrl; + private string selectedCapabilityId; + private string preferredFormat; - public BruTileLayer BackgroundLayer { get; private set; } - - public void Dispose() + protected override void OnLayerInitializationSuccessful(BruTileLayer backgroundLayer, ImageBasedMapData dataSource) { - BackgroundLayer?.Dispose(); - } - - public void LayerInitializationSuccessful(BruTileLayer backgroundLayer, ImageBasedMapData dataSource) - { - if (backgroundLayer == null) - { - throw new ArgumentNullException(nameof(backgroundLayer)); - } - if (dataSource == null) - { - throw new ArgumentNullException(nameof(dataSource)); - } var wmtsDataSource = dataSource as WmtsMapData; if (wmtsDataSource == null) { PreviousBackgroundLayerCreationFailed = true; return; } - SourceCapabilitiesUrl = wmtsDataSource.SourceCapabilitiesUrl; - SelectedCapabilityId = wmtsDataSource.SelectedCapabilityIdentifier; - PreferredFormat = wmtsDataSource.PreferredFormat; + sourceCapabilitiesUrl = wmtsDataSource.SourceCapabilitiesUrl; + selectedCapabilityId = wmtsDataSource.SelectedCapabilityIdentifier; + preferredFormat = wmtsDataSource.PreferredFormat; BackgroundLayer = backgroundLayer; PreviousBackgroundLayerCreationFailed = false; } - public void LayerInitializationFailed() + public override void ClearConfiguration(bool expectRecreationOfSameBackgroundLayer = false) { - ClearConfiguration(); - PreviousBackgroundLayerCreationFailed = true; - } + sourceCapabilitiesUrl = null; + selectedCapabilityId = null; + preferredFormat = null; - public void ClearConfiguration(bool expectRecreationOfSameBackgroundLayer = false) - { - SourceCapabilitiesUrl = null; - SelectedCapabilityId = null; - PreferredFormat = null; - if (BackgroundLayer != null) { BackgroundLayer.Dispose(); @@ -89,26 +69,13 @@ } } - public bool HasSameConfiguration(ImageBasedMapData mapData) + protected override bool OnHasSameConfiguration(ImageBasedMapData mapData) { - if (mapData == null) - { - throw new ArgumentNullException(nameof(mapData)); - } - var wmtsDataSource = mapData as WmtsMapData; - if (wmtsDataSource == null) - { - return false; - } - - return Equals(wmtsDataSource.SourceCapabilitiesUrl, SourceCapabilitiesUrl) - && Equals(wmtsDataSource.SelectedCapabilityIdentifier, SelectedCapabilityId) - && Equals(wmtsDataSource.PreferredFormat, PreferredFormat); + return wmtsDataSource != null + && Equals(wmtsDataSource.SourceCapabilitiesUrl, sourceCapabilitiesUrl) + && Equals(wmtsDataSource.SelectedCapabilityIdentifier, selectedCapabilityId) + && Equals(wmtsDataSource.PreferredFormat, preferredFormat); } - - private string SourceCapabilitiesUrl { get; set; } - private string SelectedCapabilityId { get; set; } - private string PreferredFormat { get; set; } } } \ No newline at end of file Index: Core/Components/test/Core.Components.DotSpatial.Forms.Test/BackgroundLayerStatusFactoryTest.cs =================================================================== diff -u -r13a7121f09c123fe08031a03d3aa598d9800b372 -r5f0893eb7fb4e2e25ae762ef20aa05eac0e40acf --- Core/Components/test/Core.Components.DotSpatial.Forms.Test/BackgroundLayerStatusFactoryTest.cs (.../BackgroundLayerStatusFactoryTest.cs) (revision 13a7121f09c123fe08031a03d3aa598d9800b372) +++ Core/Components/test/Core.Components.DotSpatial.Forms.Test/BackgroundLayerStatusFactoryTest.cs (.../BackgroundLayerStatusFactoryTest.cs) (revision 5f0893eb7fb4e2e25ae762ef20aa05eac0e40acf) @@ -61,7 +61,7 @@ WmtsMapData mapData = WmtsMapData.CreateAlternativePdokMapData(); // Call - IBackgroundLayerStatus backgroundLayerStatus = BackgroundLayerStatusFactory.CreateBackgroundLayerStatus(mapData); + BackgroundLayerStatus backgroundLayerStatus = BackgroundLayerStatusFactory.CreateBackgroundLayerStatus(mapData); // Assert Assert.IsInstanceOf(backgroundLayerStatus); @@ -74,7 +74,7 @@ var mapData = new WellKnownTileSourceMapData(new Random().NextEnum()); // Call - IBackgroundLayerStatus backgroundLayerStatus = BackgroundLayerStatusFactory.CreateBackgroundLayerStatus(mapData); + BackgroundLayerStatus backgroundLayerStatus = BackgroundLayerStatusFactory.CreateBackgroundLayerStatus(mapData); // Assert Assert.IsInstanceOf(backgroundLayerStatus); Index: Core/Components/test/Core.Components.DotSpatial.Forms.Test/BackgroundLayerStatusTest.cs =================================================================== diff -u --- Core/Components/test/Core.Components.DotSpatial.Forms.Test/BackgroundLayerStatusTest.cs (revision 0) +++ Core/Components/test/Core.Components.DotSpatial.Forms.Test/BackgroundLayerStatusTest.cs (revision 5f0893eb7fb4e2e25ae762ef20aa05eac0e40acf) @@ -0,0 +1,153 @@ +// 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 BruTile; +using Core.Components.BruTile.Configurations; +using Core.Components.BruTile.IO; +using Core.Components.DotSpatial.Layer.BruTile; +using Core.Components.Gis.Data; +using Core.Components.Gis.TestUtil; +using NUnit.Framework; +using Rhino.Mocks; + +namespace Core.Components.DotSpatial.Forms.Test +{ + [TestFixture] + public class BackgroundLayerStatusTest + { + [Test] + public void Constructor_ExpectedValues() + { + // Call + using (var layerStatus = new SimpleBackgroundLayerStatus()) + { + // Assert + Assert.IsInstanceOf(layerStatus); + + Assert.IsNull(layerStatus.BackgroundLayer); + Assert.IsFalse(layerStatus.PreviousBackgroundLayerCreationFailed); + } + } + + [Test] + public void HasSameConfiguration_MapDataNull_ThrowArgumentNullException() + { + // Setup + using (var layerStatus = new SimpleBackgroundLayerStatus()) + { + // Call + TestDelegate call = () => layerStatus.HasSameConfiguration(null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("mapData", paramName); + } + } + + [Test] + public void LayerInitializationSuccessful_LayerNull_ThrowArgumentNullException() + { + // Setup + using (var layerStatus = new SimpleBackgroundLayerStatus()) + { + var dataSource = new TestImageBasedMapData("Test", false); + + // Call + TestDelegate call = () => layerStatus.LayerInitializationSuccessful(null, dataSource); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("backgroundLayer", paramName); + } + } + + [Test] + public void LayerInitializationSuccessful_MapDataNull_ThrowArgumentNullException() + { + // 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 SimpleBackgroundLayerStatus()) + { + // Call + TestDelegate call = () => layerStatus.LayerInitializationSuccessful(layer, null); + + // Assert + string paramName = Assert.Throws(call).ParamName; + Assert.AreEqual("dataSource", paramName); + } + } + + [Test] + public void LayerInitializationFailed_PreviousBackgroundLayerCreationFailedAndConfigurationClearedTrue() + { + // Setup + using (var layerStatus = new SimpleBackgroundLayerStatus()) + { + // Call + layerStatus.LayerInitializationFailed(); + + // Assert + Assert.IsTrue(layerStatus.PreviousBackgroundLayerCreationFailed); + Assert.IsTrue(layerStatus.ConfigurationCleared); + } + } + + private static IConfiguration CreateStubConfiguration(MockRepository mocks, ITileFetcher tileFetcher) + { + var schema = mocks.Stub(); + schema.Stub(s => s.Srs).Return("EPSG:28992"); + schema.Stub(s => s.Extent).Return(new Extent()); + + var configuration = mocks.Stub(); + configuration.Stub(c => c.Initialized).Return(true); + configuration.Stub(c => c.TileSchema).Return(schema); + configuration.Stub(c => c.TileFetcher).Return(tileFetcher); + configuration.Stub(c => c.Dispose()); + return configuration; + } + + private class SimpleBackgroundLayerStatus : BackgroundLayerStatus + { + public bool ConfigurationCleared { get; private set; } + + public override void ClearConfiguration(bool expectRecreationOfSameBackgroundLayer = false) + { + ConfigurationCleared = true; + } + + protected override void OnLayerInitializationSuccessful(BruTileLayer backgroundLayer, ImageBasedMapData dataSource) + { + throw new NotImplementedException(); + } + + protected override bool OnHasSameConfiguration(ImageBasedMapData mapData) + { + throw new NotImplementedException(); + } + } + } +} \ No newline at end of file Index: Core/Components/test/Core.Components.DotSpatial.Forms.Test/Core.Components.DotSpatial.Forms.Test.csproj =================================================================== diff -u -r9c660fc9a1125762276ea0fd66a8befaa33bac28 -r5f0893eb7fb4e2e25ae762ef20aa05eac0e40acf --- Core/Components/test/Core.Components.DotSpatial.Forms.Test/Core.Components.DotSpatial.Forms.Test.csproj (.../Core.Components.DotSpatial.Forms.Test.csproj) (revision 9c660fc9a1125762276ea0fd66a8befaa33bac28) +++ Core/Components/test/Core.Components.DotSpatial.Forms.Test/Core.Components.DotSpatial.Forms.Test.csproj (.../Core.Components.DotSpatial.Forms.Test.csproj) (revision 5f0893eb7fb4e2e25ae762ef20aa05eac0e40acf) @@ -78,6 +78,7 @@ Properties\GlobalAssembly.cs + @@ -140,6 +141,10 @@ {1081336C-D919-4249-AB33-9AF15F4D19EC} Core.Components.BruTile.TestUtil + + {F0FB401A-3494-4237-9E6D-02CDF77912A8} + Core.Components.Gis.TestUtils +