Files
StructureHelper/StructureHelperCommon/Models/Materials/ConcreteCurveLogic.cs
2024-05-26 11:35:48 +05:00

63 lines
1.9 KiB
C#

using LoaderCalculator.Data.Materials;
using LoaderCalculator.Data.Materials.MaterialBuilders;
using StructureHelperCommon.Infrastructures.Enums;
using StructureHelperCommon.Infrastructures.Exceptions;
namespace StructureHelperCommon.Models.Materials
{
public class ConcreteCurveLogic : IMaterialLogic
{
private ConcreteOptions concreteOptions;
private IMaterialOptionLogic optionLogic;
private ConcreteLogicOptions options;
public string Name { get; set; }
public IMaterialLogicOptions Options
{
get => options;
set
{
if (value is not ConcreteLogicOptions)
{
throw new StructureHelperException($"{ErrorStrings.ExpectedWas(typeof(ConcreteLogicOptions), value)}");
}
options = (ConcreteLogicOptions)value;
}
}
public MaterialTypes MaterialType { get; set; }
public DiagramType DiagramType { get; set; }
public IMaterial GetLoaderMaterial()
{
GetLoaderOptions();
IBuilderDirector director = GetMaterialDirector();
try
{
var material = director.BuildMaterial();
return material;
}
catch (System.Exception)
{
throw;
}
}
private IBuilderDirector GetMaterialDirector()
{
IMaterialBuilder builder = new ConcreteBuilder(concreteOptions);
IBuilderDirector director = new BuilderDirector(builder);
return director;
}
private void GetLoaderOptions()
{
concreteOptions = new ConcreteOptions();
optionLogic = new ConcreteMaterialOptionLogic(options);
optionLogic.SetMaterialOptions(concreteOptions);
}
}
}