Material Update Strategy was added
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
using StructureHelperCommon.Infrastructures.Enums;
|
||||
using StructureHelperCommon.Infrastructures.Exceptions;
|
||||
using StructureHelperCommon.Infrastructures.Strings;
|
||||
|
||||
namespace StructureHelperCommon.Models.Forces
|
||||
{
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using StructureHelperCommon.Infrastructures.Enums;
|
||||
using StructureHelperCommon.Infrastructures.Exceptions;
|
||||
using StructureHelperCommon.Infrastructures.Strings;
|
||||
|
||||
namespace StructureHelperCommon.Models.Forces
|
||||
{
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using StructureHelperCommon.Infrastructures.Enums;
|
||||
using StructureHelperCommon.Infrastructures.Exceptions;
|
||||
using StructureHelperCommon.Infrastructures.Strings;
|
||||
|
||||
namespace StructureHelperCommon.Models.Materials.Libraries
|
||||
{
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using StructureHelperCommon.Infrastructures.Enums;
|
||||
using StructureHelperCommon.Infrastructures.Exceptions;
|
||||
using StructureHelperCommon.Infrastructures.Strings;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
@@ -4,7 +4,6 @@ using System.Linq;
|
||||
using StructureHelperCommon.Infrastructures.Enums;
|
||||
using StructureHelperCommon.Infrastructures.Exceptions;
|
||||
using StructureHelperCommon.Infrastructures.Settings;
|
||||
using StructureHelperCommon.Infrastructures.Strings;
|
||||
using StructureHelperCommon.Models.Codes;
|
||||
|
||||
namespace StructureHelperCommon.Models.Materials.Libraries
|
||||
@@ -177,7 +176,6 @@ namespace StructureHelperCommon.Models.Materials.Libraries
|
||||
new ConcreteMaterialEntity(new Guid("2f5b70b9-f4c1-470d-ac27-a39a7093b6ea"))
|
||||
{
|
||||
CodeType = codeType,
|
||||
Code = code,
|
||||
Name = "B30",
|
||||
MainStrength = 30e6
|
||||
},
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using StructureHelperCommon.Infrastructures.Enums;
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
|
||||
namespace StructureHelperCommon.Models.Materials.Libraries
|
||||
{
|
||||
public interface IMaterialSafetyFactor : ICloneable
|
||||
public interface IMaterialSafetyFactor : ISaveable, ICloneable
|
||||
{
|
||||
string Name { get; set; }
|
||||
bool Take { get; set; }
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
using System;
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using System;
|
||||
|
||||
namespace StructureHelperCommon.Models.Materials.Libraries
|
||||
{
|
||||
public interface IPartialFactor : ICloneable
|
||||
public interface IPartialFactor : ISaveable, ICloneable
|
||||
{
|
||||
double FactorValue {get;set;}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelperCommon.Models.Materials.Libraries
|
||||
{
|
||||
internal class MaterialPartialFactorUpdateStrategy : IUpdateStrategy<IMaterialPartialFactor>
|
||||
{
|
||||
public void Update(IMaterialPartialFactor targetObject, IMaterialPartialFactor sourceObject)
|
||||
{
|
||||
targetObject.LimitState = sourceObject.LimitState;
|
||||
targetObject.StressState = sourceObject.StressState;
|
||||
targetObject.CalcTerm = sourceObject.CalcTerm;
|
||||
targetObject.FactorValue = sourceObject.FactorValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelperCommon.Models.Materials.Libraries
|
||||
{
|
||||
internal class MaterialSafetyFactorUpdateStrategy : IUpdateStrategy<IMaterialSafetyFactor>
|
||||
{
|
||||
public void Update(IMaterialSafetyFactor targetObject, IMaterialSafetyFactor sourceObject)
|
||||
{
|
||||
targetObject.Name = sourceObject.Name;
|
||||
targetObject.Take = sourceObject.Take;
|
||||
targetObject.Description = sourceObject.Description;
|
||||
targetObject.PartialFactors.Clear();
|
||||
foreach (var item in sourceObject.PartialFactors)
|
||||
{
|
||||
targetObject.PartialFactors.Add(item.Clone() as IMaterialPartialFactor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,13 @@
|
||||
using StructureHelperCommon.Infrastructures.Enums;
|
||||
using StructureHelperCommon.Infrastructures.Exceptions;
|
||||
using StructureHelperCommon.Infrastructures.Strings;
|
||||
using System;
|
||||
|
||||
namespace StructureHelperCommon.Models.Materials.Libraries
|
||||
{
|
||||
public class MaterialPartialFactor : IMaterialPartialFactor
|
||||
{
|
||||
private double factorValue;
|
||||
|
||||
public Guid Id { get; }
|
||||
public StressStates StressState { get; set; }
|
||||
public CalcTerms CalcTerm { get; set; }
|
||||
public LimitStates LimitState { get; set; }
|
||||
@@ -24,23 +24,24 @@ namespace StructureHelperCommon.Models.Materials.Libraries
|
||||
}
|
||||
}
|
||||
|
||||
public MaterialPartialFactor()
|
||||
|
||||
public MaterialPartialFactor(Guid id)
|
||||
{
|
||||
Id = id;
|
||||
StressState = StressStates.Compression;
|
||||
LimitState = LimitStates.ULS;
|
||||
CalcTerm = CalcTerms.LongTerm;
|
||||
FactorValue = 1d;
|
||||
}
|
||||
|
||||
public MaterialPartialFactor() : this (Guid.NewGuid())
|
||||
{ }
|
||||
|
||||
public object Clone()
|
||||
{
|
||||
var newItem = new MaterialPartialFactor()
|
||||
{
|
||||
StressState = StressState,
|
||||
CalcTerm = CalcTerm,
|
||||
LimitState = LimitState,
|
||||
FactorValue = FactorValue,
|
||||
};
|
||||
var newItem = new MaterialPartialFactor();
|
||||
var updateStrategy = new MaterialPartialFactorUpdateStrategy();
|
||||
updateStrategy.Update(newItem, this);
|
||||
return newItem;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using StructureHelperCommon.Infrastructures.Enums;
|
||||
|
||||
@@ -6,23 +7,32 @@ namespace StructureHelperCommon.Models.Materials.Libraries
|
||||
{
|
||||
public class MaterialSafetyFactor : IMaterialSafetyFactor
|
||||
{
|
||||
public Guid Id { get; }
|
||||
public string Name {get; set; }
|
||||
public bool Take { get; set; }
|
||||
public string Description { get; set; }
|
||||
public List<IMaterialPartialFactor> PartialFactors { get; }
|
||||
|
||||
public MaterialSafetyFactor()
|
||||
|
||||
public MaterialSafetyFactor(Guid id)
|
||||
{
|
||||
Id = id;
|
||||
Take = true;
|
||||
Name = "New factor";
|
||||
Description = "Material safety factor for ...";
|
||||
PartialFactors = new List<IMaterialPartialFactor>();
|
||||
}
|
||||
|
||||
public MaterialSafetyFactor() : this (Guid.NewGuid())
|
||||
{ }
|
||||
|
||||
public double GetFactor(StressStates stressState, CalcTerms calcTerm, LimitStates limitStates)
|
||||
{
|
||||
double result = 1d;
|
||||
var coefficients = PartialFactors.Where(x => (x.StressState == stressState & x.CalcTerm == calcTerm & x.LimitState == limitStates));
|
||||
var coefficients = PartialFactors
|
||||
.Where(x => x.StressState == stressState
|
||||
& x.CalcTerm == calcTerm
|
||||
& x.LimitState == limitStates);
|
||||
foreach (var item in coefficients) { result *= item.FactorValue;}
|
||||
return result;
|
||||
}
|
||||
@@ -30,13 +40,8 @@ namespace StructureHelperCommon.Models.Materials.Libraries
|
||||
public object Clone()
|
||||
{
|
||||
var newItem = new MaterialSafetyFactor();
|
||||
newItem.Take = Take;
|
||||
newItem.Name = Name;
|
||||
newItem.Description = Description;
|
||||
foreach (var item in PartialFactors)
|
||||
{
|
||||
newItem.PartialFactors.Add(item.Clone() as IMaterialPartialFactor);
|
||||
}
|
||||
var updateSrategy = new MaterialSafetyFactorUpdateStrategy();
|
||||
updateSrategy.Update(newItem, this);
|
||||
return newItem;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using StructureHelperCommon.Infrastructures.Exceptions;
|
||||
using StructureHelperCommon.Infrastructures.Strings;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
58
StructureHelperCommon/Models/Repositories/ListRepository.cs
Normal file
58
StructureHelperCommon/Models/Repositories/ListRepository.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using StructureHelperCommon.Infrastructures.Exceptions;
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelperCommon.Models.Repositories
|
||||
{
|
||||
public class ListRepository<T> : IDataRepository<T>
|
||||
where T : ISaveable
|
||||
{
|
||||
List<T> internalData;
|
||||
private IUpdateStrategy<T> updateStrategy;
|
||||
public void Create(T entity)
|
||||
{
|
||||
var isExists = internalData.Exists(x => x.Id == entity.Id);
|
||||
if (isExists == true)
|
||||
{
|
||||
throw new StructureHelperException(ErrorStrings.DataIsInCorrect + $":\nobject with Id={entity.Id} already exists");
|
||||
}
|
||||
internalData.Add(entity);
|
||||
}
|
||||
|
||||
public void Delete(Guid Id)
|
||||
{
|
||||
T existingObject = GetById(Id);
|
||||
internalData.Remove(existingObject);
|
||||
}
|
||||
|
||||
public List<T> GetAll()
|
||||
{
|
||||
return new List<T>(internalData);
|
||||
}
|
||||
|
||||
public T GetById(Guid id)
|
||||
{
|
||||
T existingObject = internalData.Single(x => x.Id == id);
|
||||
return existingObject;
|
||||
}
|
||||
|
||||
public void Update(T updateObject)
|
||||
{
|
||||
T existingObject = GetById(updateObject.Id);
|
||||
updateStrategy.Update(existingObject, updateObject);
|
||||
}
|
||||
public ListRepository(List<T> initialData, IUpdateStrategy<T> updateStrategy)
|
||||
{
|
||||
internalData = initialData;
|
||||
this.updateStrategy = updateStrategy;
|
||||
}
|
||||
public ListRepository(IUpdateStrategy<T> updateStrategy) : this(new List<T>(), updateStrategy)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user