Add beam shear clone strategies

This commit is contained in:
Evgeny Redikultsev
2025-06-01 21:58:06 +05:00
parent 34ad25b2ea
commit 957ab62ece
28 changed files with 343 additions and 167 deletions

View File

@@ -3,32 +3,32 @@ using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models;
using StructureHelperCommon.Models.Analyses;
using StructureHelperLogic.Models.Analyses;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.ToolTip;
using StructureHelperLogics.Models.Analyses;
namespace DataAccess.DTOs.Converters
namespace DataAccess.DTOs
{
public class AnalysisToDTOConvertStrategy : IConvertStrategy<IAnalysis, IAnalysis>
public class AnalysisToDTOConvertStrategy : ConvertStrategy<IAnalysis, IAnalysis>
{
private const string Message = "Analysis type is";
private IConvertStrategy<CrossSectionNdmAnalysisDTO, ICrossSectionNdmAnalysis> convertCrossSectionNdmAnalysisStrategy = new CrossSectionNdmAnalysisToDTOConvertStrategy();
private DictionaryConvertStrategy<CrossSectionNdmAnalysisDTO, ICrossSectionNdmAnalysis> convertLogic;
public Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; set; }
public IShiftTraceLogger TraceLogger { get; set; }
private IConvertStrategy<CrossSectionNdmAnalysisDTO, ICrossSectionNdmAnalysis> crossSectionConvertLogic;
private IConvertStrategy<BeamShearAnalysisDTO, IBeamShearAnalysis> beamShearConvertLogic;
public IAnalysis Convert(IAnalysis source)
public AnalysisToDTOConvertStrategy(Dictionary<(Guid id, Type type), ISaveable> referenceDictionary, IShiftTraceLogger traceLogger) : base(referenceDictionary, traceLogger)
{
}
public override IAnalysis GetNewItem(IAnalysis source)
{
Check();
IAnalysis analysis;
if (source is ICrossSectionNdmAnalysis crossSectionNdmAnalysis)
{
analysis = GetCrossSectionNdmAnalysisDTO(crossSectionNdmAnalysis);
}
else if (source is IBeamShearAnalysis beamShearAnalysis)
{
analysis = GetBeamShearAnalysis(beamShearAnalysis);
}
else
{
string errorString = ErrorStrings.ObjectTypeIsUnknownObj(source);
@@ -41,23 +41,26 @@ namespace DataAccess.DTOs.Converters
}
return analysis;
}
private BeamShearAnalysisDTO GetBeamShearAnalysis(IBeamShearAnalysis beamShearAnalysis)
{
TraceLogger?.AddMessage(Message + " Beam Shear Analysis", TraceLogStatuses.Debug);
beamShearConvertLogic ??= new DictionaryConvertStrategy<BeamShearAnalysisDTO, IBeamShearAnalysis>
(this,
new BeamShearAnalysisToDTOConvertStrategy(ReferenceDictionary, TraceLogger)
);
BeamShearAnalysisDTO newItem = beamShearConvertLogic.Convert(beamShearAnalysis);
return newItem;
}
private CrossSectionNdmAnalysisDTO GetCrossSectionNdmAnalysisDTO(ICrossSectionNdmAnalysis crossSectionNdmAnalysis)
{
TraceLogger?.AddMessage(Message + " Cross-Section Ndm Analysis", TraceLogStatuses.Debug);
convertCrossSectionNdmAnalysisStrategy.ReferenceDictionary = ReferenceDictionary;
convertCrossSectionNdmAnalysisStrategy.TraceLogger = TraceLogger;
convertLogic = new DictionaryConvertStrategy<CrossSectionNdmAnalysisDTO, ICrossSectionNdmAnalysis>(this, convertCrossSectionNdmAnalysisStrategy);
CrossSectionNdmAnalysisDTO crossSectionNdmAnalysisDTO = convertLogic.Convert(crossSectionNdmAnalysis);
return crossSectionNdmAnalysisDTO;
}
private void Check()
{
var checkLogic = new CheckConvertLogic<IAnalysis, IAnalysis>();
checkLogic.ConvertStrategy = this;
checkLogic.TraceLogger = TraceLogger;
checkLogic.Check();
crossSectionConvertLogic ??= new DictionaryConvertStrategy<CrossSectionNdmAnalysisDTO, ICrossSectionNdmAnalysis>
(this,
new CrossSectionNdmAnalysisToDTOConvertStrategy(ReferenceDictionary, TraceLogger)
);
CrossSectionNdmAnalysisDTO newItem = crossSectionConvertLogic.Convert(crossSectionNdmAnalysis);
return newItem;
}
}
}

View File

@@ -0,0 +1,31 @@
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models;
using StructureHelperLogics.Models.Analyses;
namespace DataAccess.DTOs
{
public class BeamShearAnalysisToDTOConvertStrategy : ConvertStrategy<BeamShearAnalysisDTO, IBeamShearAnalysis>
{
private IUpdateStrategy<IBeamShearAnalysis> updateStrategy;
public BeamShearAnalysisToDTOConvertStrategy(Dictionary<(Guid id, Type type), ISaveable> referenceDictionary, IShiftTraceLogger traceLogger) : base(referenceDictionary, traceLogger)
{
}
public override BeamShearAnalysisDTO GetNewItem(IBeamShearAnalysis source)
{
updateStrategy ??= new BeamShearAnalysisUpdateStrategy();
try
{
NewItem = new(source.Id);
updateStrategy.Update(NewItem, source);
return NewItem;
}
catch (Exception ex)
{
TraceErrorByEntity(this, ex.Message);
throw;
}
}
}
}

View File

@@ -4,13 +4,8 @@ using StructureHelperCommon.Models.Analyses;
using StructureHelperCommon.Models.Loggers;
using StructureHelperLogic.Models.Analyses;
using StructureHelperLogics.Models.Analyses;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DataAccess.DTOs.Converters
namespace DataAccess.DTOs
{
internal class CrossSectionNdmAnalysisToDTOConvertStrategy : IConvertStrategy<CrossSectionNdmAnalysisDTO, ICrossSectionNdmAnalysis>
{
@@ -37,6 +32,16 @@ namespace DataAccess.DTOs.Converters
}
public CrossSectionNdmAnalysisToDTOConvertStrategy(Dictionary<(Guid id, Type type), ISaveable> referenceDictionary, IShiftTraceLogger? traceLogger)
: this(
new CrossSectionNdmAnalysisUpdateStrategy(),
new VersionProcessorToDTOConvertStrategy(),
null)
{
ReferenceDictionary = referenceDictionary;
TraceLogger = traceLogger;
}
public CrossSectionNdmAnalysisDTO Convert(ICrossSectionNdmAnalysis source)
{
try

View File

@@ -1,49 +1,33 @@
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Infrastructures.Settings;
using StructureHelperCommon.Models;
using StructureHelperCommon.Models.Analyses;
using StructureHelperCommon.Models.Projects;
using StructureHelperLogics.Models.CrossSections;
using StructureHelperLogics.NdmCalculations.Analyses.ByForces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DataAccess.DTOs
{
public class ProjectToDTOConvertStrategy : IConvertStrategy<ProjectDTO, IProject>
public class ProjectToDTOConvertStrategy : ConvertStrategy<ProjectDTO, IProject>
{
private IUpdateStrategy<IProject> updateStrategy;
private IConvertStrategy<VisualAnalysisDTO, IVisualAnalysis> convertStrategy;
private DictionaryConvertStrategy<VisualAnalysisDTO, IVisualAnalysis> convertLogic;
public Dictionary<(Guid id, Type type), ISaveable> ReferenceDictionary { get; set; }
public IShiftTraceLogger TraceLogger { get; set; }
public ProjectToDTOConvertStrategy(IUpdateStrategy<IProject> updateStrategy, IConvertStrategy<VisualAnalysisDTO, IVisualAnalysis> convertStrategy)
{
this.updateStrategy = updateStrategy;
this.convertStrategy = convertStrategy;
}
public ProjectToDTOConvertStrategy() : this(new ProjectUpdateStrategy(), new VisualAnalysisToDTOConvertStrategy())
public ProjectToDTOConvertStrategy()
{
}
public ProjectDTO Convert(IProject source)
public ProjectToDTOConvertStrategy(
IUpdateStrategy<IProject> updateStrategy,
DictionaryConvertStrategy<VisualAnalysisDTO, IVisualAnalysis> convertLogic)
{
Check();
ProjectDTO newItem = new()
{
Id = source.Id
};
this.updateStrategy = updateStrategy;
this.convertLogic = convertLogic;
}
public override ProjectDTO GetNewItem(IProject source)
{
InitializeStrategies();
ProjectDTO newItem = new(source.Id);
updateStrategy.Update(newItem, source);
convertStrategy.ReferenceDictionary = ReferenceDictionary;
convertStrategy.TraceLogger = TraceLogger;
convertLogic = new DictionaryConvertStrategy<VisualAnalysisDTO, IVisualAnalysis>(this, convertStrategy);
newItem.VisualAnalyses.Clear();
foreach (var item in source.VisualAnalyses)
{
@@ -51,15 +35,15 @@ namespace DataAccess.DTOs
newItem.VisualAnalyses.Add(newVisualAnalysis);
}
return newItem;
}
private void Check()
private void InitializeStrategies()
{
var checkLogic = new CheckConvertLogic<ProjectDTO, IProject>();
checkLogic.ConvertStrategy = this;
checkLogic.TraceLogger = TraceLogger;
checkLogic.Check();
updateStrategy ??= new ProjectUpdateStrategy();
convertLogic ??= new DictionaryConvertStrategy<VisualAnalysisDTO, IVisualAnalysis>
(this,
new VisualAnalysisToDTOConvertStrategy(ReferenceDictionary, TraceLogger)
);
}
}
}

View File

@@ -1,35 +1,16 @@
using DataAccess.DTOs.Converters;
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Infrastructures.Settings;
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models;
using StructureHelperCommon.Models.Analyses;
using StructureHelperCommon.Models.Loggers;
using StructureHelperCommon.Models.Projects;
using StructureHelperLogic.Models.Analyses;
using StructureHelperLogics.Models.CrossSections;
using StructureHelperLogics.NdmCalculations.Analyses.ByForces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
//Copyright (c) 2025 Redikultsev Evgeny, Ekaterinburg, Russia
//All rights reserved.
namespace DataAccess.DTOs
{
internal class VisualAnalysisToDTOConvertStrategy : ConvertStrategy<VisualAnalysisDTO, IVisualAnalysis>
{
private IConvertStrategy<IAnalysis, IAnalysis> convertStrategy;
public VisualAnalysisToDTOConvertStrategy(IConvertStrategy<IAnalysis, IAnalysis> convertStrategy)
{
this.convertStrategy = convertStrategy;
}
public VisualAnalysisToDTOConvertStrategy() : this(new AnalysisToDTOConvertStrategy())
{
}
private IConvertStrategy<IAnalysis, IAnalysis> convertLogic;
public override VisualAnalysisDTO GetNewItem(IVisualAnalysis source)
{
@@ -40,30 +21,29 @@ namespace DataAccess.DTOs
return visualAnalysisDTO;
}
public VisualAnalysisToDTOConvertStrategy
(Dictionary<(Guid id, Type type), ISaveable> referenceDictionary,
IShiftTraceLogger traceLogger)
: base(referenceDictionary, traceLogger)
{
}
private VisualAnalysisDTO GetNewAnalysis(IVisualAnalysis source)
{
VisualAnalysisDTO visualAnalysisDTO = new()
InitializeStrategies();
VisualAnalysisDTO visualAnalysisDTO = new(source.Id)
{
Id = source.Id
Analysis = convertLogic.Convert(source.Analysis)
};
convertStrategy.ReferenceDictionary = ReferenceDictionary;
convertStrategy.TraceLogger = TraceLogger;
var convertLogic = new DictionaryConvertStrategy<IAnalysis, IAnalysis>(this, convertStrategy)
{
ReferenceDictionary = ReferenceDictionary,
ConvertStrategy = convertStrategy,
TraceLogger = TraceLogger
};
visualAnalysisDTO.Analysis = convertLogic.Convert(source.Analysis);
return visualAnalysisDTO;
}
private void Check()
private void InitializeStrategies()
{
var checkLogic = new CheckConvertLogic<VisualAnalysisDTO, IVisualAnalysis>();
checkLogic.ConvertStrategy = this;
checkLogic.TraceLogger = TraceLogger;
checkLogic.Check();
convertLogic ??= new DictionaryConvertStrategy<IAnalysis, IAnalysis>
(this,
new AnalysisToDTOConvertStrategy(ReferenceDictionary, TraceLogger)
);
}
}
}