Index: DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/IO/DamProjectVersionXmlHandler.cs
===================================================================
diff -u
--- DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/IO/DamProjectVersionXmlHandler.cs (revision 0)
+++ DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/IO/DamProjectVersionXmlHandler.cs (revision 2234)
@@ -0,0 +1,134 @@
+// Copyright (C) Stichting Deltares 2019. All rights reserved.
+//
+// This file is part of the application DAM - Clients Library.
+//
+// DAM - UI 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 Deltares.Standard.IO.Xml;
+
+namespace Deltares.Dam.Data.IO
+{
+ ///
+ /// This class is added to be able to retrieve the proper version from the damx xml file via the xmlHandler interface.
+ /// So the only useful methods are GetDamProjectVersion and SetVersion (interface).
+ ///
+ ///
+ public class DamProjectVersionXmlHandler: IXmlHandler
+ {
+ private string damProjectVersion;
+
+ ///
+ /// Gets the dam project version.
+ ///
+ ///
+ public string GetDamProjectVersion()
+ {
+ return damProjectVersion;
+ }
+
+ ///
+ /// Sets the version of the file to be deserialized
+ ///
+ /// Version of the xml file
+ public void SetVersion(string version)
+ {
+ damProjectVersion = version;
+ }
+
+ ///
+ /// This method returns true if the can be handled by this XmlHandler
+ ///
+ /// Type of the objects
+ ///
+ /// True if the type can be handled, false otherwise
+ ///
+ public bool CanHandle(Type type)
+ {
+ return false;
+ }
+
+ ///
+ /// This method returns true if the and property can be handled by this XmlHandler
+ ///
+ /// Type of the objects
+ /// Indicates whether the property can be handled
+ ///
+ /// True if the type can be handled, false otherwise
+ ///
+ public bool CanHandle(Type type, string property)
+ {
+ return false;
+ }
+
+ ///
+ /// Indicates the type of the property which should be created
+ ///
+ /// The type in which the property is or was defined
+ /// The name of the property
+ ///
+ /// The type of the property
+ ///
+ ///
+ ///
+ /// If null is returned, the property type is left over to reflection
+ ///
+ public Type GetFormerPropertyType(Type type, string property)
+ {
+ throw new NotImplementedException();
+ }
+
+ ///
+ /// When the handler can handle the property, this method can be called to actually perform
+ /// the handling of the value for a specific target.
+ ///
+ /// The object for which the value is handled
+ /// The property which should be handled
+ /// The value which is handled
+ /// The deserialized objects list
+ ///
+ public void Handle(object target, string property, object value, object[] objects)
+ {
+ throw new NotImplementedException();
+ }
+
+ ///
+ /// When the handler can handle the property, this method can be called to actually perform
+ /// the handling of the value of the specific target. The value, in this case, can be
+ /// altered before it is set to the target. It is the implementing class' responsibility
+ /// to assign the value to the correct property of the target.
+ ///
+ /// The target object to assign the value for.
+ /// The value to assign to the target
+ ///
+ public void HandleObject(object target, object value)
+ {
+ throw new NotImplementedException();
+ }
+
+ ///
+ /// Allows the xml handler to post process each created object, which it can handle
+ ///
+ /// The object to be post processed
+ ///
+ public void Upgrade(object[] target)
+ {
+ throw new NotImplementedException();
+ }
+ }
+}
Index: DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/Deltares.Dam.Data.csproj
===================================================================
diff -u -r2202 -r2234
--- DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/Deltares.Dam.Data.csproj (.../Deltares.Dam.Data.csproj) (revision 2202)
+++ DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/Deltares.Dam.Data.csproj (.../Deltares.Dam.Data.csproj) (revision 2234)
@@ -197,6 +197,7 @@
+
Index: DamClients/DamUI/trunk/src/Dam/Forms/DamPlugin.cs
===================================================================
diff -u -r2194 -r2234
--- DamClients/DamUI/trunk/src/Dam/Forms/DamPlugin.cs (.../DamPlugin.cs) (revision 2194)
+++ DamClients/DamUI/trunk/src/Dam/Forms/DamPlugin.cs (.../DamPlugin.cs) (revision 2234)
@@ -82,6 +82,7 @@
private CsvExportData lastDesignResult = null;
private LocationResult lastLocationResult = null;
private LocationJob currentLocationJob = null;
+ private DamProjectVersionXmlHandler damProjectVersionXmlHandler;
private readonly GridViewControl locationsControl = new GridViewControl
{
@@ -189,6 +190,8 @@
LocalizationManager.CultureChanged += (sender, args) => UpdateNavigatorTopItem();
// for backward compatibility
+ damProjectVersionXmlHandler = new DamProjectVersionXmlHandler();
+ XmlHandler.RegisterObjectHandler(damProjectVersionXmlHandler);
XmlHandler.RegisterObjectHandler(new FailureMechanismeParamatersMStabXmlHandler());
// This is to force the version type (Alpha, Pre-Alpha etc.) to be updated
@@ -378,6 +381,18 @@
///
public bool IsChartVisible { get; set; }
+ private string GetMainVersion(string fullVersion)
+ {
+ if (fullVersion.Contains("."))
+ {
+ string[] currentVer = fullVersion.Split(".".ToCharArray());
+ var main = currentVer[0];
+ var sec = currentVer[1];
+ return main + "." + sec;
+ }
+ return fullVersion;
+ }
+
public void Assign(object source)
{
var projectData = source as DamProjectData;
@@ -389,6 +404,17 @@
projectData.ClearResults();
}
+ var damProjectVersion = damProjectVersionXmlHandler.GetDamProjectVersion();
+ damProjectVersion = GetMainVersion(damProjectVersion);
+ if (damProjectVersion != null)
+ {
+ var currentProgramVersion = GetMainVersion(About.Version);
+ if (!currentProgramVersion.Equals(damProjectVersion))
+ {
+ projectData.ClearResults();
+ }
+ }
+
initial = false;
// var args = Environment.GetCommandLineArgs();
Index: DamClients/DamUI/trunk/src/Dam/Tests/Deltares.Dam.Tests.csproj
===================================================================
diff -u -r2232 -r2234
--- DamClients/DamUI/trunk/src/Dam/Tests/Deltares.Dam.Tests.csproj (.../Deltares.Dam.Tests.csproj) (revision 2232)
+++ DamClients/DamUI/trunk/src/Dam/Tests/Deltares.Dam.Tests.csproj (.../Deltares.Dam.Tests.csproj) (revision 2234)
@@ -136,6 +136,7 @@
+
Index: DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/DamProject.cs
===================================================================
diff -u -r2168 -r2234
--- DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/DamProject.cs (.../DamProject.cs) (revision 2168)
+++ DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/DamProject.cs (.../DamProject.cs) (revision 2234)
@@ -238,6 +238,7 @@
ClearProject();
damProjectData.DamProjectType = DamProjectType.AssessOld;
}
+ //var LVersion = xmlSerializer.xmlDocument.Version;
// Project still needs a reference to soilmaterials database; to be resolved later
UpdateSoilDatabaseReferences(damProjectFolder);
UpdateSoilPropertiesToSoilDatabase();
Index: DamClients/DamUI/trunk/src/Dam/Tests/IO/DamProjectVersionXmlHandlerTests.cs
===================================================================
diff -u
--- DamClients/DamUI/trunk/src/Dam/Tests/IO/DamProjectVersionXmlHandlerTests.cs (revision 0)
+++ DamClients/DamUI/trunk/src/Dam/Tests/IO/DamProjectVersionXmlHandlerTests.cs (revision 2234)
@@ -0,0 +1,127 @@
+// Copyright (C) Stichting Deltares 2018. All rights reserved.
+//
+// This file is part of the application DAM - UI.
+//
+// DAM - UI 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 Deltares.Dam.Data;
+using Deltares.Dam.Data.IO;
+using Deltares.DamEngine.Data.Standard;
+using NUnit.Framework;
+
+namespace Deltares.Dam.Tests.IO
+{
+ public class DamProjectVersionXmlHandlerTests
+ {
+ private DamProjectVersionXmlHandler target;
+
+ [SetUp]
+ public void SetUp()
+ {
+ target = new DamProjectVersionXmlHandler();
+ }
+
+ [Test]
+ public void CanHandle_ForTypeAndProperty_ReturnsFalseWithParameters()
+ {
+ // setup
+ var propertyName = StaticReflection.GetMemberName(x => x.DamProjectData);
+ // call
+ var result = target.CanHandle(typeof(DamProject), propertyName);
+
+ // assert
+ Assert.IsFalse(result);
+ }
+
+ [Test]
+ public void CanHandle_ForTypeAndProperty_ReturnsFalseWithNull()
+ {
+ // call
+ var result = target.CanHandle(null, null);
+ // assert
+ Assert.IsFalse(result);
+ }
+
+ [Test]
+ public void CanHandle_ForType_ReturnsFalseWithParameters()
+ {
+ // call
+ var result = target.CanHandle(typeof(DamProject));
+
+ // assert
+ Assert.IsFalse(result);
+ }
+
+ [Test]
+ public void CanHandle_ForType_ReturnsFalseWithNull()
+ {
+ // call
+ var result = target.CanHandle(null);
+
+ // assert
+ Assert.IsFalse(result);
+ }
+
+ [Test]
+ public void Handle_ThrowsNotImplementedException()
+ {
+ // setup
+ // call
+ var testDelegate = new TestDelegate(() => target.Handle(null, null, null, null));
+
+ // assert
+ Assert.Throws(testDelegate);
+ }
+
+ [Test]
+ public void HandleObject_ThrowsNotImplementedException()
+ {
+ // setup
+ // call
+ var testDelegate = new TestDelegate(() => target.HandleObject(null, null));
+
+ // assert
+ Assert.Throws(testDelegate);
+ }
+
+ [Test]
+ public void Upgrade_ThrowsNotImplementedException()
+ {
+ // setup
+ // call
+ var testDelegate = new TestDelegate(() => target.Upgrade(null));
+
+ // assert
+ Assert.Throws(testDelegate);
+ }
+
+ [Test]
+ public void SetVersion_GetDamProjectVersionDoesWork()
+ {
+ // setup
+ var version = "versie 1";
+ // call
+ //var testDelegate = new TestDelegate(() => );
+ target.SetVersion(version);
+ var resultVersion = target.GetDamProjectVersion();
+ // assert
+ Assert.AreEqual(version, resultVersion);
+ }
+ }
+}