Add materials converting from DTOs

This commit is contained in:
Evgeny Redikultsev
2024-10-27 21:29:50 +05:00
parent b0c24126da
commit 223e69263f
71 changed files with 1398 additions and 253 deletions

View File

@@ -3,10 +3,10 @@
{
public enum MaterialTypes
{
Concrete,
Reinforcement,
//Steel,
CarbonFiber,
GlassFiber,
Concrete = 0,
Reinforcement = 1,
Steel = 3,
CarbonFiber = 4,
GlassFiber = 5,
}
}

View File

@@ -0,0 +1,40 @@
using StructureHelperCommon.Models;
using StructureHelperCommon.Models.Loggers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StructureHelperCommon.Infrastructures.Interfaces
{
public abstract class ConvertStrategy<T, V> : IConvertStrategy<T, V>
where T : ISaveable
where V : ISaveable
{
public Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; set; }
public IShiftTraceLogger TraceLogger { get; set; }
public virtual T Convert(V source)
{
try
{
Check();
return GetNewItem(source);
}
catch (Exception ex)
{
TraceLogger?.AddMessage(LoggerStrings.LogicType(this), TraceLogStatuses.Error);
TraceLogger?.AddMessage(ex.Message, TraceLogStatuses.Error);
throw;
}
}
public abstract T GetNewItem(V source);
private void Check()
{
var checkLogic = new CheckConvertLogic<T,V>(this);
checkLogic.Check();
}
}
}

View File

@@ -10,6 +10,11 @@ using System.Windows.Media;
namespace StructureHelperCommon.Infrastructures.Interfaces
{
/// <summary>
/// Find object in refernce dictionary, if it exists return existing object, else return new one by child logic
/// </summary>
/// <typeparam name="T">Type of target object</typeparam>
/// <typeparam name="V">Type of source object</typeparam>
public class DictionaryConvertStrategy<T, V> : IConvertStrategy<T, V>
where T : ISaveable
where V : ISaveable

View File

@@ -7,10 +7,20 @@ using System.Threading.Tasks;
namespace StructureHelperCommon.Infrastructures.Interfaces
{
/// <summary>
/// Converts object of type of ISaveable to another one
/// </summary>
/// <typeparam name="T">Target object type</typeparam>
/// <typeparam name="V">Source object type</typeparam>
public interface IConvertStrategy<T,V> : IBaseConvertStrategy
where T :ISaveable
where V :ISaveable
{
/// <summary>
/// Converts object to another one
/// </summary>
/// <param name="source">Source object</param>
/// <returns>Converted object</returns>
T Convert(V source);
}
}

View File

@@ -0,0 +1,30 @@
using StructureHelper.Models.Materials;
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models.Forces;
using StructureHelperCommon.Models.Repositories;
namespace StructureHelperCommon.Infrastructures.Settings
{
internal static class GlobalRepository
{
private static IDataRepository<IHeadMaterial> materials;
private static IDataRepository<IAction> actions;
//public static IDataRepository<IHeadMaterial> Materials
//{
// get
// {
// materials ??= new ListRepository<IHeadMaterial>(new HeadMaterialUpdateStrategy());
// return materials;
// }
//}
//public static IDataRepository<IAction> Actions
//{
// get
// {
// actions ??= new ListRepository<IAction>(new ActionUpdateStrategy());
// return actions;
// }
//}
}
}

View File

@@ -11,6 +11,6 @@ namespace StructureHelperCommon.Models.Analyses
{
string Name { get; set; }
string Tags { get; set; }
IVersionProcessor VersionProcessor { get;}
IVersionProcessor VersionProcessor { get; set; }
}
}

View File

@@ -22,7 +22,7 @@ namespace StructureHelperCommon.Models.Forces
/// <inheritdoc/>
public IPoint2D ForcePoint { get; set; }
/// <inheritdoc/>
public IForceTuple FullSLSForces { get; private set; }
public IForceTuple FullSLSForces { get; set; }
/// <inheritdoc/>
public double ULSFactor { get; set; }
/// <inheritdoc/>

View File

@@ -22,7 +22,7 @@ namespace StructureHelperCommon.Models.Forces
/// <inheritdoc/>
public IPoint2D ForcePoint { get; set; }
/// <inheritdoc/>
public List<IDesignForceTuple> DesignForces { get; private set; }
public List<IDesignForceTuple> DesignForces { get; set; }
public ForceCombinationList(Guid id)

View File

@@ -9,7 +9,7 @@ namespace StructureHelperCommon.Models.Forces
{
public interface IForceCombinationByFactor : IForceAction
{
IForceTuple FullSLSForces { get; }
IForceTuple FullSLSForces { get; set; }
double ULSFactor { get; set; }
double LongTermFactor { get; set; }
}

View File

@@ -6,6 +6,6 @@ namespace StructureHelperCommon.Models.Forces
{
public interface IForceCombinationList : IForceAction
{
List<IDesignForceTuple> DesignForces { get;}
List<IDesignForceTuple> DesignForces { get; set; }
}
}

View File

@@ -0,0 +1,10 @@
using StructureHelperCommon.Models.Materials.Libraries;
using System.Collections.Generic;
namespace StructureHelperLogics.Models.Materials
{
public interface IHasSafetyFactors
{
List<IMaterialSafetyFactor> SafetyFactors { get; set; }
}
}

View File

@@ -0,0 +1,18 @@
using LoaderCalculator.Data.Materials;
using StructureHelperCommon.Infrastructures.Enums;
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperLogics.Models.Materials;
using System;
using System.Windows.Media;
namespace StructureHelper.Models.Materials
{
public interface IHeadMaterial : ISaveable, ICloneable
{
string Name { get; set; }
Color Color { get; set; }
IHelperMaterial HelperMaterial { get; set; }
IMaterial GetLoaderMaterial(LimitStates limitState, CalcTerms calcTerm);
IMaterial GetCrackedLoaderMaterial(LimitStates limitState, CalcTerms calcTerm);
}
}

View File

@@ -0,0 +1,17 @@
using LoaderCalculator.Data.Materials;
using StructureHelperCommon.Infrastructures.Enums;
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models.Materials.Libraries;
using StructureHelperLogics.Models.Materials;
using System;
using System.Collections.Generic;
using System.Text;
namespace StructureHelperLogics.Models.Materials
{
public interface IHelperMaterial : ISaveable, ICloneable, IHasSafetyFactors
{
IMaterial GetLoaderMaterial(LimitStates limitState, CalcTerms calcTerm);
IMaterial GetCrackedLoaderMaterial(LimitStates limitState, CalcTerms calcTerm);
}
}

View File

@@ -0,0 +1,18 @@
using StructureHelperCommon.Infrastructures.Enums;
using StructureHelperCommon.Models.Materials;
using StructureHelperCommon.Models.Materials.Libraries;
using StructureHelperLogics.Models.Materials;
using System;
using System.Collections.Generic;
using System.Text;
namespace StructureHelperLogics.Models.Materials
{
public interface ILibMaterial : IHelperMaterial
{
ILibMaterialEntity MaterialEntity { get; set; }
IMaterialLogic MaterialLogic { get; set; }
List<IMaterialLogic> MaterialLogics { get; }
(double Compressive, double Tensile) GetStrength(LimitStates limitState, CalcTerms calcTerm);
}
}

View File

@@ -0,0 +1,23 @@
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StructureHelperCommon.Models.Materials.Libraries
{
public class MaterialSafetyFactorBaseUpdateStrategy : IUpdateStrategy<IMaterialSafetyFactor>
{
public void Update(IMaterialSafetyFactor targetObject, IMaterialSafetyFactor sourceObject)
{
CheckObject.IsNull(sourceObject);
CheckObject.IsNull(targetObject);
if (ReferenceEquals(targetObject, sourceObject)) { return; }
targetObject.Name = sourceObject.Name;
targetObject.Take = sourceObject.Take;
targetObject.Description = sourceObject.Description;
}
}
}

View File

@@ -10,14 +10,13 @@ namespace StructureHelperCommon.Models.Materials.Libraries
{
public class MaterialSafetyFactorUpdateStrategy : IUpdateStrategy<IMaterialSafetyFactor>
{
private IUpdateStrategy<IMaterialSafetyFactor> baseUpdateStrategy = new MaterialSafetyFactorBaseUpdateStrategy();
public void Update(IMaterialSafetyFactor targetObject, IMaterialSafetyFactor sourceObject)
{
CheckObject.IsNull(sourceObject);
CheckObject.IsNull(targetObject);
if (ReferenceEquals(targetObject, sourceObject)) { return; }
targetObject.Name = sourceObject.Name;
targetObject.Take = sourceObject.Take;
targetObject.Description = sourceObject.Description;
baseUpdateStrategy.Update(targetObject, sourceObject);
targetObject.PartialFactors.Clear();
foreach (var item in sourceObject.PartialFactors)
{