Add beam shear clone strategies
This commit is contained in:
@@ -1,16 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
|
||||
namespace StructureHelperLogics.Models.BeamShears
|
||||
{
|
||||
public class BeamShear : IBeamShear
|
||||
{
|
||||
|
||||
private ICloneStrategy<IBeamShear> cloneStrategy;
|
||||
public Guid Id { get; }
|
||||
public IBeamShearRepository Repository { get; } = new BeamShearRepository(Guid.NewGuid());
|
||||
public IBeamShearRepository Repository { get; set; } = new BeamShearRepository(Guid.NewGuid());
|
||||
public BeamShear(Guid id)
|
||||
{
|
||||
Id = id;
|
||||
@@ -18,7 +14,10 @@ namespace StructureHelperLogics.Models.BeamShears
|
||||
|
||||
public object Clone()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
var cloningStrategy = new DeepCloningStrategy();
|
||||
cloneStrategy = new BeamShearCloneStrategy(cloningStrategy);
|
||||
var newItem = cloneStrategy.GetClone(this);
|
||||
return newItem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +1,16 @@
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Models.Calculators;
|
||||
using StructureHelperCommon.Models.Forces;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelperLogics.Models.BeamShears
|
||||
{
|
||||
public class BeamShearRepository : IBeamShearRepository
|
||||
{
|
||||
|
||||
private ICloneStrategy<IBeamShearRepository> cloneStrategy;
|
||||
public Guid Id { get; }
|
||||
|
||||
public List<IBeamShearAction> Actions { get; } = new();
|
||||
|
||||
public List<ICalculator> Calculators { get; } = new();
|
||||
|
||||
public List<IBeamShearSection> Sections { get; } = new();
|
||||
|
||||
public List<IStirrup> Stirrups { get; } = new();
|
||||
|
||||
|
||||
@@ -30,7 +21,10 @@ namespace StructureHelperLogics.Models.BeamShears
|
||||
|
||||
public object Clone()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
var cloningStrategy = new DeepCloningStrategy();
|
||||
cloneStrategy = new BeamShearRepositoryCloneStrategy(cloningStrategy);
|
||||
var newItem = cloneStrategy.GetClone(this);
|
||||
return newItem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,6 @@ namespace StructureHelperLogics.Models.BeamShears
|
||||
{
|
||||
public interface IBeamShear : ISaveable, ICloneable
|
||||
{
|
||||
IBeamShearRepository Repository { get; }
|
||||
IBeamShearRepository Repository { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Models.Calculators;
|
||||
using StructureHelperCommon.Models.Forces;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
//Copyright (c) 2025 Redikultsev Evgeny, Ekaterinburg, Russia
|
||||
//All rights reserved.
|
||||
|
||||
namespace StructureHelperLogics.Models.BeamShears
|
||||
{
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
|
||||
namespace StructureHelperLogics.Models.BeamShears
|
||||
{
|
||||
public class BeamShearCloneStrategy : ICloneStrategy<IBeamShear>
|
||||
{
|
||||
private ICloningStrategy cloningStrategy;
|
||||
private ICloneStrategy<IBeamShearRepository> cloneStrategy;
|
||||
private BeamShear beamShear;
|
||||
public BeamShearCloneStrategy(ICloningStrategy cloningStrategy)
|
||||
{
|
||||
this.cloningStrategy = cloningStrategy;
|
||||
}
|
||||
|
||||
public IBeamShear GetClone(IBeamShear sourceObject)
|
||||
{
|
||||
InitializeStrategies();
|
||||
beamShear = new(Guid.NewGuid())
|
||||
{
|
||||
Repository = cloneStrategy.GetClone(sourceObject.Repository)
|
||||
};
|
||||
return beamShear;
|
||||
}
|
||||
|
||||
private void InitializeStrategies()
|
||||
{
|
||||
cloningStrategy = new DeepCloningStrategy();
|
||||
cloneStrategy ??= new BeamShearRepositoryCloneStrategy(cloningStrategy);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
|
||||
//Copyright (c) 2025 Redikultsev Evgeny, Ekaterinburg, Russia
|
||||
//All rights reserved.
|
||||
|
||||
namespace StructureHelperLogics.Models.BeamShears
|
||||
{
|
||||
public class BeamShearRepositoryCloneStrategy : ICloneStrategy<IBeamShearRepository>
|
||||
{
|
||||
private ICloningStrategy cloningStrategy;
|
||||
private IUpdateStrategy<IHasBeamShearActions> actionUpdateStrategy;
|
||||
private IUpdateStrategy<IHasBeamShearSections> sectionUpdateStrategy;
|
||||
private IUpdateStrategy<IHasStirrups> stirrupUpdateStrategy;
|
||||
private BeamShearRepository targetRepository;
|
||||
|
||||
public BeamShearRepositoryCloneStrategy(ICloningStrategy cloningStrategy)
|
||||
{
|
||||
this.cloningStrategy = cloningStrategy;
|
||||
}
|
||||
public IBeamShearRepository GetClone(IBeamShearRepository sourceObject)
|
||||
{
|
||||
InitializeStrategies();
|
||||
targetRepository = new(Guid.NewGuid());
|
||||
actionUpdateStrategy.Update(targetRepository, sourceObject);
|
||||
sectionUpdateStrategy.Update(targetRepository, sourceObject);
|
||||
stirrupUpdateStrategy.Update(targetRepository, sourceObject);
|
||||
return targetRepository;
|
||||
}
|
||||
|
||||
private void InitializeStrategies()
|
||||
{
|
||||
actionUpdateStrategy ??= new HasActionsUpdateCloneStrategy(cloningStrategy);
|
||||
sectionUpdateStrategy ??= new HasSectionsUpdateCloneStrategy(cloningStrategy);
|
||||
stirrupUpdateStrategy ??= new HasStirrupsUpdateCloneStrategy(cloningStrategy);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Services;
|
||||
|
||||
namespace StructureHelperLogics.Models.BeamShears
|
||||
{
|
||||
public class HasActionsUpdateCloneStrategy : IUpdateStrategy<IHasBeamShearActions>
|
||||
{
|
||||
private readonly ICloningStrategy cloningStrategy;
|
||||
|
||||
public HasActionsUpdateCloneStrategy(ICloningStrategy cloningStrategy)
|
||||
{
|
||||
this.cloningStrategy = cloningStrategy;
|
||||
}
|
||||
|
||||
public void Update(IHasBeamShearActions targetObject, IHasBeamShearActions sourceObject)
|
||||
{
|
||||
CheckObject.IsNull(cloningStrategy);
|
||||
CheckObject.IsNull(sourceObject);
|
||||
CheckObject.IsNull(targetObject);
|
||||
if (ReferenceEquals(targetObject, sourceObject)) { return; }
|
||||
targetObject.Actions.Clear();
|
||||
foreach (var item in sourceObject.Actions)
|
||||
{
|
||||
var newItem = cloningStrategy.Clone(item);
|
||||
targetObject.Actions.Add(newItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Services;
|
||||
|
||||
namespace StructureHelperLogics.Models.BeamShears
|
||||
{
|
||||
public class HasSectionsUpdateCloneStrategy : IUpdateStrategy<IHasBeamShearSections>
|
||||
{
|
||||
private readonly ICloningStrategy cloningStrategy;
|
||||
|
||||
public HasSectionsUpdateCloneStrategy(ICloningStrategy cloningStrategy)
|
||||
{
|
||||
this.cloningStrategy = cloningStrategy;
|
||||
}
|
||||
|
||||
public void Update(IHasBeamShearSections targetObject, IHasBeamShearSections sourceObject)
|
||||
{
|
||||
CheckObject.IsNull(cloningStrategy);
|
||||
CheckObject.IsNull(sourceObject);
|
||||
CheckObject.IsNull(targetObject);
|
||||
if (ReferenceEquals(targetObject, sourceObject)) { return; }
|
||||
targetObject.Sections.Clear();
|
||||
foreach (var item in sourceObject.Sections)
|
||||
{
|
||||
IBeamShearSection newSection = cloningStrategy.Clone(item);
|
||||
targetObject.Sections.Add(newSection);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
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.BeamShears
|
||||
{
|
||||
public class HasStirrupsUpdateCloneStrategy : IUpdateStrategy<IHasStirrups>
|
||||
{
|
||||
private readonly ICloningStrategy cloningStrategy;
|
||||
|
||||
public HasStirrupsUpdateCloneStrategy(ICloningStrategy cloningStrategy)
|
||||
{
|
||||
this.cloningStrategy = cloningStrategy;
|
||||
}
|
||||
|
||||
public void Update(IHasStirrups targetObject, IHasStirrups sourceObject)
|
||||
{
|
||||
CheckObject.IsNull(cloningStrategy);
|
||||
CheckObject.IsNull(sourceObject);
|
||||
CheckObject.IsNull(targetObject);
|
||||
if (ReferenceEquals(targetObject, sourceObject)) { return; }
|
||||
targetObject.Stirrups.Clear();
|
||||
foreach (var item in sourceObject.Stirrups)
|
||||
{
|
||||
IStirrup newStirrup = cloningStrategy.Clone(item);
|
||||
targetObject.Stirrups.Add(newStirrup);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user