Index: Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.IO/Exporters/MacroStabilityInwardsCalculationGroupExporter.cs =================================================================== diff -u -re6972847cef019302b4fe9f7dd45d09175ef6cea -r6f3f5cd43feafa96fdedaeb2ccb01240c4261de1 --- Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.IO/Exporters/MacroStabilityInwardsCalculationGroupExporter.cs (.../MacroStabilityInwardsCalculationGroupExporter.cs) (revision e6972847cef019302b4fe9f7dd45d09175ef6cea) +++ Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.IO/Exporters/MacroStabilityInwardsCalculationGroupExporter.cs (.../MacroStabilityInwardsCalculationGroupExporter.cs) (revision 6f3f5cd43feafa96fdedaeb2ccb01240c4261de1) @@ -105,8 +105,8 @@ CreateDirectory(currentFolderPath); var continueExport = true; - var exportedGroups = new List(); - var exportedCalculations = new List(); + var exportedGroups = new Dictionary(); + var exportedCalculations = new Dictionary(); foreach (ICalculationBase calculationItem in groupToExport.Children) { @@ -148,25 +148,27 @@ } } - private bool ExportCalculationGroup(CalculationGroup nestedGroup, string currentFolderPath, ICollection exportedGroups) + private bool ExportCalculationGroup(CalculationGroup nestedGroup, string currentFolderPath, IDictionary exportedGroups) { - string uniqueGroupName = NamingHelper.GetUniqueName(exportedGroups, nestedGroup.Name, group => group.Name); + string uniqueGroupName = NamingHelper.GetUniqueName(exportedGroups, nestedGroup.Name, group => group.Value); bool exportSucceeded = ExportCalculationItemsRecursively(nestedGroup, Path.Combine(currentFolderPath, uniqueGroupName)); if (!exportSucceeded) { return false; } - exportedGroups.Add(nestedGroup); + exportedGroups.Add(nestedGroup, uniqueGroupName); return true; } - private bool ExportCalculation(MacroStabilityInwardsCalculation calculation, string currentFolderPath, ICollection exportedCalculations) + private bool ExportCalculation(MacroStabilityInwardsCalculation calculation, string currentFolderPath, IDictionary exportedCalculations) { log.InfoFormat(CoreCommonGuiResources.GuiExportHandler_ExportItemUsingDialog_Start_exporting_DataType_0_, calculation.Name); - string filePath = GetCalculationFilePath(calculation, currentFolderPath, exportedCalculations); + string uniqueName = NamingHelper.GetUniqueName(exportedCalculations, ((ICalculationBase)calculation).Name, c => c.Value); + string filePath = GetCalculationFilePath(currentFolderPath, uniqueName); + var exporter = new MacroStabilityInwardsCalculationExporter(calculation, persistenceFactory, filePath, () => getNormativeAssessmentLevelFunc(calculation)); bool exportSucceeded = exporter.Export(); @@ -177,14 +179,13 @@ } log.InfoFormat(Resources.MacroStabilityInwardsCalculationGroupExporter_Export_Data_from_0_exported_to_file_1, calculation.Name, filePath); - exportedCalculations.Add(calculation); + exportedCalculations.Add(calculation, uniqueName); return true; } - private string GetCalculationFilePath(ICalculationBase calculation, string currentFolderPath, IEnumerable exportedCalculations) + private string GetCalculationFilePath(string currentFolderPath, string fileName) { - string uniqueName = NamingHelper.GetUniqueName(exportedCalculations, calculation.Name, c => c.Name); - string fileNameWithExtension = $"{uniqueName}.{fileExtension}"; + string fileNameWithExtension = $"{fileName}.{fileExtension}"; return Path.Combine(currentFolderPath, fileNameWithExtension); } } Index: Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.IO.Test/Exporters/MacroStabilityInwardsCalculationGroupExporterTest.cs =================================================================== diff -u -re6972847cef019302b4fe9f7dd45d09175ef6cea -r6f3f5cd43feafa96fdedaeb2ccb01240c4261de1 --- Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.IO.Test/Exporters/MacroStabilityInwardsCalculationGroupExporterTest.cs (.../MacroStabilityInwardsCalculationGroupExporterTest.cs) (revision e6972847cef019302b4fe9f7dd45d09175ef6cea) +++ Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.IO.Test/Exporters/MacroStabilityInwardsCalculationGroupExporterTest.cs (.../MacroStabilityInwardsCalculationGroupExporterTest.cs) (revision 6f3f5cd43feafa96fdedaeb2ccb01240c4261de1) @@ -364,11 +364,13 @@ MacroStabilityInwardsCalculationScenario calculation1 = CreateCalculation("calculation1"); MacroStabilityInwardsCalculationScenario calculation2 = CreateCalculation("calculation2"); MacroStabilityInwardsCalculationScenario calculation3 = CreateCalculation("calculation1"); + MacroStabilityInwardsCalculationScenario calculation4 = CreateCalculation("calculation1"); var calculationGroup = new CalculationGroup(); calculationGroup.Children.Add(calculation1); calculationGroup.Children.Add(calculation2); calculationGroup.Children.Add(calculation3); + calculationGroup.Children.Add(calculation4); var exporter = new MacroStabilityInwardsCalculationGroupExporter(calculationGroup, new PersistenceFactory(), folderPath, fileExtension, c => AssessmentSectionTestHelper.GetTestAssessmentLevel()); @@ -384,6 +386,7 @@ AssertCalculationExists(Path.Combine(folderPath, $"{calculation1.Name}.{fileExtension}")); AssertCalculationExists(Path.Combine(folderPath, $"{calculation2.Name}.{fileExtension}")); AssertCalculationExists(Path.Combine(folderPath, $"{calculation3.Name} (1).{fileExtension}")); + AssertCalculationExists(Path.Combine(folderPath, $"{calculation4.Name} (2).{fileExtension}")); } } finally @@ -402,6 +405,8 @@ MacroStabilityInwardsCalculationScenario calculation1 = CreateCalculation("calculation1"); MacroStabilityInwardsCalculationScenario calculation2 = CreateCalculation("calculation2"); MacroStabilityInwardsCalculationScenario calculation3 = CreateCalculation("calculation1"); + MacroStabilityInwardsCalculationScenario calculation4 = CreateCalculation("calculation1"); + MacroStabilityInwardsCalculationScenario calculation5 = CreateCalculation("calculation1"); var rootGroup = new CalculationGroup { @@ -415,11 +420,18 @@ { Name = "group1" }; + var nestedGroup3 = new CalculationGroup + { + Name = "group1" + }; nestedGroup1.Children.Add(calculation1); nestedGroup1.Children.Add(calculation2); nestedGroup2.Children.Add(calculation3); + nestedGroup2.Children.Add(calculation4); + nestedGroup3.Children.Add(calculation5); rootGroup.Children.Add(nestedGroup1); rootGroup.Children.Add(nestedGroup2); + rootGroup.Children.Add(nestedGroup3); var exporter = new MacroStabilityInwardsCalculationGroupExporter(rootGroup, new PersistenceFactory(), folderPath, fileExtension, c => AssessmentSectionTestHelper.GetTestAssessmentLevel()); @@ -435,6 +447,8 @@ AssertCalculationExists(Path.Combine(folderPath, nestedGroup1.Name, $"{calculation1.Name}.{fileExtension}")); AssertCalculationExists(Path.Combine(folderPath, nestedGroup1.Name, $"{calculation2.Name}.{fileExtension}")); AssertCalculationExists(Path.Combine(folderPath, $"{nestedGroup2.Name} (1)", $"{calculation3.Name}.{fileExtension}")); + AssertCalculationExists(Path.Combine(folderPath, $"{nestedGroup2.Name} (1)", $"{calculation4.Name} (1).{fileExtension}")); + AssertCalculationExists(Path.Combine(folderPath, $"{nestedGroup3.Name} (2)", $"{calculation5.Name}.{fileExtension}")); } } finally