Index: Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsGuiPlugin.cs
===================================================================
diff -u -r1e6d07e8cbd1c29a16b5addddb7205e717543729 -r8476d48f3aa0d36c866433c29be238aa52abcfe4
--- Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsGuiPlugin.cs (.../RingtoetsGuiPlugin.cs) (revision 1e6d07e8cbd1c29a16b5addddb7205e717543729)
+++ Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsGuiPlugin.cs (.../RingtoetsGuiPlugin.cs) (revision 8476d48f3aa0d36c866433c29be238aa52abcfe4)
@@ -615,7 +615,7 @@
{
try
{
- ValidateAndImportSelectedFile(dialog.FileName, assessmentSection);
+ ImportHydraulicBoundaryDatabase(dialog.FileName, assessmentSection);
}
catch (CriticalFileReadException exception)
{
@@ -626,37 +626,34 @@
}
///
- /// Attempts to update the based on the .
+ /// Attempts to update the with a
+ /// imported from the .
///
- /// The file to use to import a from.
- /// The to which the imported will be assigned.
- /// A new which is connected to the .
- /// Thrown when the importer could not be created for the selected file.
- private static void ValidateAndImportSelectedFile(string selectedFile, IAssessmentSection assessmentSection)
+ /// The file to use to import a from.
+ /// The to which the imported
+ /// will be assigned.
+ /// Thrown when importing from the
+ /// failed.
+ private static void ImportHydraulicBoundaryDatabase(string databaseFile, IAssessmentSection assessmentSection)
{
- using (var hydraulicBoundaryLocationsImporter = new HydraulicBoundaryDatabaseImporter())
- {
- if (assessmentSection.HydraulicBoundaryDatabase != null)
- {
- var newVersion = hydraulicBoundaryLocationsImporter.GetHydraulicBoundaryDatabaseVersion(selectedFile);
+ var hydraulicBoundaryDatabase = assessmentSection.HydraulicBoundaryDatabase;
- var currentVersion = assessmentSection.HydraulicBoundaryDatabase.Version;
- var currentFilePath = assessmentSection.HydraulicBoundaryDatabase.FilePath;
+ var isHydraulicBoundaryDatabaseSet = hydraulicBoundaryDatabase != null;
+ var isClearConfirmationRequired = isHydraulicBoundaryDatabaseSet && !HydraulicDatabaseHelper.HaveEqualVersion(hydraulicBoundaryDatabase, databaseFile);
+ var isClearConfirmationGiven = isClearConfirmationRequired && IsClearCalculationConfirmationGiven();
- if (currentVersion != newVersion && HasClearCalculationConfirmation())
+ if (!isHydraulicBoundaryDatabaseSet || !isClearConfirmationRequired || isClearConfirmationGiven)
+ {
+ var hydraulicBoundaryLocationsImporter = new HydraulicBoundaryDatabaseImporter();
+ if (hydraulicBoundaryLocationsImporter.Import(assessmentSection, databaseFile))
+ {
+ if (isClearConfirmationRequired)
{
ClearCalculations(assessmentSection);
- ImportSelectedFile(assessmentSection, selectedFile, hydraulicBoundaryLocationsImporter);
}
- else if (currentFilePath != selectedFile)
- {
- SetBoundaryDatabaseData(assessmentSection, selectedFile);
- }
+ assessmentSection.NotifyObservers();
+ log.InfoFormat(RingtoetsFormsResources.RingtoetsGuiPlugin_SetBoundaryDatabaseFilePath_Database_on_path_0_linked, assessmentSection.HydraulicBoundaryDatabase.FilePath);
}
- else
- {
- ImportSelectedFile(assessmentSection, selectedFile, hydraulicBoundaryLocationsImporter);
- }
}
}
@@ -684,7 +681,7 @@
}
}
- private static bool HasClearCalculationConfirmation()
+ private static bool IsClearCalculationConfirmationGiven()
{
var confirmation = MessageBox.Show(
RingtoetsFormsResources.Delete_Calculations_Text,
@@ -708,25 +705,6 @@
log.Info(RingtoetsFormsResources.Calculations_Deleted);
}
- private static void ImportSelectedFile(IAssessmentSection assessmentSection, string hydraulicDatabasePath, HydraulicBoundaryDatabaseImporter hydraulicBoundaryLocationsImporter)
- {
- if (hydraulicBoundaryLocationsImporter.Import(assessmentSection, hydraulicDatabasePath))
- {
- SetBoundaryDatabaseData(assessmentSection);
- }
- }
-
- private static void SetBoundaryDatabaseData(IAssessmentSection assessmentSection, string selectedFile = null)
- {
- if (!String.IsNullOrEmpty(selectedFile))
- {
- assessmentSection.HydraulicBoundaryDatabase.FilePath = selectedFile;
- }
-
- assessmentSection.NotifyObservers();
- log.InfoFormat(RingtoetsFormsResources.RingtoetsGuiPlugin_SetBoundaryDatabaseFilePath_Database_on_path_0_linked, assessmentSection.HydraulicBoundaryDatabase.FilePath);
- }
-
#endregion
}
}
\ No newline at end of file