Material Update Strategy was added
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelperLogics.Models.Materials
|
||||
{
|
||||
internal class ConcreteLibUpdateStrategy : IUpdateStrategy<IConcreteLibMaterial>
|
||||
{
|
||||
LibMaterialUpdateStrategy libUpdateStrategy = new LibMaterialUpdateStrategy();
|
||||
public void Update(IConcreteLibMaterial targetObject, IConcreteLibMaterial sourceObject)
|
||||
{
|
||||
libUpdateStrategy.Update(targetObject, sourceObject);
|
||||
targetObject.TensionForULS = sourceObject.TensionForULS;
|
||||
targetObject.TensionForSLS = sourceObject.TensionForSLS;
|
||||
targetObject.Humidity = sourceObject.Humidity;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
using StructureHelperCommon.Infrastructures.Enums;
|
||||
using StructureHelperCommon.Infrastructures.Exceptions;
|
||||
using StructureHelperCommon.Infrastructures.Strings;
|
||||
using LCMB = LoaderCalculator.Data.Materials.MaterialBuilders;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelperLogics.Models.Materials
|
||||
{
|
||||
internal class ElasticUpdateStrategy : IUpdateStrategy<IElasticMaterial>
|
||||
{
|
||||
public void Update(IElasticMaterial targetObject, IElasticMaterial sourceObject)
|
||||
{
|
||||
targetObject.Modulus = sourceObject.Modulus;
|
||||
targetObject.CompressiveStrength = sourceObject.CompressiveStrength;
|
||||
targetObject.TensileStrength = sourceObject.TensileStrength;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelperLogics.Models.Materials
|
||||
{
|
||||
internal class FRUpdateStrategy : IUpdateStrategy<IFRMaterial>
|
||||
{
|
||||
public void Update(IFRMaterial targetObject, IFRMaterial sourceObject)
|
||||
{
|
||||
targetObject.Modulus = sourceObject.Modulus;
|
||||
targetObject.CompressiveStrength = sourceObject.CompressiveStrength;
|
||||
targetObject.TensileStrength = targetObject.TensileStrength;
|
||||
targetObject.ULSConcreteStrength = targetObject.ULSConcreteStrength;
|
||||
targetObject.SumThickness = targetObject.SumThickness;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Models.Materials.Libraries;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelperLogics.Models.Materials
|
||||
{
|
||||
internal class LibMaterialUpdateStrategy : IUpdateStrategy<ILibMaterial>
|
||||
{
|
||||
public void Update(ILibMaterial targetObject, ILibMaterial sourceObject)
|
||||
{
|
||||
targetObject.MaterialEntity = sourceObject.MaterialEntity;
|
||||
targetObject.SafetyFactors.Clear();
|
||||
foreach (var item in sourceObject.SafetyFactors)
|
||||
{
|
||||
targetObject.SafetyFactors.Add(item.Clone() as IMaterialSafetyFactor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
using StructureHelper.Models.Materials;
|
||||
using StructureHelperCommon.Infrastructures.Exceptions;
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelperLogics.Models.Materials
|
||||
{
|
||||
public class MaterialUpdateStrategy : IUpdateStrategy<IHeadMaterial>
|
||||
{
|
||||
public void Update(IHeadMaterial targetObject, IHeadMaterial sourceObject)
|
||||
{
|
||||
targetObject.Name = sourceObject.Name;
|
||||
targetObject.Color = sourceObject.Color;
|
||||
targetObject.HelperMaterial = sourceObject.HelperMaterial.Clone() as IHelperMaterial;
|
||||
UpdateHelperMaterial(targetObject.HelperMaterial, sourceObject.HelperMaterial);
|
||||
}
|
||||
|
||||
private static void UpdateHelperMaterial(IHelperMaterial target, IHelperMaterial source)
|
||||
{
|
||||
Check(target, source);
|
||||
UpdateMaterial(target, source);
|
||||
}
|
||||
private static void Check(IHelperMaterial target, IHelperMaterial source)
|
||||
{
|
||||
if (target.GetType() != source.GetType())
|
||||
{
|
||||
throw new StructureHelperException(ErrorStrings.DataIsInCorrect + $"target type is {target.GetType()}, \n is no coinside with source type {source.GetType()}");
|
||||
}
|
||||
}
|
||||
private static void UpdateMaterial(IHelperMaterial target, IHelperMaterial source)
|
||||
{
|
||||
if (source is ILibMaterial)
|
||||
{
|
||||
UpdateLibMaterial(target, source);
|
||||
}
|
||||
else if (source is IElasticMaterial)
|
||||
{
|
||||
UpdateElastic(target, source);
|
||||
}
|
||||
else if (source is IFRMaterial)
|
||||
{
|
||||
UpdateFR(target, source);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknown + $"\n Expected: {typeof(IHelperMaterial)},\n But was: {source.GetType()}");
|
||||
}
|
||||
}
|
||||
private static void UpdateFR(IHelperMaterial target, IHelperMaterial source)
|
||||
{
|
||||
var targetMaterial = target as IFRMaterial;
|
||||
var sourceMaterial = source as IFRMaterial;
|
||||
var logic = new FRUpdateStrategy();
|
||||
logic.Update(targetMaterial, sourceMaterial);
|
||||
}
|
||||
private static void UpdateElastic(IHelperMaterial target, IHelperMaterial source)
|
||||
{
|
||||
var targetMaterial = target as IElasticMaterial;
|
||||
var sourceMaterial = source as IElasticMaterial;
|
||||
var logic = new ElasticUpdateStrategy();
|
||||
logic.Update(targetMaterial, sourceMaterial);
|
||||
}
|
||||
private static void UpdateLibMaterial(IHelperMaterial target, IHelperMaterial source)
|
||||
{
|
||||
if (source is IConcreteLibMaterial)
|
||||
{
|
||||
var targetMaterial = target as IConcreteLibMaterial;
|
||||
var sourceMaterial = source as IConcreteLibMaterial;
|
||||
var logic = new ConcreteLibUpdateStrategy();
|
||||
logic.Update(targetMaterial, sourceMaterial);
|
||||
}
|
||||
else if (source is IReinforcementLibMaterial)
|
||||
{
|
||||
var targetMaterial = target as IReinforcementLibMaterial;
|
||||
var sourceMaterial = source as IReinforcementLibMaterial;
|
||||
var logic = new ReinforcementLibUpdateStrategy();
|
||||
logic.Update(targetMaterial, sourceMaterial);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknown + $"\n Expected: {typeof(ILibMaterial)},\n But was: {source.GetType()}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelperLogics.Models.Materials
|
||||
{
|
||||
internal class ReinforcementLibUpdateStrategy : IUpdateStrategy<IReinforcementLibMaterial>
|
||||
{
|
||||
LibMaterialUpdateStrategy libUpdateStrategy = new LibMaterialUpdateStrategy();
|
||||
public void Update(IReinforcementLibMaterial targetObject, IReinforcementLibMaterial sourceObject)
|
||||
{
|
||||
libUpdateStrategy.Update(targetObject, sourceObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user