// Copyright (C) Stichting Deltares 2017. All rights reserved.
//
// This file is part of Ringtoets.
//
// Ringtoets 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 System.Collections.Generic;
using System.Linq;
using Assembly.Kernel.Interfaces;
using Assembly.Kernel.Model;
using Ringtoets.AssemblyTool.Data;
using Ringtoets.AssemblyTool.KernelWrapper.Creators;
using Ringtoets.AssemblyTool.KernelWrapper.Kernels;
namespace Ringtoets.AssemblyTool.KernelWrapper.Calculators.Assembly
{
///
/// Class representing an assessment section assembly calculator.
///
public class AssessmentSectionAssemblyCalculator : IAssessmentSectionAssemblyCalculator
{
private readonly IAssemblyToolKernelFactory factory;
///
/// Creates a new instance of .
///
/// The factory responsible for creating the assembly kernel.
/// Thrown when any parameter is null.
public AssessmentSectionAssemblyCalculator(IAssemblyToolKernelFactory factory)
{
if (factory == null)
{
throw new ArgumentNullException(nameof(factory));
}
this.factory = factory;
}
public AssessmentSectionAssembly AssembleFailureMechanisms(IEnumerable input,
double signalingNorm,
double lowerLimitNorm)
{
try
{
IAssessmentGradeAssembler kernel = factory.CreateAssessmentSectionAssemblyKernel();
AssessmentSectionAssemblyResult output = kernel.AssembleAssessmentSectionWbi2B1(
new AssessmentSection(1, signalingNorm, lowerLimitNorm),
input.Select(AssessmentSectionAssemblyInputCreator.CreateFailureMechanismAssemblyResult).ToArray(),
false);
return AssessmentSectionAssemblyCreator.CreateAssessmentSectionAssembly(output);
}
catch (Exception e)
{
throw new AssessmentSectionAssemblyCalculatorException(e.Message, e);
}
}
public AssessmentSectionAssemblyCategoryGroup AssembleFailureMechanisms(IEnumerable input)
{
try
{
IAssessmentGradeAssembler kernel = factory.CreateAssessmentSectionAssemblyKernel();
EAssessmentGrade output = kernel.AssembleAssessmentSectionWbi2A1(
input.Select(AssessmentSectionAssemblyInputCreator.CreateFailureMechanismAssemblyResult).ToArray(),
false);
return AssemblyCategoryCreator.CreateAssessmentSectionAssemblyCategory(output);
}
catch (Exception e)
{
throw new AssessmentSectionAssemblyCalculatorException(e.Message, e);
}
}
public AssessmentSectionAssemblyCategoryGroup AssembleAssessmentSection(AssessmentSectionAssemblyCategoryGroup failureMechanismsWithoutProbability,
AssessmentSectionAssembly failureMechanismsWithProbability)
{
try
{
IAssessmentGradeAssembler kernel = factory.CreateAssessmentSectionAssemblyKernel();
AssessmentSectionAssemblyResult output = kernel.AssembleAssessmentSectionWbi2C1(
AssessmentSectionAssemblyInputCreator.CreateAssessementSectionAssemblyResult(failureMechanismsWithoutProbability),
AssessmentSectionAssemblyInputCreator.CreateAssessementSectionAssemblyResult(failureMechanismsWithProbability));
return AssessmentSectionAssemblyCreator.CreateAssessmentSectionAssembly(output).Group;
}
catch (Exception e)
{
throw new AssessmentSectionAssemblyCalculatorException(e.Message, e);
}
}
public IEnumerable AssembleCombinedFailureMechanismSections(
IEnumerable input, double assessmentSectionLength)
{
try
{
ICommonFailureMechanismSectionAssembler kernel = factory.CreateCombinedFailureMechanismSectionAssemblyKernel();
AssemblyResult output = kernel.AssembleCommonFailureMechanismSections(FailureMechanismSectionListCreator.Create(input), assessmentSectionLength, false);
return CombinedFailureMechanismSectionAssemblyCreator.Create(output).ToArray();
}
catch (Exception e)
{
throw new AssessmentSectionAssemblyCalculatorException(e.Message, e);
}
}
}
}