using System; using System.Collections.Generic; using System.Linq; using Ringtoets.AssemblyTool.Data; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.Exceptions; using Ringtoets.Integration.Data.StandAlone; using Ringtoets.Integration.Data.StandAlone.AssemblyFactories; using Ringtoets.Integration.Data.StandAlone.SectionResults; using Ringtoets.Integration.IO.Assembly; namespace Ringtoets.Integration.IO.Factories { /// /// Factory to create instances of /// with assembly results for macro stability outwards. /// public static class ExportableMacroStabilityOutwardsFailureMechanismFactory { private const ExportableFailureMechanismGroup failureMechanismGroup = ExportableFailureMechanismGroup.Group4; private const ExportableFailureMechanismType failureMechanismCode = ExportableFailureMechanismType.STBU; private const ExportableAssemblyMethod failureMechanismAssemblyMethod = ExportableAssemblyMethod.WBI1A1; /// /// Creates a /// with assembly results based on the input parameters. /// /// The to create a /// for. /// The assessment section this failure mechanism belongs to. /// A with assembly results. /// Thrown when any parameter is null. /// Thrown when assembly results cannot be created. public static ExportableFailureMechanism CreateExportableMacroStabilityOutwardsFailureMechanism( MacroStabilityOutwardsFailureMechanism failureMechanism, IAssessmentSection assessmentSection) { if (failureMechanism == null) { throw new ArgumentNullException(nameof(failureMechanism)); } if (assessmentSection == null) { throw new ArgumentNullException(nameof(assessmentSection)); } if (!failureMechanism.IsRelevant) { return ExportableFailureMechanismFactory.CreateDefaultExportableFailureMechanismWithoutProbability(failureMechanismCode, failureMechanismGroup, failureMechanismAssemblyMethod); } FailureMechanismAssemblyCategoryGroup failureMechanismAssembly = MacroStabilityOutwardsFailureMechanismAssemblyFactory.AssembleFailureMechanism(failureMechanism, assessmentSection); Dictionary failureMechanismSectionsLookup = failureMechanism.SectionResults .ToDictionary(sectionResult => sectionResult, sectionResult => ExportableFailureMechanismSectionFactory.CreateExportableFailureMechanismSection(sectionResult.Section)); return new ExportableFailureMechanism( new ExportableFailureMechanismAssemblyResult(failureMechanismAssemblyMethod, failureMechanismAssembly), failureMechanismSectionsLookup.Values, CreateExportableFailureMechanismSectionResults(failureMechanismSectionsLookup, failureMechanism, assessmentSection), failureMechanismCode, failureMechanismGroup); } /// /// Creates a collection of /// with assembly results based on the sections in . /// /// The mapping between the /// and . /// The the sections belong to. /// The assessment section the sections belong to. /// A collection of . /// Thrown when assembly results cannot be created. private static IEnumerable CreateExportableFailureMechanismSectionResults( Dictionary failureMechanismSections, MacroStabilityOutwardsFailureMechanism macroStabilityOutwardsFailureMechanism, IAssessmentSection assessmentSection) { var exportableResults = new List(); foreach (KeyValuePair failureMechanismSectionPair in failureMechanismSections) { MacroStabilityOutwardsFailureMechanismSectionResult failureMechanismSectionResult = failureMechanismSectionPair.Key; FailureMechanismSectionAssemblyCategoryGroup simpleAssembly = MacroStabilityOutwardsFailureMechanismAssemblyFactory.AssembleSimpleAssessment(failureMechanismSectionResult); FailureMechanismSectionAssemblyCategoryGroup detailedAssembly = MacroStabilityOutwardsFailureMechanismAssemblyFactory.AssembleDetailedAssessment(failureMechanismSectionResult, macroStabilityOutwardsFailureMechanism, assessmentSection); FailureMechanismSectionAssemblyCategoryGroup tailorMadeAssembly = MacroStabilityOutwardsFailureMechanismAssemblyFactory.AssembleTailorMadeAssessment(failureMechanismSectionResult, macroStabilityOutwardsFailureMechanism, assessmentSection); FailureMechanismSectionAssemblyCategoryGroup combinedAssembly = MacroStabilityOutwardsFailureMechanismAssemblyFactory.AssembleCombinedAssessment(failureMechanismSectionResult, macroStabilityOutwardsFailureMechanism, assessmentSection); exportableResults.Add( new ExportableAggregatedFailureMechanismSectionAssemblyResult( failureMechanismSectionPair.Value, ExportableSectionAssemblyResultFactory.CreateExportableSectionAssemblyResult(simpleAssembly, ExportableAssemblyMethod.WBI0E1), ExportableSectionAssemblyResultFactory.CreateExportableSectionAssemblyResult(detailedAssembly, ExportableAssemblyMethod.WBI0G3), ExportableSectionAssemblyResultFactory.CreateExportableSectionAssemblyResult(tailorMadeAssembly, ExportableAssemblyMethod.WBI0T7), ExportableSectionAssemblyResultFactory.CreateExportableSectionAssemblyResult(combinedAssembly, ExportableAssemblyMethod.WBI0A1))); } return exportableResults; } } }