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

@@ -16,17 +16,32 @@ namespace DataAccess.DTOs.Converters
{ {
public class AnalysisFromDTOConvertStrategy : IConvertStrategy<IAnalysis, IAnalysis> public class AnalysisFromDTOConvertStrategy : IConvertStrategy<IAnalysis, IAnalysis>
{ {
private const string Message = "Analysis type is"; private const string AnalysisIs = "Analysis type is";
private IConvertStrategy<ICrossSectionNdmAnalysis, ICrossSectionNdmAnalysis> convertCrossSectionNdmAnalysisStrategy = new CrossSectionNdmAnalysisFromDTOConvertStrategy();
private IConvertStrategy<ICrossSectionNdmAnalysis, ICrossSectionNdmAnalysis> convertCrossSectionNdmAnalysisStrategy;
private IConvertStrategy<IVersionProcessor, IVersionProcessor> versionProcessorConvertStrategy;
public AnalysisFromDTOConvertStrategy(IConvertStrategy<ICrossSectionNdmAnalysis, ICrossSectionNdmAnalysis> convertCrossSectionNdmAnalysisStrategy,
IConvertStrategy<IVersionProcessor, IVersionProcessor> versionProcessorConvertStrategy)
{
this.convertCrossSectionNdmAnalysisStrategy = convertCrossSectionNdmAnalysisStrategy;
this.versionProcessorConvertStrategy = versionProcessorConvertStrategy;
}
public AnalysisFromDTOConvertStrategy() : this (new CrossSectionNdmAnalysisFromDTOConvertStrategy(),
new VersionProcessorFromDTOConvertStrategy())
{
}
public Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; set; } public Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; set; }
public IShiftTraceLogger TraceLogger { get; set; } public IShiftTraceLogger TraceLogger { get; set; }
public IAnalysis Convert(IAnalysis source) public IAnalysis Convert(IAnalysis source)
{ {
Check();
try try
{ {
Check();
IAnalysis analysis = GetAnalysis(source); IAnalysis analysis = GetAnalysis(source);
return analysis; return analysis;
} }
@@ -41,10 +56,10 @@ namespace DataAccess.DTOs.Converters
private IAnalysis GetAnalysis(IAnalysis source) private IAnalysis GetAnalysis(IAnalysis source)
{ {
IAnalysis analysis; IAnalysis newItem;
if (source is ICrossSectionNdmAnalysis crossSectionNdmAnalysis) if (source is ICrossSectionNdmAnalysis crossSectionNdmAnalysis)
{ {
analysis = GetCrossSectionNdmAnalysis(crossSectionNdmAnalysis); newItem = GetCrossSectionNdmAnalysis(crossSectionNdmAnalysis);
} }
else else
{ {
@@ -52,21 +67,29 @@ namespace DataAccess.DTOs.Converters
TraceLogger?.AddMessage(errorString, TraceLogStatuses.Error); TraceLogger?.AddMessage(errorString, TraceLogStatuses.Error);
throw new StructureHelperException(errorString); throw new StructureHelperException(errorString);
} }
foreach (var item in source.VersionProcessor.Versions) newItem.VersionProcessor = GetVersionProcessor(source.VersionProcessor);
{ return newItem;
//to do }
}
return analysis; private IVersionProcessor GetVersionProcessor(IVersionProcessor source)
{
TraceLogger?.AddMessage("Version processor converting is started", TraceLogStatuses.Service);
versionProcessorConvertStrategy.ReferenceDictionary = ReferenceDictionary;
versionProcessorConvertStrategy.TraceLogger = TraceLogger;
IVersionProcessor versionProcessor = versionProcessorConvertStrategy.Convert(source);
TraceLogger?.AddMessage("Version processor converting has been finished succesfully", TraceLogStatuses.Service);
return versionProcessor;
} }
private ICrossSectionNdmAnalysis GetCrossSectionNdmAnalysis(ICrossSectionNdmAnalysis source) private ICrossSectionNdmAnalysis GetCrossSectionNdmAnalysis(ICrossSectionNdmAnalysis source)
{ {
TraceLogger?.AddMessage(Message + " Cross-Section Ndm Analysis", TraceLogStatuses.Debug); TraceLogger?.AddMessage(AnalysisIs + " Cross-Section Ndm Analysis", TraceLogStatuses.Service);
TraceLogger?.AddMessage("Cross-Section Ndm Analysis converting is started", TraceLogStatuses.Service);
convertCrossSectionNdmAnalysisStrategy.ReferenceDictionary = ReferenceDictionary; convertCrossSectionNdmAnalysisStrategy.ReferenceDictionary = ReferenceDictionary;
convertCrossSectionNdmAnalysisStrategy.TraceLogger = TraceLogger; convertCrossSectionNdmAnalysisStrategy.TraceLogger = TraceLogger;
var convertLogic = new DictionaryConvertStrategy<ICrossSectionNdmAnalysis, ICrossSectionNdmAnalysis>(this, convertCrossSectionNdmAnalysisStrategy); var convertLogic = new DictionaryConvertStrategy<ICrossSectionNdmAnalysis, ICrossSectionNdmAnalysis>(this, convertCrossSectionNdmAnalysisStrategy);
ICrossSectionNdmAnalysis crossSectionNdmAnalysis = convertLogic.Convert(source); ICrossSectionNdmAnalysis crossSectionNdmAnalysis = convertLogic.Convert(source);
TraceLogger?.AddMessage("Cross-Section Ndm Analysis converting has been finished succesfully", TraceLogStatuses.Service);
return crossSectionNdmAnalysis; return crossSectionNdmAnalysis;
} }

View File

@@ -0,0 +1,35 @@
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models;
using StructureHelperLogics.Models.Materials;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DataAccess.DTOs
{
public class ConcreteLibMaterialFromDTOConvertStrategy : ConvertStrategy<ConcreteLibMaterial, ConcreteLibMaterialDTO>
{
private readonly IUpdateStrategy<IConcreteLibMaterial> updateStrategy;
public ConcreteLibMaterialFromDTOConvertStrategy(IUpdateStrategy<IConcreteLibMaterial> updateStrategy)
{
this.updateStrategy = updateStrategy;
}
public ConcreteLibMaterialFromDTOConvertStrategy() : this (new ConcreteLibUpdateStrategy())
{
}
public override ConcreteLibMaterial GetNewItem(ConcreteLibMaterialDTO source)
{
TraceLogger?.AddMessage("Concrete library material converting is started", TraceLogStatuses.Service);
ConcreteLibMaterial newItem = new(source.Id);
updateStrategy.Update(newItem, source);
TraceLogger?.AddMessage("Concrete library material converting has been finished succesfully", TraceLogStatuses.Service);
return newItem;
}
}
}

View File

@@ -0,0 +1,69 @@
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models;
using StructureHelperCommon.Models.Loggers;
using StructureHelperLogics.Models.CrossSections;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DataAccess.DTOs
{
public class CrossSectionFromDTOConvertStrategy : IConvertStrategy<ICrossSection, ICrossSection>
{
private readonly IConvertStrategy<ICrossSectionRepository, ICrossSectionRepository> convertStrategy;
public CrossSectionFromDTOConvertStrategy(IConvertStrategy<ICrossSectionRepository, ICrossSectionRepository> convertStrategy)
{
this.convertStrategy = convertStrategy;
}
public CrossSectionFromDTOConvertStrategy() : this (new CrossSectionRepositoryFromDTOConvertStrategy())
{
}
public Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; set; }
public IShiftTraceLogger TraceLogger { get; set; }
public ICrossSection Convert(ICrossSection source)
{
try
{
Check();
return GetNewCrossSection(source);
}
catch (Exception ex)
{
TraceLogger?.AddMessage(LoggerStrings.LogicType(this), TraceLogStatuses.Error);
TraceLogger?.AddMessage(ex.Message, TraceLogStatuses.Error);
throw;
}
}
private ICrossSection GetNewCrossSection(ICrossSection source)
{
TraceLogger?.AddMessage("Cross-Section converting is started", TraceLogStatuses.Service);
CrossSection newItem = new(source.Id);
convertStrategy.ReferenceDictionary = ReferenceDictionary;
convertStrategy.TraceLogger = TraceLogger;
newItem.SectionRepository = GetNewCrossSectionRepository(source.SectionRepository);
TraceLogger?.AddMessage("Cross-Section converting has been finished succesfully", TraceLogStatuses.Service);
return newItem;
}
private ICrossSectionRepository GetNewCrossSectionRepository(ICrossSectionRepository source)
{
ICrossSectionRepository newItem = convertStrategy.Convert(source);
TraceLogger?.AddMessage($"Object of type <<{newItem.GetType()}>> was obtained", TraceLogStatuses.Service);
return newItem;
}
private void Check()
{
var checkLogic = new CheckConvertLogic<ICrossSection, ICrossSection>(this);
checkLogic.Check();
}
}
}

View File

@@ -1,5 +1,6 @@
using StructureHelperCommon.Infrastructures.Interfaces; using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models; using StructureHelperCommon.Models;
using StructureHelperCommon.Models.Analyses;
using StructureHelperCommon.Models.Loggers; using StructureHelperCommon.Models.Loggers;
using StructureHelperLogic.Models.Analyses; using StructureHelperLogic.Models.Analyses;
using StructureHelperLogics.Models.Analyses; using StructureHelperLogics.Models.Analyses;
@@ -13,7 +14,18 @@ namespace DataAccess.DTOs.Converters
{ {
public class CrossSectionNdmAnalysisFromDTOConvertStrategy : IConvertStrategy<ICrossSectionNdmAnalysis, ICrossSectionNdmAnalysis> public class CrossSectionNdmAnalysisFromDTOConvertStrategy : IConvertStrategy<ICrossSectionNdmAnalysis, ICrossSectionNdmAnalysis>
{ {
private IUpdateStrategy<ICrossSectionNdmAnalysis> updateStrategy = new CrossSectionNdmAnalysisUpdateStrategy(); private IUpdateStrategy<ICrossSectionNdmAnalysis> updateStrategy;
public CrossSectionNdmAnalysisFromDTOConvertStrategy(IUpdateStrategy<ICrossSectionNdmAnalysis> updateStrategy)
{
this.updateStrategy = updateStrategy;
}
public CrossSectionNdmAnalysisFromDTOConvertStrategy() : this(new CrossSectionNdmAnalysisUpdateStrategy())
{
}
public Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; set; } public Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; set; }
public IShiftTraceLogger TraceLogger { get; set; } public IShiftTraceLogger TraceLogger { get; set; }
@@ -21,7 +33,8 @@ namespace DataAccess.DTOs.Converters
{ {
try try
{ {
CrossSectionNdmAnalysis newItem = GetCrossSectinNDMAnalysis(source); Check();
ICrossSectionNdmAnalysis newItem = GetCrossSectinNDMAnalysis(source);
return newItem; return newItem;
} }
catch (Exception ex) catch (Exception ex)
@@ -33,11 +46,19 @@ namespace DataAccess.DTOs.Converters
} }
private CrossSectionNdmAnalysis GetCrossSectinNDMAnalysis(ICrossSectionNdmAnalysis source) private ICrossSectionNdmAnalysis GetCrossSectinNDMAnalysis(ICrossSectionNdmAnalysis source)
{ {
TraceLogger?.AddMessage("Cross-section sonverting is started");
CrossSectionNdmAnalysis newItem = new(source.Id); CrossSectionNdmAnalysis newItem = new(source.Id);
updateStrategy.Update(newItem, source); updateStrategy.Update(newItem, source);
TraceLogger?.AddMessage("Cross-section analysis was obtained succesfully");
return newItem; return newItem;
} }
private void Check()
{
var checkLogic = new CheckConvertLogic<ICrossSectionNdmAnalysis, ICrossSectionNdmAnalysis>(this);
checkLogic.Check();
}
} }
} }

View File

@@ -1,6 +1,7 @@
using StructureHelperCommon.Infrastructures.Interfaces; using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models; using StructureHelperCommon.Models;
using StructureHelperCommon.Models.Analyses; using StructureHelperCommon.Models.Analyses;
using StructureHelperCommon.Models.Loggers;
using StructureHelperLogic.Models.Analyses; using StructureHelperLogic.Models.Analyses;
using StructureHelperLogics.Models.Analyses; using StructureHelperLogics.Models.Analyses;
using System; using System;
@@ -38,7 +39,22 @@ namespace DataAccess.DTOs.Converters
public CrossSectionNdmAnalysisDTO Convert(ICrossSectionNdmAnalysis source) public CrossSectionNdmAnalysisDTO Convert(ICrossSectionNdmAnalysis source)
{ {
Check(); try
{
Check();
return GetNewAnalysis(source);
}
catch (Exception ex)
{
TraceLogger?.AddMessage(LoggerStrings.LogicType(this), TraceLogStatuses.Error);
TraceLogger?.AddMessage(ex.Message, TraceLogStatuses.Error);
throw;
}
}
private CrossSectionNdmAnalysisDTO GetNewAnalysis(ICrossSectionNdmAnalysis source)
{
TraceLogger?.AddMessage("Cross-section ndm analysis converting is started", TraceLogStatuses.Debug);
CrossSectionNdmAnalysisDTO newItem = new(); CrossSectionNdmAnalysisDTO newItem = new();
newItem.Id = source.Id; newItem.Id = source.Id;
updateStrategy.Update(newItem, source); updateStrategy.Update(newItem, source);
@@ -50,7 +66,9 @@ namespace DataAccess.DTOs.Converters
ConvertStrategy = convertStrategy, ConvertStrategy = convertStrategy,
TraceLogger = TraceLogger TraceLogger = TraceLogger
}; };
TraceLogger?.AddMessage("Convert version processor is started", TraceLogStatuses.Service);
newItem.VersionProcessor = convertLogic.Convert(source.VersionProcessor); newItem.VersionProcessor = convertLogic.Convert(source.VersionProcessor);
TraceLogger?.AddMessage("Cross-section ndm analysis has been converted succesfully", TraceLogStatuses.Service);
return newItem; return newItem;
} }

View File

@@ -0,0 +1,52 @@
using StructureHelper.Models.Materials;
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models;
using StructureHelperCommon.Models.Loggers;
using StructureHelperLogics.Models.CrossSections;
using StructureHelperLogics.Models.Materials;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DataAccess.DTOs
{
public class CrossSectionRepositoryFromDTOConvertStrategy : ConvertStrategy<ICrossSectionRepository, ICrossSectionRepository>
{
private const string convertStarted = " converting is started";
private const string convertFinished = " converting has been finished succesfully";
private CrossSectionRepository newRepository;
public override CrossSectionRepository GetNewItem(ICrossSectionRepository source)
{
TraceLogger?.AddMessage("Cross-Section repository" + convertStarted, TraceLogStatuses.Service);
newRepository = new(source.Id);
ProcessMaterials(source);
ProcessActions(source);
TraceLogger?.AddMessage("Cross-Section repository" + convertFinished, TraceLogStatuses.Service);
return newRepository;
}
private void ProcessActions(ICrossSectionRepository source)
{
TraceLogger?.AddMessage("Actions"+ convertStarted, TraceLogStatuses.Service);
TraceLogger?.AddMessage("Actions" + convertFinished, TraceLogStatuses.Service);
throw new NotImplementedException();
}
private void ProcessMaterials(IHasHeadMaterials source)
{
TraceLogger?.AddMessage("Materials" + convertStarted, TraceLogStatuses.Service);
var convertStrategy = new HeadMaterialFromDTOConvertStrategy
{
ReferenceDictionary = ReferenceDictionary,
TraceLogger = TraceLogger
};
var convertLogic = new DictionaryConvertStrategy<IHeadMaterial, IHeadMaterial>(this, convertStrategy);
var updateStrategy = new HasMaterialFromDTOUpdateStrategy(convertLogic);
updateStrategy.Update(newRepository, source);
TraceLogger?.AddMessage("Materials" + convertFinished, TraceLogStatuses.Service);
}
}
}

View File

@@ -0,0 +1,71 @@
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models;
using StructureHelperCommon.Models.Analyses;
using StructureHelperCommon.Models.Loggers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DataAccess.DTOs
{
public class DateVersionFromDTOConvertStrategy : IConvertStrategy<IDateVersion, IDateVersion>
{
private IUpdateStrategy<IDateVersion> updateStrategy;
private IConvertStrategy<ISaveable, ISaveable> convertStrategy;
private DictionaryConvertStrategy<ISaveable, ISaveable> convertLogic;
public DateVersionFromDTOConvertStrategy(IUpdateStrategy<IDateVersion> updateStrategy,
IConvertStrategy<ISaveable, ISaveable> convertStrategy)
{
this.updateStrategy = updateStrategy;
this.convertStrategy = convertStrategy;
}
public DateVersionFromDTOConvertStrategy() : this (
new DateVersionUpdateStrategy(),
new VersionItemFromDTOConvertStrategy())
{
}
public Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; set; }
public IShiftTraceLogger TraceLogger { get; set; }
public IDateVersion Convert(IDateVersion source)
{
try
{
Check();
return GetDateVersion(source);
}
catch (Exception ex)
{
TraceLogger?.AddMessage(LoggerStrings.LogicType(this), TraceLogStatuses.Error);
TraceLogger?.AddMessage(ex.Message, TraceLogStatuses.Error);
throw;
}
}
private DateVersion GetDateVersion(IDateVersion source)
{
TraceLogger?.AddMessage("Date version converting is started", TraceLogStatuses.Service);
DateVersion newItem = new(source.Id);
updateStrategy.Update(newItem, source);
convertStrategy.ReferenceDictionary = ReferenceDictionary;
convertStrategy.TraceLogger = TraceLogger;
convertLogic = new DictionaryConvertStrategy<ISaveable, ISaveable>(this, convertStrategy);
newItem.AnalysisVersion = convertLogic.Convert(source.AnalysisVersion);
TraceLogger?.AddMessage($"Date version date = {newItem.DateTime} converting has been finished", TraceLogStatuses.Service);
return newItem;
}
private void Check()
{
var checkLogic = new CheckConvertLogic<IDateVersion, IDateVersion>(this);
checkLogic.Check();
}
}
}

View File

@@ -1,6 +1,7 @@
using StructureHelperCommon.Infrastructures.Interfaces; using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models; using StructureHelperCommon.Models;
using StructureHelperCommon.Models.Analyses; using StructureHelperCommon.Models.Analyses;
using StructureHelperCommon.Models.Loggers;
using StructureHelperLogic.Models.Analyses; using StructureHelperLogic.Models.Analyses;
using StructureHelperLogics.Models.CrossSections; using StructureHelperLogics.Models.CrossSections;
using System; using System;
@@ -37,7 +38,22 @@ namespace DataAccess.DTOs
public DateVersionDTO Convert(IDateVersion source) public DateVersionDTO Convert(IDateVersion source)
{ {
Check(); try
{
Check();
return GetNewDateVersion(source);
}
catch (Exception ex)
{
TraceLogger?.AddMessage(LoggerStrings.LogicType(this), TraceLogStatuses.Error);
TraceLogger?.AddMessage(ex.Message, TraceLogStatuses.Error);
throw;
}
}
private DateVersionDTO GetNewDateVersion(IDateVersion source)
{
TraceLogger?.AddMessage("Date version converting is started", TraceLogStatuses.Debug);
DateVersionDTO newItem = new() DateVersionDTO newItem = new()
{ {
Id = source.Id Id = source.Id
@@ -47,14 +63,13 @@ namespace DataAccess.DTOs
convertStrategy.TraceLogger = TraceLogger; convertStrategy.TraceLogger = TraceLogger;
convertLogic = new DictionaryConvertStrategy<ISaveable, ISaveable>(this, convertStrategy); convertLogic = new DictionaryConvertStrategy<ISaveable, ISaveable>(this, convertStrategy);
newItem.AnalysisVersion = convertLogic.Convert(source.AnalysisVersion); newItem.AnalysisVersion = convertLogic.Convert(source.AnalysisVersion);
TraceLogger?.AddMessage("Date version converting has been finished", TraceLogStatuses.Service);
return newItem; return newItem;
} }
private void Check() private void Check()
{ {
var checkLogic = new CheckConvertLogic<DateVersionDTO, IDateVersion>(); var checkLogic = new CheckConvertLogic<DateVersionDTO, IDateVersion>(this);
checkLogic.ConvertStrategy = this;
checkLogic.TraceLogger = TraceLogger;
checkLogic.Check(); checkLogic.Check();
} }
} }

View File

@@ -0,0 +1,45 @@
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models.Forces;
using StructureHelperCommon.Models.Forces.Logics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DataAccess.DTOs
{
public class DesignForceTupleFromDTOConvertStrategy : ConvertStrategy<DesignForceTuple, DesignForceTupleDTO>
{
private IUpdateStrategy<IDesignForceTuple> updateStrategy;
private IConvertStrategy<ForceTuple, ForceTupleDTO> forceTupleConvertStrategy;
public DesignForceTupleFromDTOConvertStrategy(
IUpdateStrategy<IDesignForceTuple> updateStrategy,
IConvertStrategy<ForceTuple, ForceTupleDTO> forceTupleConvertStrategy)
{
this.updateStrategy = updateStrategy;
this.forceTupleConvertStrategy = forceTupleConvertStrategy;
}
public DesignForceTupleFromDTOConvertStrategy() : this(
new DesignForceTupleUpdateStrategy(),
new ForceTupleFromDTOConvertStrategy())
{
}
public override DesignForceTuple GetNewItem(DesignForceTupleDTO source)
{
TraceLogger?.AddMessage("Design force tuple converting is started");
DesignForceTuple newItem = new(source.Id);
updateStrategy.Update(newItem, source);
forceTupleConvertStrategy.ReferenceDictionary = ReferenceDictionary;
forceTupleConvertStrategy.TraceLogger = TraceLogger;
var convertLogic = new DictionaryConvertStrategy<ForceTuple, ForceTupleDTO>(this, forceTupleConvertStrategy);
newItem.ForceTuple = convertLogic.Convert((ForceTupleDTO)source.ForceTuple);
TraceLogger?.AddMessage("Design force tuple converting has been finished");
return newItem;
}
}
}

View File

@@ -24,7 +24,8 @@ namespace DataAccess.DTOs.Converters
this.forceTupleConvertStrategy = forceTupleConvertStrategy; this.forceTupleConvertStrategy = forceTupleConvertStrategy;
} }
public DesignForceTupleToDTOConvertStrategy() : this(new DesignForceTupleUpdateStrategy(), public DesignForceTupleToDTOConvertStrategy() : this(
new DesignForceTupleUpdateStrategy(),
new ForceTupleToDTOConvertStrategy()) new ForceTupleToDTOConvertStrategy())
{ {

View File

@@ -0,0 +1,35 @@
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models;
using StructureHelperLogics.Models.Materials;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DataAccess.DTOs
{
public class ElasticMaterialFromDTOConvertStrategy : ConvertStrategy<ElasticMaterial, ElasticMaterialDTO>
{
private readonly IUpdateStrategy<IElasticMaterial> updateStrategy;
public ElasticMaterialFromDTOConvertStrategy(IUpdateStrategy<IElasticMaterial> updateStrategy)
{
this.updateStrategy = updateStrategy;
}
public ElasticMaterialFromDTOConvertStrategy() : this (new ElasticUpdateStrategy())
{
}
public override ElasticMaterial GetNewItem(ElasticMaterialDTO source)
{
TraceLogger?.AddMessage("Elastic material converting is started", TraceLogStatuses.Service);
ElasticMaterial newItem = new(source.Id);
updateStrategy.Update(newItem, source);
TraceLogger?.AddMessage("Elastic material converting has been finished succesfully", TraceLogStatuses.Service);
return newItem;
}
}
}

View File

@@ -0,0 +1,35 @@
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models;
using StructureHelperLogics.Models.Materials;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DataAccess.DTOs
{
public class FRMaterialFromDTOConvertStrategy : ConvertStrategy<FRMaterial, FRMaterialDTO>
{
private IUpdateStrategy<IFRMaterial> updateStrategy;
public FRMaterialFromDTOConvertStrategy(IUpdateStrategy<IFRMaterial> updateStrategy)
{
this.updateStrategy = updateStrategy;
}
public FRMaterialFromDTOConvertStrategy() : this(new FRUpdateStrategy())
{
}
public override FRMaterial GetNewItem(FRMaterialDTO source)
{
TraceLogger?.AddMessage("Fiber reinforcement material converting is started", TraceLogStatuses.Service);
FRMaterial newItem = new(source.MaterialType, source.Id);
updateStrategy.Update(newItem, source);
TraceLogger?.AddMessage("FiberReinforcement material converting has been finished succesfully", TraceLogStatuses.Service);
return newItem;
}
}
}

View File

@@ -6,7 +6,7 @@ using StructureHelperCommon.Models.Loggers;
namespace DataAccess.DTOs.Converters namespace DataAccess.DTOs.Converters
{ {
public class ForceActionToDTOConvertStrategy : IConvertStrategy<IForceAction, IForceAction> public class ForceActionToDTOConvertStrategy : ConvertStrategy<IForceAction, IForceAction>
{ {
private IConvertStrategy<ForceCombinationByFactorDTO, IForceCombinationByFactor> forceCombinationByFactorConvertStrategy; private IConvertStrategy<ForceCombinationByFactorDTO, IForceCombinationByFactor> forceCombinationByFactorConvertStrategy;
private IConvertStrategy<ForceCombinationListDTO, IForceCombinationList> forceCombinationListConvertStrategy; private IConvertStrategy<ForceCombinationListDTO, IForceCombinationList> forceCombinationListConvertStrategy;
@@ -26,24 +26,7 @@ namespace DataAccess.DTOs.Converters
} }
public Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; set; } public override IForceAction GetNewItem(IForceAction source)
public IShiftTraceLogger TraceLogger { get; set; }
public IForceAction Convert(IForceAction source)
{
try
{
return ProcessForceAction(source);
}
catch (Exception ex)
{
TraceLogger?.AddMessage(LoggerStrings.LogicType(this), TraceLogStatuses.Error);
TraceLogger?.AddMessage(ex.Message, TraceLogStatuses.Error);
throw;
}
}
private IForceAction ProcessForceAction(IForceAction source)
{ {
if (source is IForceCombinationByFactor forceCombinationByFactor) if (source is IForceCombinationByFactor forceCombinationByFactor)
{ {

View File

@@ -0,0 +1,66 @@
using StructureHelperCommon.Infrastructures.Exceptions;
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models;
using StructureHelperCommon.Models.Forces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DataAccess.DTOs
{
public class ForceActionsFromDTOConvertStrategy : ConvertStrategy<IForceAction, IForceAction>
{
private IConvertStrategy<ForceCombinationList, ForceCombinationListDTO> listConvertStrategy;
private IConvertStrategy<ForceCombinationByFactor, ForceCombinationByFactorDTO> factorConvertStrategy;
public ForceActionsFromDTOConvertStrategy(
IConvertStrategy<ForceCombinationList, ForceCombinationListDTO> listConvertStrategy,
IConvertStrategy<ForceCombinationByFactor, ForceCombinationByFactorDTO> factorConvertStrategy)
{
this.listConvertStrategy = listConvertStrategy;
this.factorConvertStrategy = factorConvertStrategy;
}
public ForceActionsFromDTOConvertStrategy() : this (
new ForceCombinationListFromDTOConvertStrategy(),
new ForceCombinationByFactorFromDTOConvertStrategy())
{
}
public override IForceAction GetNewItem(IForceAction source)
{
if (source is ForceCombinationByFactorDTO combination)
{
return GetForceCombination(combination);
}
if (source is ForceCombinationListDTO forceList)
{
return GetForceList(forceList);
}
string errorString = ErrorStrings.ObjectTypeIsUnknownObj(source);
TraceLogger.AddMessage(errorString, TraceLogStatuses.Error);
throw new StructureHelperException(errorString);
}
private IForceAction GetForceCombination(ForceCombinationByFactorDTO source)
{
TraceLogger?.AddMessage("Force action is combination by factors");
factorConvertStrategy.ReferenceDictionary = ReferenceDictionary;
factorConvertStrategy.TraceLogger = TraceLogger;
ForceCombinationByFactor newItem = factorConvertStrategy.Convert(source);
return newItem;
}
private IForceAction GetForceList(ForceCombinationListDTO forceList)
{
TraceLogger?.AddMessage("Force action is combination by list");
listConvertStrategy.ReferenceDictionary = ReferenceDictionary;
listConvertStrategy.TraceLogger = TraceLogger;
ForceCombinationList newItem = listConvertStrategy.Convert(forceList);
return newItem;
}
}
}

View File

@@ -0,0 +1,57 @@
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models.Forces;
using StructureHelperCommon.Models.Forces.Logics;
using StructureHelperCommon.Models.Shapes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DataAccess.DTOs
{
public class ForceCombinationByFactorFromDTOConvertStrategy : ConvertStrategy<ForceCombinationByFactor, ForceCombinationByFactorDTO>
{
private IUpdateStrategy<IForceAction> baseUpdateStrategy;
private IUpdateStrategy<IForceCombinationByFactor> updateStrategy;
private IConvertStrategy<Point2D, Point2DDTO> pointConvertStrategy;
private IConvertStrategy<ForceTuple, ForceTupleDTO> forceTupleConvertStrategy;
public ForceCombinationByFactorFromDTOConvertStrategy(
IUpdateStrategy<IForceAction> baseUpdateStrategy,
IUpdateStrategy<IForceCombinationByFactor> updateStrategy,
IConvertStrategy<Point2D, Point2DDTO> pointConvertStrategy,
IConvertStrategy<ForceTuple, ForceTupleDTO> forceTupleConvertStrategy)
{
this.baseUpdateStrategy = baseUpdateStrategy;
this.updateStrategy = updateStrategy;
this.pointConvertStrategy = pointConvertStrategy;
this.forceTupleConvertStrategy = forceTupleConvertStrategy;
}
public ForceCombinationByFactorFromDTOConvertStrategy() : this(
new ForceActionBaseUpdateStrategy(),
new ForceCombinationByFactorUpdateStrategy(),
new Point2DFromDTOConvertStrategy(),
new ForceTupleFromDTOConvertStrategy())
{
}
public override ForceCombinationByFactor GetNewItem(ForceCombinationByFactorDTO source)
{
TraceLogger.AddMessage($"Force combination by factor name = {source.Name} is starting");
ForceCombinationByFactor newItem = new(source.Id);
baseUpdateStrategy.Update(newItem, source);
updateStrategy.Update(newItem, source);
pointConvertStrategy.ReferenceDictionary = ReferenceDictionary;
pointConvertStrategy.TraceLogger = TraceLogger;
newItem.ForcePoint = pointConvertStrategy.Convert((Point2DDTO)source.ForcePoint);
forceTupleConvertStrategy.ReferenceDictionary = ReferenceDictionary;
forceTupleConvertStrategy.TraceLogger = TraceLogger;
newItem.FullSLSForces = forceTupleConvertStrategy.Convert((ForceTupleDTO)source.FullSLSForces);
TraceLogger.AddMessage($"Force combination by factor name = {newItem.Name} has been finished");
return newItem;
}
}
}

View File

@@ -0,0 +1,61 @@
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models.Forces;
using StructureHelperCommon.Models.Forces.Logics;
using StructureHelperCommon.Models.Shapes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DataAccess.DTOs
{
public class ForceCombinationListFromDTOConvertStrategy : ConvertStrategy<ForceCombinationList, ForceCombinationListDTO>
{
private IUpdateStrategy<IForceAction> baseUpdateStrategy;
private IUpdateStrategy<IForceCombinationList> updateStrategy;
private IConvertStrategy<Point2D, Point2DDTO> pointConvertStrategy;
private IConvertStrategy<DesignForceTuple, DesignForceTupleDTO> designTupleConvertStrategy;
public ForceCombinationListFromDTOConvertStrategy(
IUpdateStrategy<IForceAction> baseUpdateStrategy,
IUpdateStrategy<IForceCombinationList> updateStrategy,
IConvertStrategy<Point2D, Point2DDTO> pointConvertStrategy,
IConvertStrategy<DesignForceTuple, DesignForceTupleDTO> designTupleConvertStrategy)
{
this.baseUpdateStrategy = baseUpdateStrategy;
this.updateStrategy = updateStrategy;
this.pointConvertStrategy = pointConvertStrategy;
this.designTupleConvertStrategy = designTupleConvertStrategy;
}
public ForceCombinationListFromDTOConvertStrategy() : this(
new ForceActionBaseUpdateStrategy(),
new ForceCombinationListUpdateStrategy(),
new Point2DFromDTOConvertStrategy(),
new DesignForceTupleFromDTOConvertStrategy())
{
}
public override ForceCombinationList GetNewItem(ForceCombinationListDTO source)
{
TraceLogger?.AddMessage($"Force combination list name = {source.Name} is starting");
ForceCombinationList newItem = new(source.Id);
baseUpdateStrategy.Update(newItem, source);
updateStrategy.Update(newItem, source);
pointConvertStrategy.ReferenceDictionary = ReferenceDictionary;
pointConvertStrategy.TraceLogger = TraceLogger;
newItem.ForcePoint = pointConvertStrategy.Convert((Point2DDTO)source.ForcePoint);
designTupleConvertStrategy.ReferenceDictionary = ReferenceDictionary;
designTupleConvertStrategy.TraceLogger = TraceLogger;
foreach (var item in source.DesignForces)
{
DesignForceTuple newDesignTuple = designTupleConvertStrategy.Convert((DesignForceTupleDTO)item);
newItem.DesignForces.Add(newDesignTuple);
}
TraceLogger?.AddMessage($"Force combination list name = {newItem.Name} has been finished succesfully");
return newItem;
}
}
}

View File

@@ -0,0 +1,32 @@
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models.Forces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DataAccess.DTOs
{
public class ForceTupleFromDTOConvertStrategy : ConvertStrategy<ForceTuple, ForceTupleDTO>
{
private readonly IUpdateStrategy<IForceTuple> updateStrategy;
public ForceTupleFromDTOConvertStrategy(IUpdateStrategy<IForceTuple> updateStrategy)
{
this.updateStrategy = updateStrategy;
}
public ForceTupleFromDTOConvertStrategy() : this(new ForceTupleUpdateStrategy())
{
}
public override ForceTuple GetNewItem(ForceTupleDTO source)
{
ForceTuple newItem = new(source.Id);
updateStrategy.Update(newItem, source);
return newItem;
}
}
}

View File

@@ -10,7 +10,7 @@ using System.Threading.Tasks;
namespace DataAccess.DTOs namespace DataAccess.DTOs
{ {
public class ForceTupleToDTOConvertStrategy : IConvertStrategy<ForceTupleDTO, IForceTuple> public class ForceTupleToDTOConvertStrategy : ConvertStrategy<ForceTupleDTO, IForceTuple>
{ {
private IUpdateStrategy<IForceTuple> updateStrategy; private IUpdateStrategy<IForceTuple> updateStrategy;
@@ -27,27 +27,11 @@ namespace DataAccess.DTOs
} }
public ForceTupleDTO Convert(IForceTuple source) public override ForceTupleDTO GetNewItem(IForceTuple source)
{ {
Check(); ForceTupleDTO newItem = new() { Id = source.Id};
try updateStrategy.Update(newItem, source);
{ return newItem;
ForceTupleDTO newItem = new() { Id = source.Id};
updateStrategy.Update(newItem, source);
return newItem;
}
catch (Exception ex)
{
TraceLogger?.AddMessage(LoggerStrings.LogicType(this), TraceLogStatuses.Debug);
TraceLogger?.AddMessage(ex.Message, TraceLogStatuses.Error);
throw;
}
}
private void Check()
{
var checkLogic = new CheckConvertLogic<ForceTupleDTO, IForceTuple>(this);
checkLogic.Check();
} }
} }
} }

View File

@@ -0,0 +1,37 @@
using StructureHelper.Models.Materials;
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperLogics.Models.Materials;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//Copyright (c) 2024 Redikultsev Evgeny, Ekaterinburg, Russia
//All rights reserved.
namespace DataAccess.DTOs
{
/// <summary>
/// Creates copies of materials from source and adds them into target material list
/// </summary>
public class HasMaterialFromDTOUpdateStrategy : IUpdateStrategy<IHasHeadMaterials>
{
private readonly IConvertStrategy<IHeadMaterial, IHeadMaterial> convertStrategy;
public HasMaterialFromDTOUpdateStrategy(IConvertStrategy<IHeadMaterial, IHeadMaterial> convertStrategy)
{
this.convertStrategy = convertStrategy;
}
public void Update(IHasHeadMaterials targetObject, IHasHeadMaterials sourceObject)
{
targetObject.HeadMaterials.Clear();
foreach (var item in sourceObject.HeadMaterials)
{
var newItem = convertStrategy.Convert(item);
targetObject.HeadMaterials.Add(newItem);
}
}
}
}

View File

@@ -0,0 +1,58 @@
using DataAccess.DTOs.Converters;
using StructureHelper.Models.Materials;
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models;
using StructureHelperCommon.Models.Loggers;
using StructureHelperLogics.Models.CrossSections;
using StructureHelperLogics.Models.Materials;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DataAccess.DTOs
{
public class HeadMaterialFromDTOConvertStrategy : ConvertStrategy<IHeadMaterial, IHeadMaterial>
{
private IUpdateStrategy<IHeadMaterial> updateStrategy;
private IConvertStrategy<IHelperMaterial, IHelperMaterial> helperMaterialConvertStrategy;
public HeadMaterialFromDTOConvertStrategy(
IUpdateStrategy<IHeadMaterial> updateStrategy,
IConvertStrategy<IHelperMaterial, IHelperMaterial> helperMaterialConvertStrategy)
{
this.updateStrategy = updateStrategy;
this.helperMaterialConvertStrategy = helperMaterialConvertStrategy;
}
public HeadMaterialFromDTOConvertStrategy() : this (
new HeadMaterialBaseUpdateStrategy(),
new HelperMaterialFromDTOConvertStrategy())
{
}
public override IHeadMaterial GetNewItem(IHeadMaterial source)
{
TraceLogger?.AddMessage("Head material converting is started", TraceLogStatuses.Service);
HeadMaterial newItem = new(source.Id);
updateStrategy.Update(newItem, source);
IHelperMaterial helperMaterial = GetHelperMaterial(source.HelperMaterial);
newItem.HelperMaterial = helperMaterial;
//GlobalRepository
TraceLogger?.AddMessage($"Head material Name = {newItem.Name} converting has been finished succesfully", TraceLogStatuses.Service);
return newItem;
}
private IHelperMaterial GetHelperMaterial(IHelperMaterial source)
{
TraceLogger?.AddMessage("Helper material converting is started", TraceLogStatuses.Service);
helperMaterialConvertStrategy.ReferenceDictionary = ReferenceDictionary;
helperMaterialConvertStrategy.TraceLogger = TraceLogger;
IHelperMaterial newItem = helperMaterialConvertStrategy.Convert(source);
TraceLogger?.AddMessage($"Object of type <<{newItem.GetType()}>> was obtained", TraceLogStatuses.Service);
return newItem;
}
}
}

View File

@@ -8,12 +8,13 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace DataAccess.DTOs.Converters namespace DataAccess.DTOs
{ {
public class HelperMaterialDTOSafetyFactorUpdateStrategy : IUpdateStrategy<IHelperMaterial> public class HelperMaterialDTOSafetyFactorUpdateStrategy : IUpdateStrategy<IHelperMaterial>
{ {
private IUpdateStrategy<IMaterialSafetyFactor> safetyFactorUpdateStrategy; private IUpdateStrategy<IMaterialSafetyFactor> safetyFactorUpdateStrategy;
private IUpdateStrategy<IMaterialPartialFactor> partialFactorUpdateStrategy; private IUpdateStrategy<IMaterialPartialFactor> partialFactorUpdateStrategy;
private IMaterialSafetyFactorDTOLogic factorDTOLogic;
public HelperMaterialDTOSafetyFactorUpdateStrategy( public HelperMaterialDTOSafetyFactorUpdateStrategy(
IUpdateStrategy<IMaterialSafetyFactor> safetyFactorUpdateStrategy, IUpdateStrategy<IMaterialSafetyFactor> safetyFactorUpdateStrategy,
@@ -23,11 +24,11 @@ namespace DataAccess.DTOs.Converters
this.partialFactorUpdateStrategy = partialFactorUpdateStrategy; this.partialFactorUpdateStrategy = partialFactorUpdateStrategy;
} }
public HelperMaterialDTOSafetyFactorUpdateStrategy() : this( public HelperMaterialDTOSafetyFactorUpdateStrategy(IMaterialSafetyFactorDTOLogic factorDTOLogic) : this(
new MaterialSafetyFactorUpdateStrategy(), new MaterialSafetyFactorBaseUpdateStrategy(),
new MaterialPartialFactorUpdateStrategy()) new MaterialPartialFactorUpdateStrategy())
{ {
this.factorDTOLogic = factorDTOLogic;
} }
public void Update(IHelperMaterial targetObject, IHelperMaterial sourceObject) public void Update(IHelperMaterial targetObject, IHelperMaterial sourceObject)
@@ -40,35 +41,29 @@ namespace DataAccess.DTOs.Converters
targetObject.SafetyFactors.Clear(); targetObject.SafetyFactors.Clear();
foreach (var safetyFactor in sourceObject.SafetyFactors) foreach (var safetyFactor in sourceObject.SafetyFactors)
{ {
MaterialSafetyFactorDTO newSafetyFactor = GetNewSafetyFactorByOld(safetyFactor); IMaterialSafetyFactor newSafetyFactor = GetNewSafetyFactorByOld(safetyFactor);
targetObject.SafetyFactors.Add(newSafetyFactor); targetObject.SafetyFactors.Add(newSafetyFactor);
} }
} }
} }
private MaterialSafetyFactorDTO GetNewSafetyFactorByOld(IMaterialSafetyFactor safetyFactor) private IMaterialSafetyFactor GetNewSafetyFactorByOld(IMaterialSafetyFactor safetyFactor)
{ {
MaterialSafetyFactorDTO newSafetyFactor = new() IMaterialSafetyFactor newSafetyFactor = factorDTOLogic.GetNewSafetyFactorByOld(safetyFactor);
{
Id = safetyFactor.Id
};
safetyFactorUpdateStrategy.Update(newSafetyFactor, safetyFactor); safetyFactorUpdateStrategy.Update(newSafetyFactor, safetyFactor);
newSafetyFactor.PartialFactors.Clear(); newSafetyFactor.PartialFactors.Clear();
foreach (var partialFactor in safetyFactor.PartialFactors) foreach (var partialFactor in safetyFactor.PartialFactors)
{ {
MaterialPartialFactorDTO newPartialFactor = GetNewPartialFactorByOld(partialFactor); IMaterialPartialFactor newPartialFactor = GetNewPartialFactorByOld(partialFactor);
newSafetyFactor.PartialFactors.Add(newPartialFactor); newSafetyFactor.PartialFactors.Add(newPartialFactor);
} }
return newSafetyFactor; return newSafetyFactor;
} }
private MaterialPartialFactorDTO GetNewPartialFactorByOld(IMaterialPartialFactor partialFactor) private IMaterialPartialFactor GetNewPartialFactorByOld(IMaterialPartialFactor partialFactor)
{ {
MaterialPartialFactorDTO newPartialFactor = new() IMaterialPartialFactor newPartialFactor = factorDTOLogic.GetNewPartialFactorByOld(partialFactor);
{
Id = partialFactor.Id
};
partialFactorUpdateStrategy.Update(newPartialFactor, partialFactor); partialFactorUpdateStrategy.Update(newPartialFactor, partialFactor);
return newPartialFactor; return newPartialFactor;
} }

View File

@@ -0,0 +1,113 @@
using DataAccess.DTOs.Converters;
using StructureHelper.Models.Materials;
using StructureHelperCommon.Infrastructures.Exceptions;
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models;
using StructureHelperLogics.Models.Materials;
using System;
using System.CodeDom;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DataAccess.DTOs
{
public class HelperMaterialFromDTOConvertStrategy : ConvertStrategy<IHelperMaterial, IHelperMaterial>
{
const string MaterialIs = "Material type is: ";
private IConvertStrategy<ConcreteLibMaterial, ConcreteLibMaterialDTO> concreteConvertStrategy;
private IConvertStrategy<ReinforcementLibMaterial, ReinforcementLibMaterialDTO> reinforcementConvertStrategy;
private IConvertStrategy<ElasticMaterial, ElasticMaterialDTO> elasticConvertStrategy;
private IConvertStrategy<FRMaterial, FRMaterialDTO> frConvertStrategy;
private IUpdateStrategy<IHelperMaterial> safetyFactorUpdateStrategy = new HelperMaterialDTOSafetyFactorUpdateStrategy(new MaterialSafetyFactorsFromDTOLogic());
public HelperMaterialFromDTOConvertStrategy() : this(
new ConcreteLibMaterialFromDTOConvertStrategy(),
new ReinforcementLibMaterialFromDTOConvertStrategy(),
new ElasticMaterialFromDTOConvertStrategy(),
new FRMaterialFromDTOConvertStrategy()
)
{
}
public HelperMaterialFromDTOConvertStrategy(
IConvertStrategy<ConcreteLibMaterial, ConcreteLibMaterialDTO> concreteConvertStrategy,
IConvertStrategy<ReinforcementLibMaterial, ReinforcementLibMaterialDTO> reinforcementConvertStrategy,
IConvertStrategy<ElasticMaterial, ElasticMaterialDTO> elasticConvertStrategy,
IConvertStrategy<FRMaterial, FRMaterialDTO> frConvertStrategy)
{
this.concreteConvertStrategy = concreteConvertStrategy;
this.reinforcementConvertStrategy = reinforcementConvertStrategy;
this.elasticConvertStrategy = elasticConvertStrategy;
this.frConvertStrategy = frConvertStrategy;
}
public override IHelperMaterial GetNewItem(IHelperMaterial source)
{
if (source is ConcreteLibMaterialDTO concrete)
{
return GetConcreteMaterial(concrete);
}
else if (source is ReinforcementLibMaterialDTO reinforcement)
{
return GetReinforcementMaterial(reinforcement);
}
else if (source is FRMaterialDTO frMaterial)
{
return GetFRMaterial(frMaterial);
}
else if (source is ElasticMaterialDTO elastic)
{
return GetElasticMaterial(elastic);
}
else
{
string errorString = ErrorStrings.ObjectTypeIsUnknownObj(source) + ": helper material type";
TraceLogger?.AddMessage(errorString, TraceLogStatuses.Error);
throw new StructureHelperException(errorString);
}
}
private IHelperMaterial GetElasticMaterial(ElasticMaterialDTO source)
{
TraceLogger?.AddMessage(MaterialIs + "Elastic material", TraceLogStatuses.Service);
reinforcementConvertStrategy.ReferenceDictionary = ReferenceDictionary;
reinforcementConvertStrategy.TraceLogger = TraceLogger;
var newItem = elasticConvertStrategy.Convert(source);
safetyFactorUpdateStrategy.Update(newItem, source);
return newItem;
}
private IHelperMaterial GetFRMaterial(FRMaterialDTO source)
{
TraceLogger?.AddMessage(MaterialIs + "Fiber reinforcement material", TraceLogStatuses.Service);
reinforcementConvertStrategy.ReferenceDictionary = ReferenceDictionary;
reinforcementConvertStrategy.TraceLogger = TraceLogger;
var newItem = frConvertStrategy.Convert(source);
safetyFactorUpdateStrategy.Update(newItem, source);
return newItem;
}
private IHelperMaterial GetReinforcementMaterial(ReinforcementLibMaterialDTO source)
{
TraceLogger?.AddMessage(MaterialIs + "Reinforcement library material", TraceLogStatuses.Service);
reinforcementConvertStrategy.ReferenceDictionary = ReferenceDictionary;
reinforcementConvertStrategy.TraceLogger = TraceLogger;
var newItem = reinforcementConvertStrategy.Convert(source);
safetyFactorUpdateStrategy.Update(newItem, source);
return newItem;
}
private IHelperMaterial GetConcreteMaterial(ConcreteLibMaterialDTO source)
{
TraceLogger?.AddMessage(MaterialIs + "Concrete library material", TraceLogStatuses.Service);
concreteConvertStrategy.ReferenceDictionary = ReferenceDictionary;
concreteConvertStrategy.TraceLogger = TraceLogger;
var newItem = concreteConvertStrategy.Convert(source);
safetyFactorUpdateStrategy.Update(newItem, source);
return newItem;
}
}
}

View File

@@ -20,7 +20,7 @@ namespace DataAccess.DTOs
private LibMaterialToDTOConvertStrategy<ReinforcementLibMaterialDTO, IReinforcementLibMaterial> reinforcementConvertStrategy; private LibMaterialToDTOConvertStrategy<ReinforcementLibMaterialDTO, IReinforcementLibMaterial> reinforcementConvertStrategy;
private IConvertStrategy<ElasticMaterialDTO, IElasticMaterial> elasticConvertStrategy; private IConvertStrategy<ElasticMaterialDTO, IElasticMaterial> elasticConvertStrategy;
private IConvertStrategy<FRMaterialDTO, IFRMaterial> frMaterialConvertStrategy; private IConvertStrategy<FRMaterialDTO, IFRMaterial> frMaterialConvertStrategy;
private IUpdateStrategy<IHelperMaterial> safetyFactorUpdateStrategy = new HelperMaterialDTOSafetyFactorUpdateStrategy(); private IUpdateStrategy<IHelperMaterial> safetyFactorUpdateStrategy = new HelperMaterialDTOSafetyFactorUpdateStrategy(new MaterialSafetyFactorToDTOLogic());
public Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; set; } public Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; set; }
public IShiftTraceLogger TraceLogger { get; set; } public IShiftTraceLogger TraceLogger { get; set; }

View File

@@ -0,0 +1,10 @@
using StructureHelperCommon.Models.Materials.Libraries;
namespace DataAccess.DTOs
{
public interface IMaterialSafetyFactorDTOLogic
{
IMaterialPartialFactor GetNewPartialFactorByOld(IMaterialPartialFactor partialFactor);
IMaterialSafetyFactor GetNewSafetyFactorByOld(IMaterialSafetyFactor safetyFactor);
}
}

View File

@@ -0,0 +1,30 @@
using StructureHelperCommon.Models.Materials.Libraries;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DataAccess.DTOs
{
public class MaterialSafetyFactorToDTOLogic : IMaterialSafetyFactorDTOLogic
{
public IMaterialSafetyFactor GetNewSafetyFactorByOld(IMaterialSafetyFactor safetyFactor)
{
MaterialSafetyFactorDTO newSafetyFactor = new()
{
Id = safetyFactor.Id
};
return newSafetyFactor;
}
public IMaterialPartialFactor GetNewPartialFactorByOld(IMaterialPartialFactor partialFactor)
{
MaterialPartialFactorDTO newPartialFactor = new()
{
Id = partialFactor.Id
};
return newPartialFactor;
}
}
}

View File

@@ -0,0 +1,24 @@
using StructureHelperCommon.Models.Materials.Libraries;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DataAccess.DTOs
{
public class MaterialSafetyFactorsFromDTOLogic : IMaterialSafetyFactorDTOLogic
{
public IMaterialSafetyFactor GetNewSafetyFactorByOld(IMaterialSafetyFactor safetyFactor)
{
MaterialSafetyFactor newItem = new(safetyFactor.Id);
return newItem;
}
public IMaterialPartialFactor GetNewPartialFactorByOld(IMaterialPartialFactor partialFactor)
{
MaterialPartialFactor newItem = new(partialFactor.Id);
return newItem;
}
}
}

View File

@@ -9,13 +9,13 @@ using System.Threading.Tasks;
namespace DataAccess.DTOs namespace DataAccess.DTOs
{ {
public class MaterialSafetyFactorToDTOConvertStrategy : IConvertStrategy<MaterialSafetyFactorDTO, IMaterialSafetyFactor> public class MaterialSafetyFactorsToDTOConvertStrategy : IConvertStrategy<MaterialSafetyFactorDTO, IMaterialSafetyFactor>
{ {
private IUpdateStrategy<IMaterialSafetyFactor> updateStrategy; private IUpdateStrategy<IMaterialSafetyFactor> updateStrategy;
public Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; set; } public Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; set; }
public IShiftTraceLogger TraceLogger { get; set; } public IShiftTraceLogger TraceLogger { get; set; }
public MaterialSafetyFactorToDTOConvertStrategy(IUpdateStrategy<IMaterialSafetyFactor> updateStrategy) public MaterialSafetyFactorsToDTOConvertStrategy(IUpdateStrategy<IMaterialSafetyFactor> updateStrategy)
{ {
this.updateStrategy = updateStrategy; this.updateStrategy = updateStrategy;
} }

View File

@@ -0,0 +1,34 @@
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models.Shapes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DataAccess.DTOs
{
public class Point2DFromDTOConvertStrategy : ConvertStrategy<Point2D, Point2DDTO>
{
private IUpdateStrategy<IPoint2D> updateStrategy;
public Point2DFromDTOConvertStrategy(IUpdateStrategy<IPoint2D> updateStrategy)
{
this.updateStrategy = updateStrategy;
}
public Point2DFromDTOConvertStrategy() : this (new Point2DUpdateStrategy())
{
}
public override Point2D GetNewItem(Point2DDTO source)
{
TraceLogger?.AddMessage("Point 2D converting is started");
Point2D newItem = new(source.Id);
updateStrategy.Update(newItem, source);
TraceLogger?.AddMessage("Point 2D converting has been finished");
return newItem;
}
}
}

View File

@@ -48,18 +48,28 @@ namespace DataAccess.DTOs
private Project GetProject(ProjectDTO source) private Project GetProject(ProjectDTO source)
{ {
TraceLogger?.AddMessage("Converting of project is started", TraceLogStatuses.Service);
Project newItem = new(); Project newItem = new();
updateStrategy.Update(newItem, source); updateStrategy.Update(newItem, source);
visualAnalysisConvertStrategy.ReferenceDictionary = ReferenceDictionary; visualAnalysisConvertStrategy.ReferenceDictionary = ReferenceDictionary;
visualAnalysisConvertStrategy.TraceLogger = TraceLogger; visualAnalysisConvertStrategy.TraceLogger = TraceLogger;
var convertLogic = new DictionaryConvertStrategy<IVisualAnalysis, IVisualAnalysis>(this, visualAnalysisConvertStrategy); var convertLogic = new DictionaryConvertStrategy<IVisualAnalysis, IVisualAnalysis>(this, visualAnalysisConvertStrategy);
newItem.VisualAnalyses.Clear(); newItem.VisualAnalyses.Clear();
TraceLogger?.AddMessage($"Source project has {source.VisualAnalyses.Count()} analyses", TraceLogStatuses.Service);
foreach (var item in source.VisualAnalyses) foreach (var item in source.VisualAnalyses)
{ {
var visualAnalysis = convertLogic.Convert(item); var visualAnalysis = convertLogic.Convert(item);
newItem.VisualAnalyses.Add(visualAnalysis); newItem.VisualAnalyses.Add(visualAnalysis);
} }
TraceLogger?.AddMessage("Converting project has completed succesfully", TraceLogStatuses.Info); if (newItem.VisualAnalyses.Any())
{
TraceLogger?.AddMessage($"Totaly {newItem.VisualAnalyses.Count()} were(was) obtained", TraceLogStatuses.Service);
}
else
{
TraceLogger?.AddMessage($"Project does not have any analyses", TraceLogStatuses.Warning);
}
TraceLogger?.AddMessage("Converting of project has completed succesfully", TraceLogStatuses.Service);
return newItem; return newItem;
} }

View File

@@ -0,0 +1,35 @@
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models;
using StructureHelperLogics.Models.Materials;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DataAccess.DTOs
{
public class ReinforcementLibMaterialFromDTOConvertStrategy : ConvertStrategy<ReinforcementLibMaterial, ReinforcementLibMaterialDTO>
{
private readonly IUpdateStrategy<IReinforcementLibMaterial> updateStrategy;
public ReinforcementLibMaterialFromDTOConvertStrategy(IUpdateStrategy<IReinforcementLibMaterial> updateStrategy)
{
this.updateStrategy = updateStrategy;
}
public ReinforcementLibMaterialFromDTOConvertStrategy() : this(new ReinforcementLibUpdateStrategy())
{
}
public override ReinforcementLibMaterial GetNewItem(ReinforcementLibMaterialDTO source)
{
TraceLogger?.AddMessage("Reinforcement library material converting is started", TraceLogStatuses.Service);
ReinforcementLibMaterial newItem = new(source.Id);
updateStrategy.Update(newItem, source);
TraceLogger?.AddMessage("Reinforcement library material converting has been finished succesfully", TraceLogStatuses.Service);
return newItem;
}
}
}

View File

@@ -0,0 +1,77 @@
using StructureHelperCommon.Infrastructures.Exceptions;
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models;
using StructureHelperCommon.Models.Loggers;
using StructureHelperLogics.Models.CrossSections;
namespace DataAccess.DTOs
{
public class VersionItemFromDTOConvertStrategy : IConvertStrategy<ISaveable, ISaveable>
{
private const string AnalysisIs = "Analysis type is";
private IConvertStrategy<ICrossSection, ICrossSection> crossSectionConvertStrategy;
public VersionItemFromDTOConvertStrategy(IConvertStrategy<ICrossSection, ICrossSection> crossSectionConvertStrategy)
{
this.crossSectionConvertStrategy = crossSectionConvertStrategy;
}
public VersionItemFromDTOConvertStrategy() : this (new CrossSectionFromDTOConvertStrategy())
{
}
public Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; set; }
public IShiftTraceLogger TraceLogger { get; set; }
public ISaveable Convert(ISaveable source)
{
try
{
Check();
return GetNewAnalysis(source);
}
catch (Exception ex)
{
TraceLogger?.AddMessage(LoggerStrings.LogicType(this), TraceLogStatuses.Error);
TraceLogger?.AddMessage(ex.Message, TraceLogStatuses.Error);
throw;
}
}
private ISaveable GetNewAnalysis(ISaveable source)
{
ISaveable newItem;
if (source is ICrossSection crossSection)
{
newItem = ProcessCrossSection(crossSection);
}
else
{
string errorString = ErrorStrings.ObjectTypeIsUnknownObj(source);
TraceLogger?.AddMessage(errorString, TraceLogStatuses.Error);
throw new StructureHelperException(errorString);
}
TraceLogger?.AddMessage($"Object of type <<{newItem.GetType()}>> was obtained", TraceLogStatuses.Service);
return newItem;
}
private ICrossSection ProcessCrossSection(ICrossSection source)
{
TraceLogger?.AddMessage(AnalysisIs + " Cross-Section", TraceLogStatuses.Service);
TraceLogger?.AddMessage("Cross-Section converting is started", TraceLogStatuses.Service);
crossSectionConvertStrategy.ReferenceDictionary = ReferenceDictionary;
crossSectionConvertStrategy.TraceLogger = TraceLogger;
var convertLogic = new DictionaryConvertStrategy<ICrossSection, ICrossSection>(this, crossSectionConvertStrategy);
ICrossSection newItem = convertLogic.Convert(source);
TraceLogger?.AddMessage("Cross-Section converting has been finished succesfully", TraceLogStatuses.Service);
return newItem;
}
private void Check()
{
var checkLogic = new CheckConvertLogic<ISaveable, ISaveable>(this);
checkLogic.Check();
}
}
}

View File

@@ -1,6 +1,7 @@
using StructureHelperCommon.Infrastructures.Exceptions; using StructureHelperCommon.Infrastructures.Exceptions;
using StructureHelperCommon.Infrastructures.Interfaces; using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models; using StructureHelperCommon.Models;
using StructureHelperCommon.Models.Loggers;
using StructureHelperLogics.Models.CrossSections; using StructureHelperLogics.Models.CrossSections;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@@ -13,7 +14,7 @@ namespace DataAccess.DTOs
{ {
public class VersionItemToDTOConvertStrategy : IConvertStrategy<ISaveable, ISaveable> public class VersionItemToDTOConvertStrategy : IConvertStrategy<ISaveable, ISaveable>
{ {
private const string Message = "Analysis type is"; private const string AnalysisIs = "Analysis type is";
private IConvertStrategy<CrossSectionDTO, ICrossSection> crossSectionConvertStrategy = new CrossSectionToDTOConvertStrategy(); private IConvertStrategy<CrossSectionDTO, ICrossSection> crossSectionConvertStrategy = new CrossSectionToDTOConvertStrategy();
public Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; set; } public Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; set; }
public IShiftTraceLogger TraceLogger { get; set; } public IShiftTraceLogger TraceLogger { get; set; }
@@ -21,11 +22,25 @@ namespace DataAccess.DTOs
public ISaveable Convert(ISaveable source) public ISaveable Convert(ISaveable source)
{ {
Check(); try
ISaveable saveable; {
Check();
return GetNewAnalysis(source);
}
catch (Exception ex)
{
TraceLogger?.AddMessage(LoggerStrings.LogicType(this), TraceLogStatuses.Error);
TraceLogger?.AddMessage(ex.Message, TraceLogStatuses.Error);
throw;
}
}
private ISaveable GetNewAnalysis(ISaveable source)
{
ISaveable newItem;
if (source is ICrossSection crossSection) if (source is ICrossSection crossSection)
{ {
saveable = ProcessCrossSection(crossSection); newItem = ProcessCrossSection(crossSection);
} }
else else
{ {
@@ -33,12 +48,12 @@ namespace DataAccess.DTOs
TraceLogger?.AddMessage(errorString, TraceLogStatuses.Error); TraceLogger?.AddMessage(errorString, TraceLogStatuses.Error);
throw new StructureHelperException(errorString); throw new StructureHelperException(errorString);
} }
return saveable; return newItem;
} }
private ISaveable ProcessCrossSection(ICrossSection crossSection) private ISaveable ProcessCrossSection(ICrossSection crossSection)
{ {
TraceLogger?.AddMessage(Message + " Cross-Section Ndm Analysis", TraceLogStatuses.Debug); TraceLogger?.AddMessage(AnalysisIs + " Cross-Section Ndm Analysis", TraceLogStatuses.Debug);
ISaveable saveable; ISaveable saveable;
crossSectionConvertStrategy.ReferenceDictionary = ReferenceDictionary; crossSectionConvertStrategy.ReferenceDictionary = ReferenceDictionary;
crossSectionConvertStrategy.TraceLogger = TraceLogger; crossSectionConvertStrategy.TraceLogger = TraceLogger;
@@ -54,9 +69,7 @@ namespace DataAccess.DTOs
private void Check() private void Check()
{ {
var checkLogic = new CheckConvertLogic<ISaveable, ISaveable>(); var checkLogic = new CheckConvertLogic<ISaveable, ISaveable>(this);
checkLogic.ConvertStrategy = this;
checkLogic.TraceLogger = TraceLogger;
checkLogic.Check(); checkLogic.Check();
} }
} }

View File

@@ -0,0 +1,72 @@
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models;
using StructureHelperCommon.Models.Analyses;
using StructureHelperCommon.Models.Loggers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DataAccess.DTOs
{
public class VersionProcessorFromDTOConvertStrategy : IConvertStrategy<IVersionProcessor, IVersionProcessor>
{
private IConvertStrategy<IDateVersion, IDateVersion> dateVersionConvertStrategy;
private ICheckConvertLogic<IVersionProcessor, IVersionProcessor> checkLogic;
public VersionProcessorFromDTOConvertStrategy(
IConvertStrategy<IDateVersion, IDateVersion> dateVersionConvertStrategy)
{
this.dateVersionConvertStrategy = dateVersionConvertStrategy;
this.checkLogic = checkLogic;
}
public VersionProcessorFromDTOConvertStrategy() : this(new DateVersionFromDTOConvertStrategy())
{
}
public Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; set; }
public IShiftTraceLogger TraceLogger { get; set; }
public IVersionProcessor Convert(IVersionProcessor source)
{
try
{
Check();
IVersionProcessor versionProcessor = GetVersionProcessor(source);
return versionProcessor;
}
catch (Exception ex)
{
TraceLogger?.AddMessage(LoggerStrings.LogicType(this), TraceLogStatuses.Error);
TraceLogger?.AddMessage(ex.Message, TraceLogStatuses.Error);
throw;
}
}
private IVersionProcessor GetVersionProcessor(IVersionProcessor source)
{
TraceLogger?.AddMessage("Version processor converting is started", TraceLogStatuses.Debug);
IVersionProcessor newItem = new VersionProcessor(source.Id);
TraceLogger?.AddMessage($"Source version processor has {source.Versions.Count} version(s)", TraceLogStatuses.Service);
dateVersionConvertStrategy.ReferenceDictionary = ReferenceDictionary;
dateVersionConvertStrategy.TraceLogger = TraceLogger;
foreach (var item in source.Versions)
{
IDateVersion dateVersion = dateVersionConvertStrategy.Convert(item);
newItem.Versions.Add(dateVersion);
}
TraceLogger?.AddMessage($"Totaly {newItem.Versions.Count} version(s) was(were) obtained", TraceLogStatuses.Service);
TraceLogger?.AddMessage("Version processor has been converted succesfully", TraceLogStatuses.Service);
return newItem;
}
private void Check()
{
var checkLogic = new CheckConvertLogic<IVersionProcessor, IVersionProcessor>(this);
checkLogic.Check();
}
}
}

View File

@@ -15,6 +15,8 @@ namespace DataAccess.DTOs
{ {
[JsonProperty("Id")] [JsonProperty("Id")]
public Guid Id { get; set; } public Guid Id { get; set; }
[JsonProperty("MaterialType")]
public MaterialTypes MaterialType { get; set; } = MaterialTypes.CarbonFiber;
[JsonProperty("ULSConcreteStrength")] [JsonProperty("ULSConcreteStrength")]
public double ULSConcreteStrength { get; set; } public double ULSConcreteStrength { get; set; }
[JsonProperty("SunThickness")] [JsonProperty("SunThickness")]

View File

@@ -1,36 +0,0 @@
using StructureHelper.Models.Materials;
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models.Forces;
using StructureHelperCommon.Models.Repositories;
using StructureHelperLogics.Models.Materials;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StructureHelper.Services.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

@@ -86,6 +86,7 @@
<Folder Include="Documentation\Manuals\" /> <Folder Include="Documentation\Manuals\" />
<Folder Include="Infrastructure\UI\DataContexts\Logics\" /> <Folder Include="Infrastructure\UI\DataContexts\Logics\" />
<Folder Include="Resources\" /> <Folder Include="Resources\" />
<Folder Include="Services\Settings\" />
<Folder Include="Windows\UserControls\MultiplyTuples\" /> <Folder Include="Windows\UserControls\MultiplyTuples\" />
</ItemGroup> </ItemGroup>

View File

@@ -2,7 +2,6 @@
using StructureHelper.Infrastructure; using StructureHelper.Infrastructure;
using StructureHelper.Infrastructure.UI.DataContexts; using StructureHelper.Infrastructure.UI.DataContexts;
using StructureHelper.Models.Materials; using StructureHelper.Models.Materials;
using StructureHelper.Services.Settings;
using StructureHelper.Windows.PrimitiveTemplates.RCs.Beams; using StructureHelper.Windows.PrimitiveTemplates.RCs.Beams;
using StructureHelper.Windows.PrimitiveTemplates.RCs.RectangleBeam; using StructureHelper.Windows.PrimitiveTemplates.RCs.RectangleBeam;
using StructureHelper.Windows.ViewModels; using StructureHelper.Windows.ViewModels;
@@ -15,7 +14,6 @@ using StructureHelperLogics.Models.CrossSections;
using StructureHelperLogics.Models.Templates.CrossSections.RCs; using StructureHelperLogics.Models.Templates.CrossSections.RCs;
using StructureHelperLogics.Models.Templates.RCs; using StructureHelperLogics.Models.Templates.RCs;
using StructureHelperLogics.Services.NdmPrimitives; using StructureHelperLogics.Services.NdmPrimitives;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
@@ -290,14 +288,14 @@ namespace StructureHelper.Windows.MainWindow
CalculatorsLogic.AddItems(newRepository.Calculators); CalculatorsLogic.AddItems(newRepository.Calculators);
var primitives = PrimitiveOperations.ConvertNdmPrimitivesToPrimitiveBase(newRepository.Primitives); var primitives = PrimitiveOperations.ConvertNdmPrimitivesToPrimitiveBase(newRepository.Primitives);
PrimitiveLogic.Refresh(); PrimitiveLogic.Refresh();
foreach (var item in newRepository.HeadMaterials) //foreach (var item in newRepository.HeadMaterials)
{ //{
GlobalRepository.Materials.Create(item); // GlobalRepository.Materials.Create(item);
} //}
foreach (var item in newRepository.ForceActions) //foreach (var item in newRepository.ForceActions)
{ //{
GlobalRepository.Actions.Create(item); // GlobalRepository.Actions.Create(item);
} //}
return primitives; return primitives;
} }

View File

@@ -1,5 +1,4 @@
using StructureHelper.Infrastructure.Enums; using StructureHelper.Infrastructure.Enums;
using StructureHelper.Services.Settings;
using StructureHelper.Windows.Forces; using StructureHelper.Windows.Forces;
using StructureHelperCommon.Infrastructures.Exceptions; using StructureHelperCommon.Infrastructures.Exceptions;
using StructureHelperCommon.Infrastructures.Interfaces; using StructureHelperCommon.Infrastructures.Interfaces;
@@ -31,7 +30,7 @@ namespace StructureHelper.Windows.ViewModels.Forces
NewItem = new ForceCombinationByFactor() { Name = "New Factored Combination" }; NewItem = new ForceCombinationByFactor() { Name = "New Factored Combination" };
} }
else throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknown + $": Actual type: {nameof(paramType)}"); else throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknown + $": Actual type: {nameof(paramType)}");
GlobalRepository.Actions.Create(NewItem); //GlobalRepository.Actions.Create(NewItem);
base.AddMethod(parameter); base.AddMethod(parameter);
} }
} }
@@ -42,7 +41,7 @@ namespace StructureHelper.Windows.ViewModels.Forces
if (dialogResult == DialogResult.Yes) if (dialogResult == DialogResult.Yes)
{ {
if (DeleteAction() != true) return; if (DeleteAction() != true) return;
GlobalRepository.Actions.Delete(SelectedItem.Id); //GlobalRepository.Actions.Delete(SelectedItem.Id);
base.DeleteMethod(parameter); base.DeleteMethod(parameter);
} }
} }
@@ -51,7 +50,7 @@ namespace StructureHelper.Windows.ViewModels.Forces
{ {
NewItem = SelectedItem.Clone() as IForceAction; NewItem = SelectedItem.Clone() as IForceAction;
NewItem.Name = $"{NewItem.Name} copy"; NewItem.Name = $"{NewItem.Name} copy";
GlobalRepository.Actions.Create(NewItem); //GlobalRepository.Actions.Create(NewItem);
Collection.Add(NewItem); Collection.Add(NewItem);
Items.Add(NewItem); Items.Add(NewItem);
SelectedItem = NewItem; SelectedItem = NewItem;
@@ -59,7 +58,8 @@ namespace StructureHelper.Windows.ViewModels.Forces
public override void EditMethod(object parameter) public override void EditMethod(object parameter)
{ {
var copyObject = GlobalRepository.Actions.GetById(SelectedItem.Id).Clone() as IAction; //var copyObject = GlobalRepository.Actions.GetById(SelectedItem.Id).Clone() as IAction;
var copyObject = SelectedItem.Clone() as IAction;
System.Windows.Window wnd; System.Windows.Window wnd;
if (SelectedItem is IForceCombinationList) if (SelectedItem is IForceCombinationList)
{ {
@@ -75,7 +75,7 @@ namespace StructureHelper.Windows.ViewModels.Forces
wnd.ShowDialog(); wnd.ShowDialog();
if (wnd.DialogResult == true) if (wnd.DialogResult == true)
{ {
GlobalRepository.Actions.Update(SelectedItem); //GlobalRepository.Actions.Update(SelectedItem);
} }
else else
{ {

View File

@@ -1,7 +1,6 @@
using StructureHelper.Infrastructure; using StructureHelper.Infrastructure;
using StructureHelper.Infrastructure.Enums; using StructureHelper.Infrastructure.Enums;
using StructureHelper.Models.Materials; using StructureHelper.Models.Materials;
using StructureHelper.Services.Settings;
using StructureHelper.Windows.MainWindow.Materials; using StructureHelper.Windows.MainWindow.Materials;
using StructureHelperCommon.Infrastructures.Exceptions; using StructureHelperCommon.Infrastructures.Exceptions;
using StructureHelperLogics.Models.CrossSections; using StructureHelperLogics.Models.CrossSections;
@@ -42,7 +41,7 @@ namespace StructureHelper.Windows.ViewModels.Materials
else if (parameterType == MaterialType.CarbonFiber) { AddCarbonFiber(); } else if (parameterType == MaterialType.CarbonFiber) { AddCarbonFiber(); }
else if (parameterType == MaterialType.GlassFiber) { AddGlassFiber(); } else if (parameterType == MaterialType.GlassFiber) { AddGlassFiber(); }
else throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknown + $". Expected: {typeof(MaterialType)}, Actual type: {nameof(parameterType)}"); else throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknown + $". Expected: {typeof(MaterialType)}, Actual type: {nameof(parameterType)}");
GlobalRepository.Materials.Create(NewItem); //GlobalRepository.Materials.Create(NewItem);
base.AddMethod(parameter); base.AddMethod(parameter);
} }
public override void DeleteMethod(object parameter) public override void DeleteMethod(object parameter)
@@ -58,18 +57,19 @@ namespace StructureHelper.Windows.ViewModels.Materials
var dialogResult = MessageBox.Show("Delete material?", "Please, confirm deleting", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); var dialogResult = MessageBox.Show("Delete material?", "Please, confirm deleting", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (dialogResult == DialogResult.Yes) if (dialogResult == DialogResult.Yes)
{ {
GlobalRepository.Materials.Delete(SelectedItem.Id); //GlobalRepository.Materials.Delete(SelectedItem.Id);
base.DeleteMethod(parameter); base.DeleteMethod(parameter);
} }
} }
public override void EditMethod(object parameter) public override void EditMethod(object parameter)
{ {
var copyObject = GlobalRepository.Materials.GetById(SelectedItem.Id).Clone() as IHeadMaterial; //var copyObject = GlobalRepository.Materials.GetById(SelectedItem.Id).Clone() as IHeadMaterial;
var copyObject = SelectedItem.Clone() as IHeadMaterial;
var wnd = new HeadMaterialView(SelectedItem); var wnd = new HeadMaterialView(SelectedItem);
wnd.ShowDialog(); wnd.ShowDialog();
if (wnd.DialogResult == true) if (wnd.DialogResult == true)
{ {
GlobalRepository.Materials.Update(SelectedItem); //
} }
else else
{ {
@@ -82,7 +82,6 @@ namespace StructureHelper.Windows.ViewModels.Materials
{ {
NewItem = SelectedItem.Clone() as IHeadMaterial; NewItem = SelectedItem.Clone() as IHeadMaterial;
NewItem.Name = $"{NewItem.Name} copy"; NewItem.Name = $"{NewItem.Name} copy";
GlobalRepository.Materials.Create(NewItem);
Collection.Add(NewItem); Collection.Add(NewItem);
Items.Add(NewItem); Items.Add(NewItem);
SelectedItem = NewItem; SelectedItem = NewItem;

View File

@@ -1,20 +1,13 @@
using StructureHelper.Infrastructure; using StructureHelper.Infrastructure;
using StructureHelper.Infrastructure.Enums; using StructureHelper.Infrastructure.Enums;
using StructureHelper.Infrastructure.UI.DataContexts; using StructureHelper.Infrastructure.UI.DataContexts;
using StructureHelper.Services.Settings;
using StructureHelper.Windows.PrimitiveProperiesWindow; using StructureHelper.Windows.PrimitiveProperiesWindow;
using StructureHelper.Windows.PrimitiveTemplates.RCs.Beams;
using StructureHelper.Windows.PrimitiveTemplates.RCs.RectangleBeam;
using StructureHelper.Windows.Services; using StructureHelper.Windows.Services;
using StructureHelperCommon.Infrastructures.Exceptions; using StructureHelperCommon.Infrastructures.Exceptions;
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models.Calculators; using StructureHelperCommon.Models.Calculators;
using StructureHelperCommon.Models.Materials;
using StructureHelperCommon.Models.Shapes; using StructureHelperCommon.Models.Shapes;
using StructureHelperLogics.Models.CrossSections; using StructureHelperLogics.Models.CrossSections;
using StructureHelperLogics.Models.Primitives; using StructureHelperLogics.Models.Primitives;
using StructureHelperLogics.Models.Templates.CrossSections.RCs;
using StructureHelperLogics.Models.Templates.RCs;
using StructureHelperLogics.NdmCalculations.Analyses.ByForces; using StructureHelperLogics.NdmCalculations.Analyses.ByForces;
using StructureHelperLogics.NdmCalculations.Cracking; using StructureHelperLogics.NdmCalculations.Cracking;
using StructureHelperLogics.NdmCalculations.Primitives; using StructureHelperLogics.NdmCalculations.Primitives;
@@ -25,7 +18,7 @@ using System.Linq;
using System.Windows.Forms; using System.Windows.Forms;
using System.Windows.Input; using System.Windows.Input;
//Copyright (c) 2023 Redikultsev Evgeny, Ekaterinburg, Russia //Copyright (c) 2024 Redikultsev Evgeny, Ekaterinburg, Russia
//All rights reserved. //All rights reserved.
namespace StructureHelper.Windows.ViewModels.NdmCrossSections namespace StructureHelper.Windows.ViewModels.NdmCrossSections

View File

@@ -3,10 +3,10 @@
{ {
public enum MaterialTypes public enum MaterialTypes
{ {
Concrete, Concrete = 0,
Reinforcement, Reinforcement = 1,
//Steel, Steel = 3,
CarbonFiber, CarbonFiber = 4,
GlassFiber, 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 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> public class DictionaryConvertStrategy<T, V> : IConvertStrategy<T, V>
where T : ISaveable where T : ISaveable
where V : ISaveable where V : ISaveable

View File

@@ -7,10 +7,20 @@ using System.Threading.Tasks;
namespace StructureHelperCommon.Infrastructures.Interfaces 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 public interface IConvertStrategy<T,V> : IBaseConvertStrategy
where T :ISaveable where T :ISaveable
where V :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); 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 Name { get; set; }
string Tags { get; set; } string Tags { get; set; }
IVersionProcessor VersionProcessor { get;} IVersionProcessor VersionProcessor { get; set; }
} }
} }

View File

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

View File

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

View File

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

View File

@@ -6,6 +6,6 @@ namespace StructureHelperCommon.Models.Forces
{ {
public interface IForceCombinationList : IForceAction 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

@@ -2,6 +2,7 @@
using StructureHelperCommon.Infrastructures.Enums; using StructureHelperCommon.Infrastructures.Enums;
using StructureHelperCommon.Infrastructures.Interfaces; using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperLogics.Models.Materials; using StructureHelperLogics.Models.Materials;
using System;
using System.Windows.Media; using System.Windows.Media;
namespace StructureHelper.Models.Materials namespace StructureHelper.Models.Materials

View File

@@ -9,10 +9,9 @@ using System.Text;
namespace StructureHelperLogics.Models.Materials namespace StructureHelperLogics.Models.Materials
{ {
public interface IHelperMaterial : ISaveable, ICloneable public interface IHelperMaterial : ISaveable, ICloneable, IHasSafetyFactors
{ {
IMaterial GetLoaderMaterial(LimitStates limitState, CalcTerms calcTerm); IMaterial GetLoaderMaterial(LimitStates limitState, CalcTerms calcTerm);
IMaterial GetCrackedLoaderMaterial(LimitStates limitState, CalcTerms calcTerm); IMaterial GetCrackedLoaderMaterial(LimitStates limitState, CalcTerms calcTerm);
List<IMaterialSafetyFactor> SafetyFactors { get; set; }
} }
} }

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> public class MaterialSafetyFactorUpdateStrategy : IUpdateStrategy<IMaterialSafetyFactor>
{ {
private IUpdateStrategy<IMaterialSafetyFactor> baseUpdateStrategy = new MaterialSafetyFactorBaseUpdateStrategy();
public void Update(IMaterialSafetyFactor targetObject, IMaterialSafetyFactor sourceObject) public void Update(IMaterialSafetyFactor targetObject, IMaterialSafetyFactor sourceObject)
{ {
CheckObject.IsNull(sourceObject); CheckObject.IsNull(sourceObject);
CheckObject.IsNull(targetObject); CheckObject.IsNull(targetObject);
if (ReferenceEquals(targetObject, sourceObject)) { return; } if (ReferenceEquals(targetObject, sourceObject)) { return; }
targetObject.Name = sourceObject.Name; baseUpdateStrategy.Update(targetObject, sourceObject);
targetObject.Take = sourceObject.Take;
targetObject.Description = sourceObject.Description;
targetObject.PartialFactors.Clear(); targetObject.PartialFactors.Clear();
foreach (var item in sourceObject.PartialFactors) foreach (var item in sourceObject.PartialFactors)
{ {

View File

@@ -10,7 +10,7 @@ namespace StructureHelperLogic.Models.Analyses
public Guid Id { get; private set; } public Guid Id { get; private set; }
public string Name { get; set; } public string Name { get; set; }
public string Tags { get; set; } public string Tags { get; set; }
public IVersionProcessor VersionProcessor { get; private set; } public IVersionProcessor VersionProcessor { get; set; }
public CrossSectionNdmAnalysis(Guid id, IVersionProcessor versionProcessor) public CrossSectionNdmAnalysis(Guid id, IVersionProcessor versionProcessor)
{ {

View File

@@ -8,7 +8,7 @@ namespace StructureHelperLogics.Models.CrossSections
{ {
public class CrossSection : ICrossSection public class CrossSection : ICrossSection
{ {
public ICrossSectionRepository SectionRepository { get; private set; } = new CrossSectionRepository(); public ICrossSectionRepository SectionRepository { get; set; } = new CrossSectionRepository();
public Guid Id { get; private set; } public Guid Id { get; private set; }

View File

@@ -9,6 +9,6 @@ namespace StructureHelperLogics.Models.CrossSections
{ {
public interface ICrossSection : ISaveable, ICloneable public interface ICrossSection : ISaveable, ICloneable
{ {
ICrossSectionRepository SectionRepository { get; } ICrossSectionRepository SectionRepository { get; set; }
} }
} }

View File

@@ -1,5 +1,6 @@
using LoaderCalculator.Data.Materials; using LoaderCalculator.Data.Materials;
using StructureHelperCommon.Infrastructures.Enums; using StructureHelperCommon.Infrastructures.Enums;
using StructureHelperCommon.Infrastructures.Exceptions;
using StructureHelperCommon.Infrastructures.Interfaces; using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Infrastructures.Settings; using StructureHelperCommon.Infrastructures.Settings;
using StructureHelperCommon.Models.Materials.Libraries; using StructureHelperCommon.Models.Materials.Libraries;
@@ -14,9 +15,9 @@ namespace StructureHelperLogics.Models.Materials
public class FRMaterial : IFRMaterial public class FRMaterial : IFRMaterial
{ {
private IElasticMaterialLogic elasticMaterialLogic => new ElasticMaterialLogic(); private IElasticMaterialLogic elasticMaterialLogic => new ElasticMaterialLogic();
private MaterialTypes materialType;
IUpdateStrategy<IFRMaterial> updateStrategy = new FRUpdateStrategy(); IUpdateStrategy<IFRMaterial> updateStrategy = new FRUpdateStrategy();
public Guid Id { get; } public Guid Id { get; }
public MaterialTypes MaterialType { get; }
public double Modulus{ get; set; } public double Modulus{ get; set; }
public double CompressiveStrength { get; set; } public double CompressiveStrength { get; set; }
public double TensileStrength { get; set; } public double TensileStrength { get; set; }
@@ -28,11 +29,16 @@ namespace StructureHelperLogics.Models.Materials
public FRMaterial(MaterialTypes materialType, Guid id) public FRMaterial(MaterialTypes materialType, Guid id)
{ {
if (materialType != MaterialTypes.CarbonFiber ||
materialType != MaterialTypes.GlassFiber)
{
throw new StructureHelperException(ErrorStrings.DataIsInCorrect + $": Material type {materialType} is not right");
}
Id = id; Id = id;
ULSConcreteStrength = 14e6d; ULSConcreteStrength = 14e6d;
SumThickness = 0.175e-3d; SumThickness = 0.175e-3d;
this.materialType = materialType; MaterialType = materialType;
SafetyFactors.AddRange(PartialCoefficientFactory.GetDefaultFRSafetyFactors(ProgramSetting.FRCodeType, this.materialType)); SafetyFactors.AddRange(PartialCoefficientFactory.GetDefaultFRSafetyFactors(ProgramSetting.FRCodeType, this.MaterialType));
} }
public FRMaterial(MaterialTypes materialType) : this (materialType, Guid.NewGuid()) public FRMaterial(MaterialTypes materialType) : this (materialType, Guid.NewGuid())
@@ -42,7 +48,7 @@ namespace StructureHelperLogics.Models.Materials
public object Clone() public object Clone()
{ {
var newItem = new FRMaterial(this.materialType); var newItem = new FRMaterial(this.MaterialType);
updateStrategy.Update(newItem, this); updateStrategy.Update(newItem, this);
return newItem; return newItem;
} }

View File

@@ -1,4 +1,5 @@
using StructureHelperCommon.Models.Materials.Libraries; using StructureHelperCommon.Infrastructures.Enums;
using StructureHelperCommon.Models.Materials.Libraries;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@@ -9,6 +10,7 @@ namespace StructureHelperLogics.Models.Materials
{ {
public interface IFRMaterial : IElasticMaterial public interface IFRMaterial : IElasticMaterial
{ {
MaterialTypes MaterialType { get; }
double ULSConcreteStrength { get; set; } double ULSConcreteStrength { get; set; }
double SumThickness { get; set; } double SumThickness { get; set; }
double GammaF2 { get; } double GammaF2 { get; }

View File

@@ -1,32 +0,0 @@
using StructureHelper.Models.Materials;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StructureHelperLogics.Models.Materials
{
public class HeadMaterialRepository : IHeadMaterialRepository
{
public object Parent { get; private set; }
public List<IHeadMaterial> HeadMaterials { get; set; }
public HeadMaterialRepository()
{
HeadMaterials = new List<IHeadMaterial>();
}
public HeadMaterialRepository(object parent)
{
Parent = parent;
HeadMaterials = new List<IHeadMaterial>();
}
public void RegisterParent(object obj)
{
Parent = obj;
}
}
}

View File

@@ -9,6 +9,6 @@ namespace StructureHelperLogics.Models.Materials
{ {
public interface IHasHeadMaterials public interface IHasHeadMaterials
{ {
List<IHeadMaterial> HeadMaterials { get; } List<IHeadMaterial> HeadMaterials { get;}
} }
} }

View File

@@ -1,18 +0,0 @@
using StructureHelper.Models.Materials;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;
namespace StructureHelperLogics.Models.Materials
{
public interface IHeadMaterialRepository
{
object Parent { get; }
List<IHeadMaterial> HeadMaterials { get; set; }
void RegisterParent(object obj);
}
}

View File

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

View File

@@ -6,6 +6,7 @@ namespace StructureHelperLogics.Models.Materials
{ {
public class HeadMaterialUpdateStrategy : IUpdateStrategy<IHeadMaterial> public class HeadMaterialUpdateStrategy : IUpdateStrategy<IHeadMaterial>
{ {
private IUpdateStrategy<IHeadMaterial> updateStrategy = new HeadMaterialBaseUpdateStrategy();
private IUpdateStrategy<IHelperMaterial> helperMaterialUpdateStrategy; private IUpdateStrategy<IHelperMaterial> helperMaterialUpdateStrategy;
public HeadMaterialUpdateStrategy(IUpdateStrategy<IHelperMaterial> helperMaterialUpdateStrategy) public HeadMaterialUpdateStrategy(IUpdateStrategy<IHelperMaterial> helperMaterialUpdateStrategy)
@@ -19,8 +20,7 @@ namespace StructureHelperLogics.Models.Materials
CheckObject.IsNull(sourceObject); CheckObject.IsNull(sourceObject);
CheckObject.IsNull(targetObject); CheckObject.IsNull(targetObject);
if (ReferenceEquals(targetObject, sourceObject)) { return; } if (ReferenceEquals(targetObject, sourceObject)) { return; }
targetObject.Name = sourceObject.Name; updateStrategy.Update(targetObject, sourceObject);
targetObject.Color = sourceObject.Color;
targetObject.HelperMaterial = sourceObject.HelperMaterial.Clone() as IHelperMaterial; targetObject.HelperMaterial = sourceObject.HelperMaterial.Clone() as IHelperMaterial;
helperMaterialUpdateStrategy.Update(targetObject.HelperMaterial, sourceObject.HelperMaterial); helperMaterialUpdateStrategy.Update(targetObject.HelperMaterial, sourceObject.HelperMaterial);
} }

View File

@@ -32,6 +32,7 @@
<ItemGroup> <ItemGroup>
<Folder Include="FunctionalTests\Ndms\SteelSections\" /> <Folder Include="FunctionalTests\Ndms\SteelSections\" />
<Folder Include="FunctionalTests\RCs\Anchorage\" /> <Folder Include="FunctionalTests\RCs\Anchorage\" />
<Folder Include="UnitTests\ConvertStrategiesTest\" />
<Folder Include="UnitTests\WindowTests\Calculations\CalculationProperties\" /> <Folder Include="UnitTests\WindowTests\Calculations\CalculationProperties\" />
</ItemGroup> </ItemGroup>

View File

@@ -60,17 +60,6 @@ namespace StructureHelperTests.UnitTests.UpdateStrategiesTests
targetMock.VerifySet(t => t.TensionForSLS = It.IsAny<bool>(), Times.Never); targetMock.VerifySet(t => t.TensionForSLS = It.IsAny<bool>(), Times.Never);
targetMock.VerifySet(t => t.RelativeHumidity = It.IsAny<double>(), Times.Never); targetMock.VerifySet(t => t.RelativeHumidity = It.IsAny<double>(), Times.Never);
} }
[Test]
public void Update_ShouldThrowStructureHelperException_WhenObjectsAreOfDifferentTypes()
{
// Arrange
var targetMock = new Mock<IConcreteLibMaterial>();
var sourceMock = new Mock<ConcreteLibMaterial>();
// Act & Assert
Assert.Throws<StructureHelperException>(() => strategy.Update(targetMock.Object, sourceMock.Object));
}
} }
} }

View File

@@ -27,17 +27,6 @@ namespace StructureHelperTests.UnitTests.UpdateStrategiesTests
mockTargetMaterial.Setup(t => t.SafetyFactors).Returns(targetSafetyFactors); mockTargetMaterial.Setup(t => t.SafetyFactors).Returns(targetSafetyFactors);
} }
[Test]
public void Update_ShouldThrowException_WhenTargetAndSourceAreDifferentTypes()
{
// Arrange
var mockTarget1 = new ConcreteLibMaterial();
var mockTarget2 = new ReinforcementLibMaterial();
// Act & Assert
Assert.Throws<StructureHelperException>(() => updateStrategy.Update(mockTarget1, mockTarget2));
}
[Test] [Test]
public void Update_ShouldCopyMaterialEntityAndMaterialLogic() public void Update_ShouldCopyMaterialEntityAndMaterialLogic()
{ {