Exemplo n.º 1
0
        private static void WriteWmtsConnectionInfoToXml(XmlWriter writer, WmtsConnectionInfo wmtsConnectionInfo)
        {
            writer.WriteStartElement(WmtsConnectionInfoXmlDefinitions.WmtsConnectionElement);

            writer.WriteElementString(WmtsConnectionInfoXmlDefinitions.WmtsConnectionNameElement, wmtsConnectionInfo.Name);
            writer.WriteElementString(WmtsConnectionInfoXmlDefinitions.WmtsConnectionUrlElement, wmtsConnectionInfo.Url);

            writer.WriteEndElement();
        }
Exemplo n.º 2
0
        public void WmtsConnectionInfoConstructor_WithoutDialogParent_ThrowsArgumentNullException()
        {
            // Setup
            var info = new WmtsConnectionInfo("name", "url");

            // Call
            TestDelegate test = () => new WmtsConnectionDialog(null, info);

            // Assert
            string paramName = Assert.Throws <ArgumentNullException>(test).ParamName;

            Assert.AreEqual("dialogParent", paramName);
        }
Exemplo n.º 3
0
        public void Constructor_ValidParameters_ExpectedProperties()
        {
            // Setup
            const string name = "name";
            const string url  = "url";

            // Call
            var connectionInfo = new WmtsConnectionInfo(name, url);

            // Assert
            Assert.AreEqual(name, connectionInfo.Name);
            Assert.AreEqual(url, connectionInfo.Url);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Creates a new instance of <see cref="WmtsConnectionDialog"/> in edit mode.
        /// </summary>
        /// <param name="dialogParent">The parent of the dialog.</param>
        /// <param name="wmtsConnectionInfo">The information to set in the input boxes.</param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="dialogParent"/> is <c>null</c>.</exception>
        public WmtsConnectionDialog(IWin32Window dialogParent, WmtsConnectionInfo wmtsConnectionInfo = null)
            : base(dialogParent, Resources.MapsIcon, 400, 150)
        {
            InitializeComponent();

            if (wmtsConnectionInfo != null)
            {
                SetWmtsConnectionInfo(wmtsConnectionInfo);
            }

            UpdateActionButton();
            InitializeEventHandlers();
            InitializeErrorProvider();
        }
Exemplo n.º 5
0
        public void ReadWmtsConnectionInfos_FileMissingOneNameElement_SkipdAndReadsRestOfFile()
        {
            // Setup
            string filePath = Path.Combine(testPath, "twoWmtsConnectionInfosOneWithoutNameElement.txt");
            var    reader   = new WmtsConnectionInfoReader();

            // Call
            WmtsConnectionInfo[] readConnectionInfos = reader.ReadWmtsConnectionInfos(filePath).ToArray();

            // Assert
            Assert.AreEqual(1, readConnectionInfos.Length);
            var expectedWmtsConnectionInfo = new WmtsConnectionInfo(@"second name", @"https://domain.com");

            AssertAreEqual(expectedWmtsConnectionInfo, readConnectionInfos[0]);
        }
Exemplo n.º 6
0
        public void ReadDefaultWmtsConnectionInfos_Always_ReturnsExpectedWmtsConnectionInfos()
        {
            // Setup
            var reader = new WmtsConnectionInfoReader();

            // Call
            ReadOnlyCollection <WmtsConnectionInfo> readConnectionInfos = reader.ReadDefaultWmtsConnectionInfos();

            // Assert
            Assert.AreEqual(2, readConnectionInfos.Count);
            var firstExpected  = new WmtsConnectionInfo(@"ESRI luchtfoto", @"http://services.arcgisonline.com/arcgis/rest/services/World_Imagery/MapServer/WMTS?");
            var secondExpected = new WmtsConnectionInfo(@"PDOK", @"https://geodata.nationaalgeoregister.nl/tiles/service/wmts/ahn2?request=GetCapabilities");

            AssertAreEqual(firstExpected, readConnectionInfos[0]);
            AssertAreEqual(secondExpected, readConnectionInfos[1]);
        }
Exemplo n.º 7
0
        private WmtsConnectionInfo PreSelectComboBox()
        {
            WmtsConnectionInfo suggestedInfo = TryCreateWmtsConnectionInfo(activeWmtsMapData?.Name,
                                                                           activeWmtsMapData?.SourceCapabilitiesUrl);

            if (suggestedInfo == null)
            {
                return(null);
            }

            if (!wmtsConnectionInfos.Contains(suggestedInfo))
            {
                wmtsConnectionInfos.Add(suggestedInfo);
            }

            return(suggestedInfo);
        }
Exemplo n.º 8
0
        public void ReadWmtsConnectionInfos_FileWithTwoWmtsConnectionInfosReversedOrder_ReturnsExpectedWmtsConnectionInfos()
        {
            // Setup
            string filePath = Path.Combine(testPath, "twoValidWmtsConnectionInfosReversedOrder.txt");
            var    reader   = new WmtsConnectionInfoReader();

            // Call
            WmtsConnectionInfo[] readConnectionInfos = reader.ReadWmtsConnectionInfos(filePath).ToArray();

            // Assert
            Assert.AreEqual(2, readConnectionInfos.Length);
            var firstExpected  = new WmtsConnectionInfo(@"Actueel Hoogtebestand Nederland (AHN1)", @"https://geodata.nationaalgeoregister.nl/tiles/service/wmts/ahn1?request=GetCapabilities");
            var secondExpected = new WmtsConnectionInfo(@"Zeegraskartering", @"https://geodata.nationaalgeoregister.nl/zeegraskartering/wfs?request=GetCapabilities");

            AssertAreEqual(firstExpected, readConnectionInfos[0]);
            AssertAreEqual(secondExpected, readConnectionInfos[1]);
        }
Exemplo n.º 9
0
        private void UpdateWmtsConnectionInfos(WmtsConnectionDialog dialog, WmtsConnectionInfo selectedWmtsConnectionInfo = null)
        {
            WmtsConnectionInfo createdWmtsConnectionInfo = TryCreateWmtsConnectionInfo(dialog.WmtsConnectionName,
                                                                                       dialog.WmtsConnectionUrl);

            if (createdWmtsConnectionInfo == null)
            {
                return;
            }

            if (selectedWmtsConnectionInfo != null)
            {
                wmtsConnectionInfos.Remove(selectedWmtsConnectionInfo);
            }

            wmtsConnectionInfos.Add(createdWmtsConnectionInfo);
            SaveWmtsConnectionInfos();
            UpdateComboBoxDataSource(createdWmtsConnectionInfo);
        }
Exemplo n.º 10
0
        private void ConnectToUrl(WmtsConnectionInfo selectedWmtsConnectionInfo)
        {
            if (selectedWmtsConnectionInfo == null)
            {
                return;
            }

            try
            {
                IEnumerable <WmtsCapability> wmtsCapabilities = wmtsCapabilityFactory.GetWmtsCapabilities(selectedWmtsConnectionInfo.Url).ToArray();
                UpdateDataGridViewDataSource(wmtsCapabilities);
            }
            catch (CannotFindTileSourceException)
            {
                Form parentForm = FindForm();
                MessageBox.Show(parentForm, string.Format(Resources.WmtsLocationControl_Unable_to_connect_to_0, selectedWmtsConnectionInfo.Name),
                                BaseResources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 11
0
        public void WmtsConnectionInfoConstructor_WithDialogParent_ExpectedProperties()
        {
            // Setup
            var mocks        = new MockRepository();
            var dialogParent = mocks.StrictMock <IWin32Window>();

            mocks.ReplayAll();
            const string connectionName = @"name";
            const string connectionUrl  = @"url";
            var          info           = new WmtsConnectionInfo(connectionName, connectionUrl);

            // Call
            using (var dialog = new WmtsConnectionDialog(dialogParent, info))
            {
                // Assert
                Assert.IsInstanceOf <DialogBase>(dialog);
                Assert.IsNull(dialog.WmtsConnectionName);
                Assert.IsNull(dialog.WmtsConnectionUrl);

                Assert.AreEqual("WMTS locatie aanpassen", dialog.Text);

                var nameLabel = new LabelTester("nameLabel", dialog);
                Assert.AreEqual("Omschrijving:", nameLabel.Text);

                var urlLabel = new LabelTester("urlLabel", dialog);
                Assert.AreEqual("URL:", urlLabel.Text);

                var actionButton = (Button) new ButtonTester("actionButton", dialog).TheObject;
                Assert.AreEqual("Opslaan", actionButton.Text);
                Assert.IsTrue(actionButton.Enabled);

                var cancelButton = new ButtonTester("cancelButton", dialog);
                Assert.AreEqual("Annuleren", cancelButton.Text);

                var nameTextBox = new TextBoxTester("nameTextBox", dialog);
                Assert.AreEqual(connectionName, nameTextBox.Text);

                var urlTextBox = new TextBoxTester("urlTextBox", dialog);
                Assert.AreEqual(connectionUrl, urlTextBox.Text);
            }

            mocks.VerifyAll();
        }
Exemplo n.º 12
0
        public void ReadWmtsConnectionInfos_FileEmptyUrlElement_WarnsAndReadsRestOfFile()
        {
            // Setup
            string filePath = Path.Combine(testPath, "twoWmtsConnectionInfosOneEmptyUrl.txt");
            var    reader   = new WmtsConnectionInfoReader();

            WmtsConnectionInfo[] readConnectionInfos = null;

            // Call
            Action action = () => readConnectionInfos = reader.ReadWmtsConnectionInfos(filePath).ToArray();

            // Assert
            string expectedMessage = $"Fout bij het lezen van bestand '{filePath}': het is niet mogelijk om WMTS connectie 'First name' aan te maken met URL ''.";

            TestHelper.AssertLogMessageWithLevelIsGenerated(action, Tuple.Create(expectedMessage, LogLevelConstant.Warn));

            Assert.IsNotNull(readConnectionInfos);
            Assert.AreEqual(1, readConnectionInfos.Length);
            var expectedWmtsConnectionInfo = new WmtsConnectionInfo(@"second name", @"https://domain.com");

            AssertAreEqual(expectedWmtsConnectionInfo, readConnectionInfos[0]);
        }
Exemplo n.º 13
0
        /// <summary>
        /// Creates a new instance of <see cref="WmtsLocationControl"/>.
        /// </summary>
        /// <param name="activeWmtsMapData">The active <see cref="WmtsMapData"/> or <c>null</c> if none active.</param>
        /// <param name="wmtsCapabilityFactory">The <see cref="IWmtsCapabilityFactory"/> to use.</param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="wmtsCapabilityFactory"/> is <c>null</c>.</exception>
        public WmtsLocationControl(WmtsMapData activeWmtsMapData, IWmtsCapabilityFactory wmtsCapabilityFactory)
            : base(Resources.WmtsLocationControl_DisplayName)
        {
            if (wmtsCapabilityFactory == null)
            {
                throw new ArgumentNullException(nameof(wmtsCapabilityFactory));
            }

            this.activeWmtsMapData     = activeWmtsMapData;
            this.wmtsCapabilityFactory = wmtsCapabilityFactory;

            InitializeComponent();
            InitializeWmtsConnectionInfos();
            InitializeDataGridView();
            InitializeComboBox();
            InitializeEventHandlers();

            WmtsConnectionInfo selectedWmtsConnectionInfo = PreSelectComboBox();

            UpdateComboBoxDataSource(selectedWmtsConnectionInfo);

            UpdateButtons();
        }
Exemplo n.º 14
0
 private void SetWmtsConnectionInfo(WmtsConnectionInfo wmtsConnectionInfo)
 {
     nameTextBox.Text = wmtsConnectionInfo.Name;
     urlTextBox.Text  = wmtsConnectionInfo.Url;
     Text             = Resources.WmtsConnectionDialog_Text_Edit;
 }
Exemplo n.º 15
0
 private static void AssertAreEqual(WmtsConnectionInfo expected, WmtsConnectionInfo actual)
 {
     Assert.AreEqual(expected.Name, actual.Name);
     Assert.AreEqual(expected.Url, actual.Url);
 }
Exemplo n.º 16
0
 private static void WriteToFile(string filePath, WmtsConnectionInfo wmtsConnectionInfo)
 {
     File.WriteAllText(filePath, @"<?xml version=""1.0"" encoding=""utf-8""?><WmtsConnections><WmtsConnection>" +
                                 $@"<Name>{wmtsConnectionInfo.Name}</Name><URL>{wmtsConnectionInfo.Url}</URL>" +
                                 @"</WmtsConnection></WmtsConnections>");
 }