95 lines
3.3 KiB
C#
95 lines
3.3 KiB
C#
using StructureHelperCommon.Infrastructures.Exceptions;
|
|
using StructureHelperCommon.Infrastructures.Interfaces;
|
|
using StructureHelperCommon.Models;
|
|
using StructureHelperCommon.Models.Calculators;
|
|
using StructureHelperCommon.Models.Materials;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace StructureHelperLogics.NdmCalculations.Primitives.Logics
|
|
{
|
|
public class CheckPrimitiveCollectionLogic : ICheckEntityLogic<IHasPrimitives>
|
|
{
|
|
private const string collectionDoesntHaveAnyPrimitives = "Calculator does not contain any primitives\n";
|
|
private const string checkRebarLogic = ": check rebar logic";
|
|
|
|
private string checkResult;
|
|
private bool result;
|
|
private ICheckEntityLogic<IRebarNdmPrimitive> checkRebarPrimitiveLogic;
|
|
|
|
public IHasPrimitives Entity { get; set; }
|
|
|
|
public string CheckResult => checkResult;
|
|
|
|
public IShiftTraceLogger? TraceLogger { get; set; }
|
|
|
|
public CheckPrimitiveCollectionLogic(
|
|
IShiftTraceLogger shiftTraceLogger,
|
|
ICheckEntityLogic<IRebarNdmPrimitive> checkRebarPrimitiveLogic)
|
|
{
|
|
TraceLogger = shiftTraceLogger;
|
|
this.checkRebarPrimitiveLogic = checkRebarPrimitiveLogic;
|
|
}
|
|
|
|
public CheckPrimitiveCollectionLogic() : this (new ShiftTraceLogger(), new CheckRebarPrimitiveLogic())
|
|
{
|
|
|
|
}
|
|
|
|
public bool Check()
|
|
{
|
|
result = true;
|
|
checkResult = string.Empty;
|
|
CheckPrimitives();
|
|
return result;
|
|
}
|
|
|
|
private void CheckPrimitives()
|
|
{
|
|
if (Entity.Primitives is null || (!Entity.Primitives.Any()))
|
|
{
|
|
result = false;
|
|
checkResult += collectionDoesntHaveAnyPrimitives;
|
|
TraceLogger?.AddMessage(collectionDoesntHaveAnyPrimitives, TraceLogStatuses.Error);
|
|
}
|
|
else
|
|
{
|
|
foreach (var primitive in Entity.Primitives)
|
|
{
|
|
if (primitive is IRebarNdmPrimitive rebar)
|
|
{
|
|
CheckRebar(rebar);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void CheckRebar(IRebarNdmPrimitive rebar)
|
|
{
|
|
if (checkRebarPrimitiveLogic is null)
|
|
{
|
|
throw new StructureHelperException(ErrorStrings.ParameterIsNull + checkRebarLogic);
|
|
}
|
|
checkRebarPrimitiveLogic.Entity = rebar;
|
|
checkRebarPrimitiveLogic.TraceLogger = TraceLogger?.GetSimilarTraceLogger();
|
|
if (checkRebarPrimitiveLogic.Check() == false)
|
|
{
|
|
result = false;
|
|
checkResult += checkRebarPrimitiveLogic.CheckResult;
|
|
return;
|
|
}
|
|
bool isPrimitivesContainRebarHost = Entity.Primitives.Contains(rebar.HostPrimitive);
|
|
if (isPrimitivesContainRebarHost == false)
|
|
{
|
|
result = false;
|
|
string message = $"Host {rebar.Name} ({rebar.HostPrimitive.Name}) is not included in primitives\n";
|
|
checkResult += message;
|
|
TraceLogger?.AddMessage(message, TraceLogStatuses.Error);
|
|
}
|
|
}
|
|
}
|
|
}
|